Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
03c910f9
提交
03c910f9
authored
2月 06, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #755 from jbenet/fix-ratelimiter-use
ratelimiter: fixing rate limiter use
上级
8558838d
91a79bc2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
28 行删除
+39
-28
worker.go
blockservice/worker/worker.go
+3
-4
swarm_dial.go
p2p/net/swarm/swarm_dial.go
+16
-13
notifier.go
thirdparty/notifier/notifier.go
+20
-11
没有找到文件。
blockservice/worker/worker.go
浏览文件 @
03c910f9
...
...
@@ -117,11 +117,10 @@ func (w *Worker) start(c Config) {
}
})
// reads from |workerChan| until process closes
w
.
process
.
Go
(
func
(
proc
process
.
Process
)
{
// reads from |workerChan| until w.process closes
limiter
:=
ratelimit
.
NewRateLimiter
(
w
.
process
,
c
.
NumWorkers
)
limiter
.
Go
(
func
(
proc
process
.
Process
)
{
ctx
:=
waitable
.
Context
(
proc
)
// shut down in-progress HasBlock when time to die
limiter
:=
ratelimit
.
NewRateLimiter
(
process
.
Background
(),
c
.
NumWorkers
)
defer
limiter
.
Close
()
for
{
select
{
case
<-
proc
.
Closing
()
:
...
...
p2p/net/swarm/swarm_dial.go
浏览文件 @
03c910f9
...
...
@@ -385,20 +385,23 @@ func (s *Swarm) dialAddrs(ctx context.Context, d *conn.Dialer, p peer.ID, remote
go
func
()
{
// rate limiting just in case. at most 10 addrs at once.
limiter
:=
ratelimit
.
NewRateLimiter
(
procctx
.
WithContext
(
ctx
),
10
)
// permute addrs so we try different sets first each time.
for
_
,
i
:=
range
rand
.
Perm
(
len
(
remoteAddrs
))
{
select
{
case
<-
foundConn
:
// if one of them succeeded already
break
default
:
limiter
.
Go
(
func
(
worker
process
.
Process
)
{
// permute addrs so we try different sets first each time.
for
_
,
i
:=
range
rand
.
Perm
(
len
(
remoteAddrs
))
{
select
{
case
<-
foundConn
:
// if one of them succeeded already
break
case
<-
worker
.
Closing
()
:
// our context was cancelled
break
default
:
}
workerAddr
:=
remoteAddrs
[
i
]
// shadow variable to avoid race
limiter
.
LimitedGo
(
func
(
worker
process
.
Process
)
{
dialSingleAddr
(
workerAddr
)
})
}
workerAddr
:=
remoteAddrs
[
i
]
// shadow variable to avoid race
limiter
.
Go
(
func
(
worker
process
.
Process
)
{
dialSingleAddr
(
workerAddr
)
})
}
})
}()
// wair fot the results.
...
...
thirdparty/notifier/notifier.go
浏览文件 @
03c910f9
...
...
@@ -120,18 +120,27 @@ func (n *Notifier) StopNotify(e Notifiee) {
// hooks into your object that block you accidentally.
func
(
n
*
Notifier
)
NotifyAll
(
notify
func
(
Notifiee
))
{
n
.
mu
.
Lock
()
if
n
.
nots
!=
nil
{
// so that zero-value is ready to be used.
for
notifiee
:=
range
n
.
nots
{
defer
n
.
mu
.
Unlock
()
if
n
.
nots
==
nil
{
// so that zero-value is ready to be used.
return
}
if
n
.
lim
==
nil
{
// no rate limit
go
notify
(
notifiee
)
}
else
{
notifiee
:=
notifiee
// rebind for data races
n
.
lim
.
LimitedGo
(
func
(
worker
process
.
Process
)
{
notify
(
notifiee
)
})
}
// no rate limiting.
if
n
.
lim
==
nil
{
for
notifiee
:=
range
n
.
nots
{
go
notify
(
notifiee
)
}
return
}
n
.
mu
.
Unlock
()
// with rate limiting.
n
.
lim
.
Go
(
func
(
worker
process
.
Process
)
{
for
notifiee
:=
range
n
.
nots
{
notifiee
:=
notifiee
// rebind for loop data races
n
.
lim
.
LimitedGo
(
func
(
worker
process
.
Process
)
{
notify
(
notifiee
)
})
}
})
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论