Skip to content

Commit 4017e53

Browse files
committed
refactor: adjust message queue debounce limits
This commit was moved from ipfs/go-bitswap@7ccab36
1 parent f090cdb commit 4017e53

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

bitswap/internal/messagequeue/messagequeue.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const (
3232
maxPriority = math.MaxInt32
3333
// sendMessageDebounce is the debounce duration when calling sendMessage()
3434
sendMessageDebounce = time.Millisecond
35-
// when we reach sendMessaageCuttoff wants/cancels, we'll send the message immediately.
36-
sendMessageCuttoff = 100
35+
// when we reach sendMessageCutoff wants/cancels, we'll send the message immediately.
36+
sendMessageCutoff = 256
3737
// when we debounce for more than sendMessageMaxDelay, we'll send the
3838
// message immediately.
39-
sendMessageMaxDelay = 100 * time.Millisecond
39+
sendMessageMaxDelay = 20 * time.Millisecond
4040
)
4141

4242
// MessageNetwork is any network that can connect peers and generate a message
@@ -286,6 +286,8 @@ func (mq *MessageQueue) runQueue() {
286286
// Create a timer for debouncing scheduled work.
287287
scheduleWork := time.NewTimer(0)
288288
if !scheduleWork.Stop() {
289+
// Need to drain the timer if Stop() returns false
290+
// See: https://golang.org/pkg/time/#Timer.Stop
289291
<-scheduleWork.C
290292
}
291293

@@ -302,12 +304,13 @@ func (mq *MessageQueue) runQueue() {
302304
if workScheduled.IsZero() {
303305
workScheduled = when
304306
} else if !scheduleWork.Stop() {
307+
// Need to drain the timer if Stop() returns false
305308
<-scheduleWork.C
306309
}
307310

308311
// If we have too many updates and/or we've waited too
309312
// long, send immediately.
310-
if mq.pendingWorkCount() > sendMessageCuttoff ||
313+
if mq.pendingWorkCount() > sendMessageCutoff ||
311314
time.Since(workScheduled) >= sendMessageMaxDelay {
312315
mq.sendIfReady()
313316
workScheduled = time.Time{}

0 commit comments

Comments
 (0)