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
af8cba85
Commit
af8cba85
authored
Apr 30, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: only record latency for first response per want
parent
5c215f41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
4 deletions
+64
-4
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+20
-4
internal/messagequeue/messagequeue_test.go
internal/messagequeue/messagequeue_test.go
+44
-0
No files found.
internal/messagequeue/messagequeue.go
View file @
af8cba85
...
...
@@ -147,6 +147,13 @@ func (r *recallWantlist) SentAt(c cid.Cid, at time.Time) {
}
}
// ClearSentAt clears out the record of the time a want was sent.
// We clear the sent at time when we receive a response for a key so that
// subsequent responses for the key don't appear to be even further delayed.
func
(
r
*
recallWantlist
)
ClearSentAt
(
c
cid
.
Cid
)
{
delete
(
r
.
sentAt
,
c
)
}
type
peerConn
struct
{
p
peer
.
ID
network
MessageNetwork
...
...
@@ -549,11 +556,20 @@ func (mq *MessageQueue) handleResponse(ks []cid.Cid) {
// Find the earliest request so as to calculate the longest latency as
// we want to be conservative when setting the timeout.
for
_
,
c
:=
range
ks
{
if
at
,
ok
:=
mq
.
bcstWants
.
sentAt
[
c
];
ok
&&
(
earliest
.
IsZero
()
||
at
.
Before
(
earliest
))
{
earliest
=
at
if
at
,
ok
:=
mq
.
bcstWants
.
sentAt
[
c
];
ok
{
if
earliest
.
IsZero
()
||
at
.
Before
(
earliest
)
{
earliest
=
at
}
mq
.
bcstWants
.
ClearSentAt
(
c
)
}
if
at
,
ok
:=
mq
.
peerWants
.
sentAt
[
c
];
ok
&&
(
earliest
.
IsZero
()
||
at
.
Before
(
earliest
))
{
earliest
=
at
if
at
,
ok
:=
mq
.
peerWants
.
sentAt
[
c
];
ok
{
if
earliest
.
IsZero
()
||
at
.
Before
(
earliest
)
{
earliest
=
at
}
// Clear out the sent time for the CID because we only want to
// record the latency between the request and the first response
// for that CID (not subsequent responses)
mq
.
peerWants
.
ClearSentAt
(
c
)
}
}
...
...
internal/messagequeue/messagequeue_test.go
View file @
af8cba85
...
...
@@ -640,6 +640,50 @@ func TestResponseReceived(t *testing.T) {
}
}
func
TestResponseReceivedAppliesForFirstResponseOnly
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
messagesSent
:=
make
(
chan
[]
bsmsg
.
Entry
)
resetChan
:=
make
(
chan
struct
{},
1
)
fakeSender
:=
newFakeMessageSender
(
resetChan
,
messagesSent
,
false
)
fakenet
:=
&
fakeMessageNetwork
{
nil
,
nil
,
fakeSender
}
peerID
:=
testutil
.
GeneratePeers
(
1
)[
0
]
dhtm
:=
&
fakeDontHaveTimeoutMgr
{}
messageQueue
:=
newMessageQueue
(
ctx
,
peerID
,
fakenet
,
maxMessageSize
,
sendErrorBackoff
,
dhtm
)
messageQueue
.
Startup
()
cids
:=
testutil
.
GenerateCids
(
2
)
// Add some wants and wait 10ms
messageQueue
.
AddWants
(
cids
,
nil
)
collectMessages
(
ctx
,
t
,
messagesSent
,
10
*
time
.
Millisecond
)
// Receive a response for the wants
messageQueue
.
ResponseReceived
(
cids
)
// Wait another 10ms
time
.
Sleep
(
10
*
time
.
Millisecond
)
// Message queue should inform DHTM of first response
upds
:=
dhtm
.
latencyUpdates
()
if
len
(
upds
)
!=
1
{
t
.
Fatal
(
"expected one latency update"
)
}
// Receive a second response for the same wants
messageQueue
.
ResponseReceived
(
cids
)
// Wait for the response to be processed by the message queue
time
.
Sleep
(
10
*
time
.
Millisecond
)
// Message queue should not inform DHTM of second response because the
// CIDs are a subset of the first response
upds
=
dhtm
.
latencyUpdates
()
if
len
(
upds
)
!=
1
{
t
.
Fatal
(
"expected one latency update"
)
}
}
func
filterWantTypes
(
wantlist
[]
bsmsg
.
Entry
)
([]
cid
.
Cid
,
[]
cid
.
Cid
,
[]
cid
.
Cid
)
{
var
wbs
[]
cid
.
Cid
var
whs
[]
cid
.
Cid
...
...
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