Skip to content

Commit

Permalink
perf: decrease wantlist send debounce time (#224)
Browse files Browse the repository at this point in the history
* perf: decrease wantlist send debounce time

We wait 200ms before sending wantlists to remote peers which is an
eternity. I'm not sure how this figure was arrived at but I've reduced
it to 10ms which has increased the js->js transfer times in the interop
tests to:

| Data    | 200ms    | 10ms    | Speedup |
|---------|----------|---------|---------|
| 1.02 kB | 486ms    | 142ms   | 342%    |
| 63.5 kB | 449ms    | 119ms   | 377%    |
| 65.5 kB | 436ms    | 105ms   | 415%    |
| 524 kB  | 1287ms   | 210ms   | 613%    |
| 786 kB  | 1676ms   | 282ms   | 594%    |
| 1.05 MB | 2066ms   | 326ms   | 634%    |
| 1.05 MB | 2123ms   | 330ms   | 643%    |
| 4.19 MB | 7091ms   | 1045ms  | 679%    |
| 8.39 MB | 13711ms  | 1927ms  | 712%    |
| 67.1 MB | 107704ms | 13462ms | 800%    |
| 134 MB  | 214988ms | 26038ms | 826%    |

* chore: PR comments

* chore: decrease debounce to 1ms
  • Loading branch information
achingbrain authored May 27, 2020
1 parent 313ae3b commit 46490f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
hasBlockTimeout: 15 * SECOND,
provideTimeout: 15 * SECOND,
kMaxPriority: Math.pow(2, 31) - 1,
maxListeners: 1000
maxListeners: 1000,
wantlistSendDebounceMs: 1
}
3 changes: 2 additions & 1 deletion src/want-manager/msg-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const debounce = require('just-debounce-it')

const Message = require('../types/message')
const logger = require('../utils').logger
const { wantlistSendDebounceMs } = require('../constants')

module.exports = class MsgQueue {
constructor (selfPeerId, otherPeerId, network) {
Expand All @@ -13,7 +14,7 @@ module.exports = class MsgQueue {

this._entries = []
this._log = logger(selfPeerId, 'msgqueue', otherPeerId.toB58String().slice(0, 8))
this.sendEntries = debounce(this._sendEntries.bind(this), 200)
this.sendEntries = debounce(this._sendEntries.bind(this), wantlistSendDebounceMs)
}

addMessage (msg) {
Expand Down

0 comments on commit 46490f5

Please sign in to comment.