Skip to content

Commit 759f56f

Browse files
authored
fix(puller): rate limit hist sync only (#4508)
1 parent 29e8462 commit 759f56f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/puller/puller.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func New(
9595
blockLister: blockLister,
9696
rate: rate.New(DefaultHistRateWindow),
9797
cancel: func() { /* Noop, since the context is initialized in the Start(). */ },
98-
limiter: ratelimit.NewLimiter(ratelimit.Every(time.Second), int(swarm.MaxBins)), // allows for 1 sync per second, max bins bursts
98+
limiter: ratelimit.NewLimiter(ratelimit.Every(time.Second/2), int(swarm.MaxBins)), // allows for 2 syncs per second, max bins bursts
9999
}
100100

101101
return p
@@ -305,8 +305,15 @@ func (p *Puller) syncWorker(ctx context.Context, peer swarm.Address, bin uint8,
305305

306306
for {
307307

308-
// rate limit within neighborhood
309-
if bin >= p.radius.StorageRadius() {
308+
s, _, _, err := p.nextPeerInterval(peer, bin)
309+
if err != nil {
310+
p.metrics.SyncWorkerErrCounter.Inc()
311+
p.logger.Error(err, "syncWorker nextPeerInterval failed, quitting")
312+
return
313+
}
314+
315+
// rate limit historical syncing
316+
if s <= cur {
310317
_ = p.limiter.Wait(ctx)
311318
}
312319

@@ -319,13 +326,6 @@ func (p *Puller) syncWorker(ctx context.Context, peer swarm.Address, bin uint8,
319326

320327
p.metrics.SyncWorkerIterCounter.Inc()
321328

322-
s, _, _, err := p.nextPeerInterval(peer, bin)
323-
if err != nil {
324-
p.metrics.SyncWorkerErrCounter.Inc()
325-
p.logger.Error(err, "syncWorker nextPeerInterval failed, quitting")
326-
return
327-
}
328-
329329
syncStart := time.Now()
330330
top, count, err := p.syncer.Sync(ctx, peer, bin, s)
331331

0 commit comments

Comments
 (0)