Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8937f5fb
提交
8937f5fb
authored
3月 05, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement a worker to consolidate HasBlock provide calls into one to alieviate memory pressure
上级
4b7493e9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
56 行增加
和
3 行删除
+56
-3
bitswap.go
exchange/bitswap/bitswap.go
+3
-0
workers.go
exchange/bitswap/workers.go
+53
-3
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
8937f5fb
...
...
@@ -89,6 +89,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
batchRequests
:
make
(
chan
*
blockRequest
,
sizeBatchRequestChan
),
process
:
px
,
newBlocks
:
make
(
chan
*
blocks
.
Block
,
HasBlockBufferSize
),
provideKeys
:
make
(
chan
u
.
Key
),
}
network
.
SetDelegate
(
bs
)
...
...
@@ -124,6 +125,8 @@ type Bitswap struct {
process
process
.
Process
newBlocks
chan
*
blocks
.
Block
provideKeys
chan
u
.
Key
}
type
blockRequest
struct
{
...
...
exchange/bitswap/workers.go
浏览文件 @
8937f5fb
...
...
@@ -6,6 +6,7 @@ import (
inflect
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/chuckpreslar/inflect"
process
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
u
"github.com/jbenet/go-ipfs/util"
)
func
(
bs
*
Bitswap
)
startWorkers
(
px
process
.
Process
,
ctx
context
.
Context
)
{
...
...
@@ -24,6 +25,10 @@ func (bs *Bitswap) startWorkers(px process.Process, ctx context.Context) {
bs
.
rebroadcastWorker
(
ctx
)
})
px
.
Go
(
func
(
px
process
.
Process
)
{
bs
.
provideCollector
(
ctx
)
})
// Spawn up multiple workers to handle incoming blocks
// consider increasing number if providing blocks bottlenecks
// file transfers
...
...
@@ -58,13 +63,13 @@ func (bs *Bitswap) taskWorker(ctx context.Context) {
func
(
bs
*
Bitswap
)
provideWorker
(
ctx
context
.
Context
)
{
for
{
select
{
case
blk
,
ok
:=
<-
bs
.
newBlock
s
:
case
k
,
ok
:=
<-
bs
.
provideKey
s
:
if
!
ok
{
log
.
Debug
(
"
newBlock
s channel closed"
)
log
.
Debug
(
"
provideKey
s channel closed"
)
return
}
ctx
,
_
:=
context
.
WithTimeout
(
ctx
,
provideTimeout
)
err
:=
bs
.
network
.
Provide
(
ctx
,
blk
.
Key
()
)
err
:=
bs
.
network
.
Provide
(
ctx
,
k
)
if
err
!=
nil
{
log
.
Error
(
err
)
}
...
...
@@ -74,6 +79,51 @@ func (bs *Bitswap) provideWorker(ctx context.Context) {
}
}
func
(
bs
*
Bitswap
)
provideCollector
(
ctx
context
.
Context
)
{
defer
close
(
bs
.
provideKeys
)
var
toprovide
[]
u
.
Key
var
nextKey
u
.
Key
select
{
case
blk
,
ok
:=
<-
bs
.
newBlocks
:
if
!
ok
{
log
.
Debug
(
"newBlocks channel closed"
)
return
}
nextKey
=
blk
.
Key
()
case
<-
ctx
.
Done
()
:
return
}
for
{
select
{
case
blk
,
ok
:=
<-
bs
.
newBlocks
:
if
!
ok
{
log
.
Debug
(
"newBlocks channel closed"
)
return
}
toprovide
=
append
(
toprovide
,
blk
.
Key
())
case
bs
.
provideKeys
<-
nextKey
:
if
len
(
toprovide
)
>
0
{
nextKey
=
toprovide
[
0
]
toprovide
=
toprovide
[
1
:
]
}
else
{
select
{
case
blk
,
ok
:=
<-
bs
.
newBlocks
:
if
!
ok
{
return
}
nextKey
=
blk
.
Key
()
case
<-
ctx
.
Done
()
:
return
}
}
case
<-
ctx
.
Done
()
:
return
}
}
}
// TODO ensure only one active request per key
func
(
bs
*
Bitswap
)
clientWorker
(
parent
context
.
Context
)
{
defer
log
.
Info
(
"bitswap client worker shutting down..."
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论