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
6e6c6638
Commit
6e6c6638
authored
Mar 05, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement a worker to consolidate HasBlock provide calls into one to alieviate memory pressure
parent
309229da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
3 deletions
+56
-3
bitswap.go
bitswap.go
+3
-0
workers.go
workers.go
+53
-3
No files found.
bitswap.go
View file @
6e6c6638
...
...
@@ -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
{
...
...
workers.go
View file @
6e6c6638
...
...
@@ -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
bl
k
,
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..."
)
...
...
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