@@ -157,21 +157,27 @@ func BenchmarkDupsManyNodesRealWorldNetwork(b *testing.B) {
157
157
158
158
func BenchmarkDupsManyNodesRealWorldNetworkWithRealDHT (b * testing.B ) {
159
159
benchmarkLog = nil
160
+ benchmarkSeed , err := strconv .ParseInt (os .Getenv ("BENCHMARK_SEED" ), 10 , 64 )
161
+ var randomGen * rand.Rand = nil
162
+ if err == nil {
163
+ randomGen = rand .New (rand .NewSource (benchmarkSeed ))
164
+ }
165
+
160
166
fastNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
161
167
mediumSpeed - fastSpeed , slowSpeed - fastSpeed ,
162
- 0.0 , 0.0 , distribution , nil )
168
+ 0.0 , 0.0 , distribution , randomGen )
163
169
fastNetworkDelay := delay .Delay (fastSpeed , fastNetworkDelayGenerator )
164
- fastBandwidthGenerator := tn .VariableRateLimitGenerator (fastBandwidth , fastBandwidthDeviation , nil )
170
+ fastBandwidthGenerator := tn .VariableRateLimitGenerator (fastBandwidth , fastBandwidthDeviation , randomGen )
165
171
averageNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
166
172
mediumSpeed - fastSpeed , slowSpeed - fastSpeed ,
167
- 0.3 , 0.3 , distribution , nil )
173
+ 0.3 , 0.3 , distribution , randomGen )
168
174
averageNetworkDelay := delay .Delay (fastSpeed , averageNetworkDelayGenerator )
169
- averageBandwidthGenerator := tn .VariableRateLimitGenerator (mediumBandwidth , mediumBandwidthDeviation , nil )
175
+ averageBandwidthGenerator := tn .VariableRateLimitGenerator (mediumBandwidth , mediumBandwidthDeviation , randomGen )
170
176
slowNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
171
177
mediumSpeed - fastSpeed , superSlowSpeed - fastSpeed ,
172
- 0.3 , 0.3 , distribution , nil )
178
+ 0.3 , 0.3 , distribution , randomGen )
173
179
slowNetworkDelay := delay .Delay (fastSpeed , slowNetworkDelayGenerator )
174
- slowBandwidthGenerator := tn .VariableRateLimitGenerator (slowBandwidth , slowBandwidthDeviation , nil )
180
+ slowBandwidthGenerator := tn .VariableRateLimitGenerator (slowBandwidth , slowBandwidthDeviation , randomGen )
175
181
176
182
b .Run ("10Nodes-RandomRandom-BigBatch-FastNetwork" , func (b * testing.B ) {
177
183
subtestDistributeAndFetchWithRealDHT (b , 20 , 10 , fastNetworkDelay , fastBandwidthGenerator , stdBlockSize , starPattern , randomRandom , batchFetchAll )
@@ -219,40 +225,42 @@ func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d
219
225
}
220
226
221
227
func subtestDistributeAndFetchWithRealDHT (b * testing.B , numnodes , numblks int , d delay.D , rateLimitGenerator tn.RateLimitGenerator , blockSize int64 , tf topologyFunc , df distFunc , ff fetchFunc ) {
222
- start := time .Now ()
223
- ctx := context .Background ()
224
- mn := mocknet .New (ctx )
225
- routing := tn .NewDHTServer ()
226
- net , err := tn .StreamNet (ctx , mn , routing )
227
- if err != nil {
228
- b .Fatal ("Unable to initialize mocknet" )
229
- }
228
+ for i := 0 ; i < b .N ; i ++ {
229
+ start := time .Now ()
230
+ ctx := context .Background ()
231
+ mn := mocknet .New (ctx )
232
+ routing := tn .NewDHTServer ()
233
+ net , err := tn .StreamNet (ctx , mn , routing )
234
+ if err != nil {
235
+ b .Fatal ("Unable to initialize mocknet" )
236
+ }
230
237
231
- ig := testinstance .NewTestInstanceGenerator (net )
232
- defer ig .Close ()
238
+ ig := testinstance .NewTestInstanceGenerator (net )
239
+ defer ig .Close ()
233
240
234
- var instances []testinstance.Instance
235
- for j := 0 ; j < numnodes ; j ++ {
236
- inst := ig .Next ()
237
- instances = append (instances , inst )
238
- }
239
- mn .LinkAll ()
240
- for i , inst := range instances {
241
- // rate limit and delate connections
242
- for j := i + 1 ; j < len (instances ); j ++ {
243
- oinst := instances [j ]
244
- links := mn .LinksBetweenPeers (inst .Peer , oinst .Peer )
245
- for _ , link := range links {
246
- link .SetOptions (mocknet.LinkOptions {Latency : d .NextWaitTime (), Bandwidth : rateLimitGenerator .NextRateLimit ()})
241
+ var instances []testinstance.Instance
242
+ for j := 0 ; j < numnodes ; j ++ {
243
+ inst := ig .Next ()
244
+ instances = append (instances , inst )
245
+ }
246
+ mn .LinkAll ()
247
+ for i , inst := range instances {
248
+ // rate limit and delate connections
249
+ for j := i + 1 ; j < len (instances ); j ++ {
250
+ oinst := instances [j ]
251
+ links := mn .LinksBetweenPeers (inst .Peer , oinst .Peer )
252
+ for _ , link := range links {
253
+ link .SetOptions (mocknet.LinkOptions {Latency : d .NextWaitTime (), Bandwidth : rateLimitGenerator .NextRateLimit ()})
254
+ }
247
255
}
248
256
}
249
- }
250
257
251
- tf (b , instances )
258
+ tf (b , instances )
252
259
253
- blocks := testutil .GenerateBlocksOfSize (numblks , blockSize )
260
+ blocks := testutil .GenerateBlocksOfSize (numblks , blockSize )
254
261
255
- runDistribution (b , instances , blocks , df , ff , start )
262
+ runDistribution (b , instances , blocks , df , ff , start )
263
+ }
256
264
}
257
265
258
266
func runDistribution (b * testing.B , instances []testinstance.Instance , blocks []blocks.Block , df distFunc , ff fetchFunc , start time.Time ) {
0 commit comments