Skip to content

Commit

Permalink
Update distance tracking one provider at a time (#47)
Browse files Browse the repository at this point in the history
Distance tracking needs to run without taking excessibe memory, and this is bounded by setting the max advertisement chain depth. If there is unbounded concurrency, that is measuring all providers at the same time, then memory consumption can no longer be bounded.
  • Loading branch information
gammazero authored Jul 28, 2023
1 parent 2c3d896 commit b033ae8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
11 changes: 2 additions & 9 deletions pkg/dtrack/distance_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dtrack
import (
"context"
"fmt"
"sync"
"time"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -88,15 +87,9 @@ func runTracker(ctx context.Context, include, exclude map[peer.ID]struct{}, prov
}

func updateTracks(ctx context.Context, provCache *pcache.ProviderCache, tracks map[peer.ID]*distTrack, depthLimit int64, updates chan<- DistanceUpdate) {
var wg sync.WaitGroup
for providerID, dtrack := range tracks {
wg.Add(1)
go func(pid peer.ID, track *distTrack) {
updateTrack(ctx, pid, track, provCache, depthLimit, updates)
wg.Done()
}(providerID, dtrack)
for providerID, track := range tracks {
updateTrack(ctx, providerID, track, provCache, depthLimit, updates)
}
wg.Wait()
}

func updateTrack(ctx context.Context, pid peer.ID, track *distTrack, provCache *pcache.ProviderCache, depthLimit int64, updates chan<- DistanceUpdate) {
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.0.6"
"version": "v0.0.7"
}

0 comments on commit b033ae8

Please sign in to comment.