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
c8f38296
Commit
c8f38296
authored
Jul 06, 2017
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract bitswap metrics to separate struct for 64bit alignment
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
194f8988
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
27 deletions
+34
-27
bitswap.go
bitswap.go
+19
-13
bitswap_test.go
bitswap_test.go
+1
-1
session_test.go
session_test.go
+2
-2
stat.go
stat.go
+10
-9
workers.go
workers.go
+2
-2
No files found.
bitswap.go
View file @
c8f38296
...
@@ -99,6 +99,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
...
@@ -99,6 +99,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
newBlocks
:
make
(
chan
*
cid
.
Cid
,
HasBlockBufferSize
),
newBlocks
:
make
(
chan
*
cid
.
Cid
,
HasBlockBufferSize
),
provideKeys
:
make
(
chan
*
cid
.
Cid
,
provideKeysBufferSize
),
provideKeys
:
make
(
chan
*
cid
.
Cid
,
provideKeysBufferSize
),
wm
:
NewWantManager
(
ctx
,
network
),
wm
:
NewWantManager
(
ctx
,
network
),
counters
:
new
(
counters
),
dupMetric
:
dupHist
,
dupMetric
:
dupHist
,
allMetric
:
allHist
,
allMetric
:
allHist
,
...
@@ -152,14 +153,8 @@ type Bitswap struct {
...
@@ -152,14 +153,8 @@ type Bitswap struct {
process
process
.
Process
process
process
.
Process
// Counters for various statistics
// Counters for various statistics
counterLk
sync
.
Mutex
counterLk
sync
.
Mutex
blocksRecvd
int
counters
*
counters
dupBlocksRecvd
int
dupDataRecvd
uint64
blocksSent
int
dataSent
uint64
dataRecvd
uint64
messagesRecvd
uint64
// Metrics interface metrics
// Metrics interface metrics
dupMetric
metrics
.
Histogram
dupMetric
metrics
.
Histogram
...
@@ -173,6 +168,16 @@ type Bitswap struct {
...
@@ -173,6 +168,16 @@ type Bitswap struct {
sessIDLk
sync
.
Mutex
sessIDLk
sync
.
Mutex
}
}
type
counters
struct
{
blocksRecvd
uint64
dupBlocksRecvd
uint64
dupDataRecvd
uint64
blocksSent
uint64
dataSent
uint64
dataRecvd
uint64
messagesRecvd
uint64
}
type
blockRequest
struct
{
type
blockRequest
struct
{
Cid
*
cid
.
Cid
Cid
*
cid
.
Cid
Ctx
context
.
Context
Ctx
context
.
Context
...
@@ -338,7 +343,7 @@ func (bs *Bitswap) SessionsForBlock(c *cid.Cid) []*Session {
...
@@ -338,7 +343,7 @@ func (bs *Bitswap) SessionsForBlock(c *cid.Cid) []*Session {
}
}
func
(
bs
*
Bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
ID
,
incoming
bsmsg
.
BitSwapMessage
)
{
func
(
bs
*
Bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
p
peer
.
ID
,
incoming
bsmsg
.
BitSwapMessage
)
{
atomic
.
AddUint64
(
&
bs
.
messagesRecvd
,
1
)
atomic
.
AddUint64
(
&
bs
.
counters
.
messagesRecvd
,
1
)
// This call records changes to wantlists, blocks received,
// This call records changes to wantlists, blocks received,
// and number of bytes transfered.
// and number of bytes transfered.
...
@@ -403,12 +408,13 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) {
...
@@ -403,12 +408,13 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) {
bs
.
counterLk
.
Lock
()
bs
.
counterLk
.
Lock
()
defer
bs
.
counterLk
.
Unlock
()
defer
bs
.
counterLk
.
Unlock
()
c
:=
bs
.
counters
bs
.
blocksRecvd
++
c
.
blocksRecvd
++
bs
.
dataRecvd
+=
uint64
(
len
(
b
.
RawData
()))
c
.
dataRecvd
+=
uint64
(
len
(
b
.
RawData
()))
if
has
{
if
has
{
bs
.
dupBlocksRecvd
++
c
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
blkLen
)
c
.
dupDataRecvd
+=
uint64
(
blkLen
)
}
}
}
}
...
...
bitswap_test.go
View file @
c8f38296
...
@@ -291,7 +291,7 @@ func TestEmptyKey(t *testing.T) {
...
@@ -291,7 +291,7 @@ func TestEmptyKey(t *testing.T) {
}
}
}
}
func
assertStat
(
st
*
Stat
,
sblks
,
rblks
int
,
sdata
,
rdata
uint64
)
error
{
func
assertStat
(
st
*
Stat
,
sblks
,
rblks
,
sdata
,
rdata
uint64
)
error
{
if
sblks
!=
st
.
BlocksSent
{
if
sblks
!=
st
.
BlocksSent
{
return
fmt
.
Errorf
(
"mismatch in blocks sent: %d vs %d"
,
sblks
,
st
.
BlocksSent
)
return
fmt
.
Errorf
(
"mismatch in blocks sent: %d vs %d"
,
sblks
,
st
.
BlocksSent
)
}
}
...
...
session_test.go
View file @
c8f38296
...
@@ -103,8 +103,8 @@ func TestSessionBetweenPeers(t *testing.T) {
...
@@ -103,8 +103,8 @@ func TestSessionBetweenPeers(t *testing.T) {
}
}
}
}
for
_
,
is
:=
range
inst
[
2
:
]
{
for
_
,
is
:=
range
inst
[
2
:
]
{
if
is
.
Exchange
.
messagesRecvd
>
2
{
if
is
.
Exchange
.
counters
.
messagesRecvd
>
2
{
t
.
Fatal
(
"uninvolved nodes should only receive two messages"
,
is
.
Exchange
.
messagesRecvd
)
t
.
Fatal
(
"uninvolved nodes should only receive two messages"
,
is
.
Exchange
.
counters
.
messagesRecvd
)
}
}
}
}
}
}
...
...
stat.go
View file @
c8f38296
...
@@ -10,11 +10,11 @@ type Stat struct {
...
@@ -10,11 +10,11 @@ type Stat struct {
ProvideBufLen
int
ProvideBufLen
int
Wantlist
[]
*
cid
.
Cid
Wantlist
[]
*
cid
.
Cid
Peers
[]
string
Peers
[]
string
BlocksReceived
int
BlocksReceived
u
int
64
DataReceived
uint64
DataReceived
uint64
BlocksSent
int
BlocksSent
u
int
64
DataSent
uint64
DataSent
uint64
DupBlksReceived
int
DupBlksReceived
u
int
64
DupDataReceived
uint64
DupDataReceived
uint64
}
}
...
@@ -23,12 +23,13 @@ func (bs *Bitswap) Stat() (*Stat, error) {
...
@@ -23,12 +23,13 @@ func (bs *Bitswap) Stat() (*Stat, error) {
st
.
ProvideBufLen
=
len
(
bs
.
newBlocks
)
st
.
ProvideBufLen
=
len
(
bs
.
newBlocks
)
st
.
Wantlist
=
bs
.
GetWantlist
()
st
.
Wantlist
=
bs
.
GetWantlist
()
bs
.
counterLk
.
Lock
()
bs
.
counterLk
.
Lock
()
st
.
BlocksReceived
=
bs
.
blocksRecvd
c
:=
bs
.
counters
st
.
DupBlksReceived
=
bs
.
dupBlocksRecvd
st
.
BlocksReceived
=
c
.
blocksRecvd
st
.
DupDataReceived
=
bs
.
dupDataRecvd
st
.
DupBlksReceived
=
c
.
dupBlocksRecvd
st
.
BlocksSent
=
bs
.
blocksSent
st
.
DupDataReceived
=
c
.
dupDataRecvd
st
.
DataSent
=
bs
.
dataSent
st
.
BlocksSent
=
c
.
blocksSent
st
.
DataReceived
=
bs
.
dataRecvd
st
.
DataSent
=
c
.
dataSent
st
.
DataReceived
=
c
.
dataRecvd
bs
.
counterLk
.
Unlock
()
bs
.
counterLk
.
Unlock
()
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
...
...
workers.go
View file @
c8f38296
...
@@ -73,8 +73,8 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
...
@@ -73,8 +73,8 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
bs
.
wm
.
SendBlock
(
ctx
,
envelope
)
bs
.
wm
.
SendBlock
(
ctx
,
envelope
)
bs
.
counterLk
.
Lock
()
bs
.
counterLk
.
Lock
()
bs
.
blocksSent
++
bs
.
counters
.
blocksSent
++
bs
.
dataSent
+=
uint64
(
len
(
envelope
.
Block
.
RawData
()))
bs
.
counters
.
dataSent
+=
uint64
(
len
(
envelope
.
Block
.
RawData
()))
bs
.
counterLk
.
Unlock
()
bs
.
counterLk
.
Unlock
()
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
...
...
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