Skip to content

Commit

Permalink
opt: reduce unnecessary pullsyncing (#4764)
Browse files Browse the repository at this point in the history
  • Loading branch information
istae authored Aug 16, 2024
1 parent 2374b05 commit d7c234a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/puller/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
recalcPeersDur = time.Minute * 5

maxChunksPerSecond = 1000 // roughly 4 MB/s

maxPODelta = 2 // the lowest level of proximity order (of peers) subtracted from the storage radius allowed for chunk syncing.
)

type Options struct {
Expand Down Expand Up @@ -262,6 +264,7 @@ func (p *Puller) syncPeer(ctx context.Context, peer *syncPeer, storageRadius uin
*/

if peer.po >= storageRadius {

// cancel all bins lower than the storage radius
for bin := uint8(0); bin < storageRadius; bin++ {
peer.cancelBin(bin)
Expand All @@ -274,7 +277,7 @@ func (p *Puller) syncPeer(ctx context.Context, peer *syncPeer, storageRadius uin
}
}

} else {
} else if storageRadius-peer.po <= maxPODelta {
// cancel all non-po bins, if any
for bin := uint8(0); bin < p.bins; bin++ {
if bin != peer.po {
Expand All @@ -285,6 +288,10 @@ func (p *Puller) syncPeer(ctx context.Context, peer *syncPeer, storageRadius uin
if !peer.isBinSyncing(peer.po) {
p.syncPeerBin(ctx, peer, peer.po, peer.cursors[peer.po])
}
} else {
for bin := uint8(0); bin < p.bins; bin++ {
peer.cancelBin(bin)
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/pullsync/pullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
MaxCursor = math.MaxUint64
DefaultMaxPage uint64 = 250
pageTimeout = time.Second
makeOfferTimeout = 5 * time.Minute
makeOfferTimeout = 15 * time.Minute
)

// Interface is the PullSync interface.
Expand Down

0 comments on commit d7c234a

Please sign in to comment.