Skip to content

Commit

Permalink
reprovide: wait a minute before reproviding
Browse files Browse the repository at this point in the history
Many times, a node will start up only to shut down immediately.
In these cases, reproviding is costly to both the node, and the
rest of the network. Also note: the probability of a node being
up another minute increases with uptime.

TODO: maybe this should be 5 * time.Minute
  • Loading branch information
jbenet committed Jan 23, 2015
1 parent 95d58b2 commit 4a5f5e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion exchange/reprovide/reprovide.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func NewReprovider(rsys routing.IpfsRouting, bstore blocks.Blockstore) *Reprovid
}

func (rp *Reprovider) ProvideEvery(ctx context.Context, tick time.Duration) {
after := time.After(0)
// dont reprovide immediately.
// may have just started the daemon and shutting it down immediately.
// probability( up another minute | uptime ) increases with uptime.
after := time.After(time.Minute)
for {
select {
case <-ctx.Done():
Expand Down
2 changes: 1 addition & 1 deletion pin/indirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
keys = append(keys, k)
refcnt[k] = v
}
log.Debugf("indirPin keys: %#v", keys)
// log.Debugf("indirPin keys: %#v", keys)

return &indirectPin{blockset: set.SimpleSetFromKeys(keys), refCounts: refcnt}, nil
}
Expand Down
12 changes: 10 additions & 2 deletions routing/dht/dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
// 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd
// probably because results compound

var cfg BootstrapConfig
cfg = DefaultBootstrapConfig
cfg.Queries = 3

start := rand.Intn(len(dhts)) // randomize to decrease bias.
for i := range dhts {
dht := dhts[(start+i)%len(dhts)]
dht.runBootstrap(ctx, 3)
dht.runBootstrap(ctx, cfg)
}
cancel()
}
Expand Down Expand Up @@ -356,11 +360,15 @@ func TestPeriodicBootstrap(t *testing.T) {
signal := make(chan time.Time)
allSignals := []chan time.Time{}

var cfg BootstrapConfig
cfg = DefaultBootstrapConfig
cfg.Queries = 5

// kick off periodic bootstrappers with instrumented signals.
for _, dht := range dhts {
s := make(chan time.Time)
allSignals = append(allSignals, s)
dht.BootstrapOnSignal(5, s)
dht.BootstrapOnSignal(cfg, s)
}
go amplify(signal, allSignals)

Expand Down

1 comment on commit 4a5f5e2

@jbenet
Copy link
Member Author

@jbenet jbenet commented on 4a5f5e2 Jan 23, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.