@@ -25,6 +25,8 @@ import (
25
25
mockrouting "github.com/ipfs/go-ipfs-routing/mock"
26
26
)
27
27
28
+ type topologyFunc func (b * testing.B , instances []testinstance.Instance )
29
+
28
30
type fetchFunc func (b * testing.B , bs * bitswap.Bitswap , ks []cid.Cid )
29
31
30
32
type distFunc func (b * testing.B , provs []testinstance.Instance , blocks []blocks.Block )
@@ -171,14 +173,14 @@ func BenchmarkDupsManyNodesRealWorldNetworkWithRealDHT(b *testing.B) {
171
173
slowNetworkDelay := delay .Delay (fastSpeed , slowNetworkDelayGenerator )
172
174
slowBandwidthGenerator := tn .VariableRateLimitGenerator (slowBandwidth , slowBandwidthDeviation , nil )
173
175
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 )
176
178
})
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 )
179
181
})
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 )
182
184
})
183
185
out , _ := json .MarshalIndent (benchmarkLog , "" , " " )
184
186
ioutil .WriteFile ("tmp/rw-benchmark.json" , out , 0666 )
@@ -189,7 +191,7 @@ func subtestDistributeAndFetch(b *testing.B, numnodes, numblks int, d delay.D, d
189
191
start := time .Now ()
190
192
net := tn .VirtualNetwork (mockrouting .NewServer (), d )
191
193
192
- ig := testinstance .NewTestInstanceGenerator (net )
194
+ ig := testinstance .NewTestInstanceGenerator (net , bitswap . ProvideEnabled ( false ) )
193
195
defer ig .Close ()
194
196
195
197
bg := blocksutil .NewBlockGenerator ()
@@ -206,7 +208,7 @@ func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d
206
208
start := time .Now ()
207
209
net := tn .RateLimitedVirtualNetwork (mockrouting .NewServer (), d , rateLimitGenerator )
208
210
209
- ig := testinstance .NewTestInstanceGenerator (net )
211
+ ig := testinstance .NewTestInstanceGenerator (net , bitswap . ProvideEnabled ( false ) )
210
212
defer ig .Close ()
211
213
212
214
instances := ig .Instances (numnodes )
@@ -216,7 +218,7 @@ func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d
216
218
}
217
219
}
218
220
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 ) {
220
222
start := time .Now ()
221
223
ctx := context .Background ()
222
224
mn := mocknet .New (ctx )
@@ -236,8 +238,6 @@ func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d
236
238
}
237
239
mn .LinkAll ()
238
240
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 )
241
241
// rate limit and delate connections
242
242
for j := i + 1 ; j < len (instances ); j ++ {
243
243
oinst := instances [j ]
@@ -248,6 +248,8 @@ func subtestDistributeAndFetchWithRealDHT(b *testing.B, numnodes, numblks int, d
248
248
}
249
249
}
250
250
251
+ tf (b , instances )
252
+
251
253
blocks := testutil .GenerateBlocksOfSize (numblks , blockSize )
252
254
253
255
runDistribution (b , instances , blocks , df , ff , start )
@@ -285,13 +287,25 @@ func runDistribution(b *testing.B, instances []testinstance.Instance, blocks []b
285
287
b .Logf ("send/recv: %d / %d" , nst .MessagesSent , nst .MessagesRecvd )
286
288
}
287
289
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 {
291
300
b .Fatal (err )
292
301
}
293
302
}
294
303
}
304
+ func allToAll (b * testing.B , provs []testinstance.Instance , blocks []blocks.Block ) {
305
+ for _ , p := range provs {
306
+ putMany (b , p , blocks )
307
+ }
308
+ }
295
309
296
310
// overlap1 gives the first 75 blocks to the first peer, and the last 75 blocks
297
311
// 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)
302
316
bill := provs [0 ]
303
317
jeff := provs [1 ]
304
318
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 :])
311
321
}
312
322
313
323
// 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)
319
329
bill := provs [0 ]
320
330
jeff := provs [1 ]
321
331
322
- bill .Blockstore (). Put (blks [0 ])
323
- jeff .Blockstore (). Put (blks [0 ])
332
+ bill .Exchange . HasBlock (blks [0 ])
333
+ jeff .Exchange . HasBlock (blks [0 ])
324
334
for i , blk := range blks {
325
335
if i % 3 == 0 {
326
- bill .Blockstore (). Put (blk )
327
- jeff .Blockstore (). Put (blk )
336
+ bill .Exchange . HasBlock (blk )
337
+ jeff .Exchange . HasBlock (blk )
328
338
} else if i % 2 == 1 {
329
- bill .Blockstore (). Put (blk )
339
+ bill .Exchange . HasBlock (blk )
330
340
} else {
331
- jeff .Blockstore (). Put (blk )
341
+ jeff .Exchange . HasBlock (blk )
332
342
}
333
343
}
334
344
}
@@ -341,16 +351,16 @@ func overlap3(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
341
351
bill := provs [0 ]
342
352
jeff := provs [1 ]
343
353
344
- bill .Blockstore (). Put (blks [0 ])
345
- jeff .Blockstore (). Put (blks [0 ])
354
+ bill .Exchange . HasBlock (blks [0 ])
355
+ jeff .Exchange . HasBlock (blks [0 ])
346
356
for i , blk := range blks {
347
357
if i % 3 == 0 {
348
- bill .Blockstore (). Put (blk )
349
- jeff .Blockstore (). Put (blk )
358
+ bill .Exchange . HasBlock (blk )
359
+ jeff .Exchange . HasBlock (blk )
350
360
} else if i % 2 == 1 {
351
- bill .Blockstore (). Put (blk )
361
+ bill .Exchange . HasBlock (blk )
352
362
} else {
353
- jeff .Blockstore (). Put (blk )
363
+ jeff .Exchange . HasBlock (blk )
354
364
}
355
365
}
356
366
}
@@ -360,7 +370,18 @@ func overlap3(b *testing.B, provs []testinstance.Instance, blks []blocks.Block)
360
370
// but we're mostly just testing performance of the sync algorithm
361
371
func onePeerPerBlock (b * testing.B , provs []testinstance.Instance , blks []blocks.Block ) {
362
372
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
+ }
364
385
}
365
386
}
366
387
0 commit comments