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-merkledag
Commits
9eb1a21c
Commit
9eb1a21c
authored
Dec 09, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merkledag: add a concurrency limit to merkledag fetch graph
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
fdf8dcc9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
0 deletions
+14
-0
merkledag.go
merkledag.go
+14
-0
No files found.
merkledag.go
View file @
9eb1a21c
...
@@ -449,6 +449,10 @@ func EnumerateChildrenAsync(ctx context.Context, ds DAGService, c *cid.Cid, visi
...
@@ -449,6 +449,10 @@ func EnumerateChildrenAsync(ctx context.Context, ds DAGService, c *cid.Cid, visi
}
}
}
}
// FetchGraphConcurrency is total number of concurrenct fetches that
// 'fetchNodes' will start at a time
var
FetchGraphConcurrency
=
8
func
fetchNodes
(
ctx
context
.
Context
,
ds
DAGService
,
in
<-
chan
[]
*
cid
.
Cid
,
out
chan
<-
*
NodeOption
)
{
func
fetchNodes
(
ctx
context
.
Context
,
ds
DAGService
,
in
<-
chan
[]
*
cid
.
Cid
,
out
chan
<-
*
NodeOption
)
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
defer
func
()
{
defer
func
()
{
...
@@ -458,8 +462,13 @@ func fetchNodes(ctx context.Context, ds DAGService, in <-chan []*cid.Cid, out ch
...
@@ -458,8 +462,13 @@ func fetchNodes(ctx context.Context, ds DAGService, in <-chan []*cid.Cid, out ch
close
(
out
)
close
(
out
)
}()
}()
rateLimit
:=
make
(
chan
struct
{},
FetchGraphConcurrency
)
get
:=
func
(
ks
[]
*
cid
.
Cid
)
{
get
:=
func
(
ks
[]
*
cid
.
Cid
)
{
defer
wg
.
Done
()
defer
wg
.
Done
()
defer
func
()
{
<-
rateLimit
}()
nodes
:=
ds
.
GetMany
(
ctx
,
ks
)
nodes
:=
ds
.
GetMany
(
ctx
,
ks
)
for
opt
:=
range
nodes
{
for
opt
:=
range
nodes
{
select
{
select
{
...
@@ -471,6 +480,11 @@ func fetchNodes(ctx context.Context, ds DAGService, in <-chan []*cid.Cid, out ch
...
@@ -471,6 +480,11 @@ func fetchNodes(ctx context.Context, ds DAGService, in <-chan []*cid.Cid, out ch
}
}
for
ks
:=
range
in
{
for
ks
:=
range
in
{
select
{
case
rateLimit
<-
struct
{}{}
:
case
<-
ctx
.
Done
()
:
return
}
wg
.
Add
(
1
)
wg
.
Add
(
1
)
go
get
(
ks
)
go
get
(
ks
)
}
}
...
...
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