@@ -9,9 +9,10 @@ import (
9
9
"testing"
10
10
"time"
11
11
12
- tn "github.com/ipfs/go-bitswap/testnet "
12
+ "github.com/ipfs/go-bitswap/testutil "
13
13
14
14
bssession "github.com/ipfs/go-bitswap/session"
15
+ tn "github.com/ipfs/go-bitswap/testnet"
15
16
"github.com/ipfs/go-block-format"
16
17
cid "github.com/ipfs/go-cid"
17
18
blocksutil "github.com/ipfs/go-ipfs-blocksutil"
@@ -102,30 +103,40 @@ const mediumSpeed = 200 * time.Millisecond
102
103
const slowSpeed = 800 * time .Millisecond
103
104
const superSlowSpeed = 4000 * time .Millisecond
104
105
const distribution = 20 * time .Millisecond
106
+ const fastBandwidth = 1250000.0
107
+ const fastBandwidthDeviation = 300000.0
108
+ const mediumBandwidth = 500000.0
109
+ const mediumBandwidthDeviation = 80000.0
110
+ const slowBandwidth = 100000.0
111
+ const slowBandwidthDeviation = 16500.0
112
+ const stdBlockSize = 8000
105
113
106
114
func BenchmarkDupsManyNodesRealWorldNetwork (b * testing.B ) {
107
115
benchmarkLog = nil
108
116
fastNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
109
117
mediumSpeed - fastSpeed , slowSpeed - fastSpeed ,
110
118
0.0 , 0.0 , distribution , nil )
111
119
fastNetworkDelay := delay .Delay (fastSpeed , fastNetworkDelayGenerator )
120
+ fastBandwidthGenerator := tn .VariableRateLimitGenerator (fastBandwidth , fastBandwidthDeviation , nil )
112
121
averageNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
113
122
mediumSpeed - fastSpeed , slowSpeed - fastSpeed ,
114
123
0.3 , 0.3 , distribution , nil )
115
124
averageNetworkDelay := delay .Delay (fastSpeed , averageNetworkDelayGenerator )
125
+ averageBandwidthGenerator := tn .VariableRateLimitGenerator (mediumBandwidth , mediumBandwidthDeviation , nil )
116
126
slowNetworkDelayGenerator := tn .InternetLatencyDelayGenerator (
117
127
mediumSpeed - fastSpeed , superSlowSpeed - fastSpeed ,
118
128
0.3 , 0.3 , distribution , nil )
119
129
slowNetworkDelay := delay .Delay (fastSpeed , slowNetworkDelayGenerator )
130
+ slowBandwidthGenerator := tn .VariableRateLimitGenerator (slowBandwidth , slowBandwidthDeviation , nil )
120
131
121
132
b .Run ("200Nodes-AllToAll-BigBatch-FastNetwork" , func (b * testing.B ) {
122
- subtestDistributeAndFetch (b , 300 , 200 , fastNetworkDelay , allToAll , batchFetchAll )
133
+ subtestDistributeAndFetchRateLimited (b , 300 , 200 , fastNetworkDelay , fastBandwidthGenerator , stdBlockSize , allToAll , batchFetchAll )
123
134
})
124
135
b .Run ("200Nodes-AllToAll-BigBatch-AverageVariableSpeedNetwork" , func (b * testing.B ) {
125
- subtestDistributeAndFetch (b , 300 , 200 , averageNetworkDelay , allToAll , batchFetchAll )
136
+ subtestDistributeAndFetchRateLimited (b , 300 , 200 , averageNetworkDelay , averageBandwidthGenerator , stdBlockSize , allToAll , batchFetchAll )
126
137
})
127
138
b .Run ("200Nodes-AllToAll-BigBatch-SlowVariableSpeedNetwork" , func (b * testing.B ) {
128
- subtestDistributeAndFetch (b , 300 , 200 , slowNetworkDelay , allToAll , batchFetchAll )
139
+ subtestDistributeAndFetchRateLimited (b , 300 , 200 , slowNetworkDelay , slowBandwidthGenerator , stdBlockSize , allToAll , batchFetchAll )
129
140
})
130
141
out , _ := json .MarshalIndent (benchmarkLog , "" , " " )
131
142
ioutil .WriteFile ("tmp/rw-benchmark.json" , out , 0666 )
@@ -134,13 +145,33 @@ func BenchmarkDupsManyNodesRealWorldNetwork(b *testing.B) {
134
145
func subtestDistributeAndFetch (b * testing.B , numnodes , numblks int , d delay.D , df distFunc , ff fetchFunc ) {
135
146
start := time .Now ()
136
147
net := tn .VirtualNetwork (mockrouting .NewServer (), d )
148
+
137
149
sg := NewTestSessionGenerator (net )
138
150
defer sg .Close ()
139
151
140
152
bg := blocksutil .NewBlockGenerator ()
141
153
142
154
instances := sg .Instances (numnodes )
143
155
blocks := bg .Blocks (numblks )
156
+ runDistribution (b , instances , blocks , df , ff , start )
157
+ }
158
+
159
+ func subtestDistributeAndFetchRateLimited (b * testing.B , numnodes , numblks int , d delay.D , rateLimitGenerator tn.RateLimitGenerator , blockSize int64 , df distFunc , ff fetchFunc ) {
160
+ start := time .Now ()
161
+ net := tn .RateLimitedVirtualNetwork (mockrouting .NewServer (), d , rateLimitGenerator )
162
+
163
+ sg := NewTestSessionGenerator (net )
164
+ defer sg .Close ()
165
+
166
+ instances := sg .Instances (numnodes )
167
+ blocks := testutil .GenerateBlocksOfSize (numblks , blockSize )
168
+
169
+ runDistribution (b , instances , blocks , df , ff , start )
170
+ }
171
+
172
+ func runDistribution (b * testing.B , instances []Instance , blocks []blocks.Block , df distFunc , ff fetchFunc , start time.Time ) {
173
+
174
+ numnodes := len (instances )
144
175
145
176
fetcher := instances [numnodes - 1 ]
146
177
0 commit comments