@cryptotaxi247 / kubo / commits / 326e6f2a4

use rate-limiter

@jbenet

Brian Tiger Chow committed Jan 20, 2015 at 16:54 UTC 326e6f2a4205a1bba25d9d4a08614a80403538f4
1 file changed +7 -3
blockservice/worker/worker.go
+7 -3
@@ -8,6 +8,7 @@ import (
8
9 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
10 process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
11 + ratelimit "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
12 blocks "github.com/jbenet/go-ipfs/blocks"
13 exchange "github.com/jbenet/go-ipfs/exchange"
14 util "github.com/jbenet/go-ipfs/util"
@@ -124,6 +125,7 @@ func (w *Worker) start(c Config) {
125 cancel()
126 })
127
128 + limiter := ratelimit.NewRateLimiter(proc, c.NumWorkers)
129 for {
130 select {
131 case <-proc.Closing():
@@ -132,9 +134,11 @@ func (w *Worker) start(c Config) {
134 if !ok {
135 return
136 }
135 - if err := w.exchange.HasBlock(ctx, block); err != nil {
136 - // TODO log event?
137 - }
137 + limiter.LimitedGo(func(proc process.Process) {
138 + if err := w.exchange.HasBlock(ctx, block); err != nil {
139 + // TODO log event?
140 + }
141 + })
142 }
143 }
144 })