Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
124afdba
提交
124afdba
authored
7月 06, 2017
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extract bitswap metrics to separate struct for 64bit alignment
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
eab2024e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
34 行增加
和
27 行删除
+34
-27
bitswap.go
exchange/bitswap/bitswap.go
+19
-13
bitswap_test.go
exchange/bitswap/bitswap_test.go
+1
-1
session_test.go
exchange/bitswap/session_test.go
+2
-2
stat.go
exchange/bitswap/stat.go
+10
-9
workers.go
exchange/bitswap/workers.go
+2
-2
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
124afdba
...
...
@@ -99,6 +99,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
newBlocks
:
make
(
chan
*
cid
.
Cid
,
HasBlockBufferSize
),
provideKeys
:
make
(
chan
*
cid
.
Cid
,
provideKeysBufferSize
),
wm
:
NewWantManager
(
ctx
,
network
),
counters
:
new
(
counters
),
dupMetric
:
dupHist
,
allMetric
:
allHist
,
...
...
@@ -152,14 +153,8 @@ type Bitswap struct {
process
process
.
Process
// Counters for various statistics
counterLk
sync
.
Mutex
blocksRecvd
int
dupBlocksRecvd
int
dupDataRecvd
uint64
blocksSent
int
dataSent
uint64
dataRecvd
uint64
messagesRecvd
uint64
counterLk
sync
.
Mutex
counters
*
counters
// Metrics interface metrics
dupMetric
metrics
.
Histogram
...
...
@@ -173,6 +168,16 @@ type Bitswap struct {
sessIDLk
sync
.
Mutex
}
type
counters
struct
{
blocksRecvd
uint64
dupBlocksRecvd
uint64
dupDataRecvd
uint64
blocksSent
uint64
dataSent
uint64
dataRecvd
uint64
messagesRecvd
uint64
}
type
blockRequest
struct
{
Cid
*
cid
.
Cid
Ctx
context
.
Context
...
...
@@ -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
)
{
atomic
.
AddUint64
(
&
bs
.
messagesRecvd
,
1
)
atomic
.
AddUint64
(
&
bs
.
counters
.
messagesRecvd
,
1
)
// This call records changes to wantlists, blocks received,
// and number of bytes transfered.
...
...
@@ -403,12 +408,13 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) {
bs
.
counterLk
.
Lock
()
defer
bs
.
counterLk
.
Unlock
()
c
:=
bs
.
counters
bs
.
blocksRecvd
++
bs
.
dataRecvd
+=
uint64
(
len
(
b
.
RawData
()))
c
.
blocksRecvd
++
c
.
dataRecvd
+=
uint64
(
len
(
b
.
RawData
()))
if
has
{
bs
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
blkLen
)
c
.
dupBlocksRecvd
++
c
.
dupDataRecvd
+=
uint64
(
blkLen
)
}
}
...
...
exchange/bitswap/bitswap_test.go
浏览文件 @
124afdba
...
...
@@ -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
{
return
fmt
.
Errorf
(
"mismatch in blocks sent: %d vs %d"
,
sblks
,
st
.
BlocksSent
)
}
...
...
exchange/bitswap/session_test.go
浏览文件 @
124afdba
...
...
@@ -103,8 +103,8 @@ func TestSessionBetweenPeers(t *testing.T) {
}
}
for
_
,
is
:=
range
inst
[
2
:
]
{
if
is
.
Exchange
.
messagesRecvd
>
2
{
t
.
Fatal
(
"uninvolved nodes should only receive two messages"
,
is
.
Exchange
.
messagesRecvd
)
if
is
.
Exchange
.
counters
.
messagesRecvd
>
2
{
t
.
Fatal
(
"uninvolved nodes should only receive two messages"
,
is
.
Exchange
.
counters
.
messagesRecvd
)
}
}
}
...
...
exchange/bitswap/stat.go
浏览文件 @
124afdba
...
...
@@ -10,11 +10,11 @@ type Stat struct {
ProvideBufLen
int
Wantlist
[]
*
cid
.
Cid
Peers
[]
string
BlocksReceived
int
BlocksReceived
uint64
DataReceived
uint64
BlocksSent
int
BlocksSent
uint64
DataSent
uint64
DupBlksReceived
int
DupBlksReceived
uint64
DupDataReceived
uint64
}
...
...
@@ -23,12 +23,13 @@ func (bs *Bitswap) Stat() (*Stat, error) {
st
.
ProvideBufLen
=
len
(
bs
.
newBlocks
)
st
.
Wantlist
=
bs
.
GetWantlist
()
bs
.
counterLk
.
Lock
()
st
.
BlocksReceived
=
bs
.
blocksRecvd
st
.
DupBlksReceived
=
bs
.
dupBlocksRecvd
st
.
DupDataReceived
=
bs
.
dupDataRecvd
st
.
BlocksSent
=
bs
.
blocksSent
st
.
DataSent
=
bs
.
dataSent
st
.
DataReceived
=
bs
.
dataRecvd
c
:=
bs
.
counters
st
.
BlocksReceived
=
c
.
blocksRecvd
st
.
DupBlksReceived
=
c
.
dupBlocksRecvd
st
.
DupDataReceived
=
c
.
dupDataRecvd
st
.
BlocksSent
=
c
.
blocksSent
st
.
DataSent
=
c
.
dataSent
st
.
DataReceived
=
c
.
dataRecvd
bs
.
counterLk
.
Unlock
()
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
...
...
exchange/bitswap/workers.go
浏览文件 @
124afdba
...
...
@@ -73,8 +73,8 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
bs
.
wm
.
SendBlock
(
ctx
,
envelope
)
bs
.
counterLk
.
Lock
()
bs
.
blocksSent
++
bs
.
dataSent
+=
uint64
(
len
(
envelope
.
Block
.
RawData
()))
bs
.
counters
.
blocksSent
++
bs
.
counters
.
dataSent
+=
uint64
(
len
(
envelope
.
Block
.
RawData
()))
bs
.
counterLk
.
Unlock
()
case
<-
ctx
.
Done
()
:
return
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论