Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 2f865f7

Browse files
committed
fix(benchmarks): actually test providing
1 parent ff8df50 commit 2f865f7

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

benchmarks_test.go

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
mockrouting "github.com/ipfs/go-ipfs-routing/mock"
2626
)
2727

28+
type topologyFunc func(b *testing.B, instances []testinstance.Instance)
29+
2830
type fetchFunc func(b *testing.B, bs *bitswap.Bitswap, ks []cid.Cid)
2931

3032
type distFunc func(b *testing.B, provs []testinstance.Instance, blocks []blocks.Block)
@@ -171,14 +173,14 @@ func BenchmarkDupsManyNodesRealWorldNetworkWithRealDHT(b *testing.B) {
171173
slowNetworkDelay := delay.Delay(fastSpeed, slowNetworkDelayGenerator)
172174
slowBandwidthGenerator := tn.VariableRateLimitGenerator(slowBandwidth, slowBandwidthDeviation, nil)
173175

174-
b.Run("10Nodes-AllToAll-BigBatch-FastNetwork", func(b *testing.B) {
175-
subtestDistributeAndFetchWithRealDHT(b, 20, 10, fastNetworkDelay, fastBandwidthGenerator, stdBlockSize, allToAll, batchFetchAll)
176+
b.Run("10Nodes-RandomRandom-BigBatch-FastNetwork", func(b *testing.B) {
177+
subtestDistributeAndFetchWithRealDHT(b, 20, 10, fastNetworkDelay, fastBandwidthGenerator, stdBlockSize, starPattern, randomRandom, batchFetchAll)
176178
})
177-
b.Run("10Nodes-AllToAll-BigBatch-AverageVariableSpeedNetwork", func(b *testing.B) {
178-
subtestDistributeAndFetchWithRealDHT(b, 20, 10, averageNetworkDelay, averageBandwidthGenerator, stdBlockSize, allToAll, batchFetchAll)
179+
b.Run("10Nodes-RandomRandom-BigBatch-AverageVariableSpeedNetwork", func(b *testing.B) {
180+
subtestDistributeAndFetchWithRealDHT(b, 20, 10, averageNetworkDelay, averageBandwidthGenerator, stdBlockSize, starPattern, randomRandom, batchFetchAll)
179181
})
180-
b.Run("10Nodes-AllToAll-BigBatch-SlowVariableSpeedNetwork", func(b *testing.B) {
181-
subtestDistributeAndFetchWithRealDHT(b, 20, 10, slowNetworkDelay, slowBandwidthGenerator, stdBlockSize, allToAll, batchFetchAll)
182+
b.Run("10Nodes-RandomRandom-BigBatch-SlowVariableSpeedNetwork", func(b *testing.B) {
183+
subtestDistributeAndFetchWithRealDHT(b, 20, 10, slowNetworkDelay, slowBandwidthGenerator, stdBlockSize, starPattern, randomRandom, batchFetchAll)
182184
})
183185
out, _ := json.MarshalIndent(benchmarkLog, "", " ")
184186
ioutil.WriteFile("tmp/rw-benchmark.json", out, 0666)
@@ -189,7 +191,7 @@ func subtestDistributeAndFetch(b *testing.B, numnodes, numblks int, d delay.D, d
189191
start := time.Now()
190192
net := tn.VirtualNetwork(mockrouting.NewServer(), d)
191193

192-
ig := testinstance.NewTestInstanceGenerator(net)
194+
ig := testinstance.NewTestInstanceGenerator(net, bitswap.ProvideEnabled(false))
193195
defer ig.Close()
194196

195197
bg := blocksutil.NewBlockGenerator()
@@ -206,7 +208,7 @@ func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d
206208
start := time.Now()
207209
net := tn.RateLimitedVirtualNetwork(mockrouting.NewServer(), d, rateLimitGenerator)
208210

209-
ig := testinstance.NewTestInstanceGenerator(net)
211+
ig := testinstance.NewTestInstanceGenerator(net, bitswap.ProvideEnabled(false))
210212
defer ig.Close()
211213

212214
instances := ig.Instances(numnodes)
@@ -216,7 +218,7 @@ func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d
216218
}
217219
}
218220

219-
func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d delay.D, rateLimitGenerator tn.RateLimitGenerator, blockSize int64, df distFunc, ff fetchFunc) {
221+
func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d delay.D, rateLimitGenerator tn.RateLimitGenerator, blockSize int64, tf topologyFunc, df distFunc, ff fetchFunc) {
220222
start := time.Now()
221223
ctx := context.Background()
222224
mn := mocknet.New(ctx)
@@ -236,8 +238,6 @@ func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d
236238
}
237239
mn.LinkAll()
238240
for i, inst := range instances {
239-
// Connect in a star pattern to first node only (like a bootstrap)
240-
inst.Adapter.ConnectTo(context.Background(), instances[0].Peer)
241241
// rate limit and delate connections
242242
for j := i + 1; j < len(instances); j++ {
243243
oinst := instances[j]
@@ -248,6 +248,8 @@ func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d
248248
}
249249
}
250250

251+
tf(b, instances)
252+
251253
blocks := testutil.GenerateBlocksOfSize(numblks, blockSize)
252254

253255
runDistribution(b, instances, blocks, df, ff, start)
@@ -285,13 +287,25 @@ func runDistribution(b *testing.B, instances []testinstance.Instance, blocks []b
285287
b.Logf("send/recv: %d / %d", nst.MessagesSent, nst.MessagesRecvd)
286288
}
287289

288-
func allToAll(b *testing.B, provs []testinstance.Instance, blocks []blocks.Block) {
289-
for _, p := range provs {
290-
if err := p.Blockstore().PutMany(blocks); err != nil {
290+
func starPattern(b *testing.B, instances []testinstance.Instance) {
291+
for _, inst := range instances {
292+
// Connect in a star pattern to first node only (like a bootstrap)
293+
inst.Adapter.ConnectTo(context.Background(), instances[0].Peer)
294+
}
295+
}
296+
297+
func putMany(b *testing.B, p testinstance.Instance, blocks []blocks.Block) {
298+
for _, blk := range blocks {
299+
if err := p.Exchange.HasBlock(blk); err != nil {
291300
b.Fatal(err)
292301
}
293302
}
294303
}
304+
func allToAll(b *testing.B, provs []testinstance.Instance, blocks []blocks.Block) {
305+
for _, p := range provs {
306+
putMany(b, p, blocks)
307+
}
308+
}
295309

296310
// overlap1 gives the first 75 blocks to the first peer, and the last 75 blocks
297311
// to the second peer. This means both peers have the middle 50 blocks
@@ -302,12 +316,8 @@ func overlap1(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
302316
bill := provs[0]
303317
jeff := provs[1]
304318

305-
if err := bill.Blockstore().PutMany(blks[:75]); err != nil {
306-
b.Fatal(err)
307-
}
308-
if err := jeff.Blockstore().PutMany(blks[25:]); err != nil {
309-
b.Fatal(err)
310-
}
319+
putMany(b, bill, blks[:75])
320+
putMany(b, jeff, blks[25:])
311321
}
312322

313323
// overlap2 gives every even numbered block to the first peer, odd numbered
@@ -319,16 +329,16 @@ func overlap2(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
319329
bill := provs[0]
320330
jeff := provs[1]
321331

322-
bill.Blockstore().Put(blks[0])
323-
jeff.Blockstore().Put(blks[0])
332+
bill.Exchange.HasBlock(blks[0])
333+
jeff.Exchange.HasBlock(blks[0])
324334
for i, blk := range blks {
325335
if i%3 == 0 {
326-
bill.Blockstore().Put(blk)
327-
jeff.Blockstore().Put(blk)
336+
bill.Exchange.HasBlock(blk)
337+
jeff.Exchange.HasBlock(blk)
328338
} else if i%2 == 1 {
329-
bill.Blockstore().Put(blk)
339+
bill.Exchange.HasBlock(blk)
330340
} else {
331-
jeff.Blockstore().Put(blk)
341+
jeff.Exchange.HasBlock(blk)
332342
}
333343
}
334344
}
@@ -341,16 +351,16 @@ func overlap3(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
341351
bill := provs[0]
342352
jeff := provs[1]
343353

344-
bill.Blockstore().Put(blks[0])
345-
jeff.Blockstore().Put(blks[0])
354+
bill.Exchange.HasBlock(blks[0])
355+
jeff.Exchange.HasBlock(blks[0])
346356
for i, blk := range blks {
347357
if i%3 == 0 {
348-
bill.Blockstore().Put(blk)
349-
jeff.Blockstore().Put(blk)
358+
bill.Exchange.HasBlock(blk)
359+
jeff.Exchange.HasBlock(blk)
350360
} else if i%2 == 1 {
351-
bill.Blockstore().Put(blk)
361+
bill.Exchange.HasBlock(blk)
352362
} else {
353-
jeff.Blockstore().Put(blk)
363+
jeff.Exchange.HasBlock(blk)
354364
}
355365
}
356366
}
@@ -360,7 +370,18 @@ func overlap3(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
360370
// but we're mostly just testing performance of the sync algorithm
361371
func onePeerPerBlock(b *testing.B, provs []testinstance.Instance, blks []blocks.Block) {
362372
for _, blk := range blks {
363-
provs[rand.Intn(len(provs))].Blockstore().Put(blk)
373+
provs[rand.Intn(len(provs))].Exchange.HasBlock(blk)
374+
}
375+
}
376+
377+
// randomRandom distributes each block randomly -- to random peers a random amount of times
378+
func randomRandom(b *testing.B, provs []testinstance.Instance, blks []blocks.Block) {
379+
for _, blk := range blks {
380+
dups := rand.Intn(len(provs)) + 1
381+
perm := rand.Perm(len(provs))
382+
for i := 0; i < dups; i++ {
383+
provs[perm[i]].Exchange.HasBlock(blk)
384+
}
364385
}
365386
}
366387

0 commit comments

Comments
 (0)