Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
7ccab36f
Commit
7ccab36f
authored
Feb 13, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: adjust message queue debounce limits
parent
777c0d9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+7
-4
No files found.
internal/messagequeue/messagequeue.go
View file @
7ccab36f
...
...
@@ -32,11 +32,11 @@ const (
maxPriority
=
math
.
MaxInt32
// sendMessageDebounce is the debounce duration when calling sendMessage()
sendMessageDebounce
=
time
.
Millisecond
// when we reach sendMessa
a
geCut
t
off wants/cancels, we'll send the message immediately.
sendMessageCut
t
off
=
100
// when we reach sendMessageCutoff wants/cancels, we'll send the message immediately.
sendMessageCutoff
=
256
// when we debounce for more than sendMessageMaxDelay, we'll send the
// message immediately.
sendMessageMaxDelay
=
10
0
*
time
.
Millisecond
sendMessageMaxDelay
=
2
0
*
time
.
Millisecond
)
// MessageNetwork is any network that can connect peers and generate a message
...
...
@@ -286,6 +286,8 @@ func (mq *MessageQueue) runQueue() {
// Create a timer for debouncing scheduled work.
scheduleWork
:=
time
.
NewTimer
(
0
)
if
!
scheduleWork
.
Stop
()
{
// Need to drain the timer if Stop() returns false
// See: https://golang.org/pkg/time/#Timer.Stop
<-
scheduleWork
.
C
}
...
...
@@ -302,12 +304,13 @@ func (mq *MessageQueue) runQueue() {
if
workScheduled
.
IsZero
()
{
workScheduled
=
when
}
else
if
!
scheduleWork
.
Stop
()
{
// Need to drain the timer if Stop() returns false
<-
scheduleWork
.
C
}
// If we have too many updates and/or we've waited too
// long, send immediately.
if
mq
.
pendingWorkCount
()
>
sendMessageCut
t
off
||
if
mq
.
pendingWorkCount
()
>
sendMessageCutoff
||
time
.
Since
(
workScheduled
)
>=
sendMessageMaxDelay
{
mq
.
sendIfReady
()
workScheduled
=
time
.
Time
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment