@@ -39,7 +39,7 @@ import (
39
39
// requestBenchmark is an interface for different randomized request generators
40
40
type requestBenchmark interface {
41
41
// init initializes the generator for generating the given number of randomized requests
42
- init (pm * ProtocolManager , count int ) error
42
+ init (h * serverHandler , count int ) error
43
43
// request initiates sending a single request to the given peer
44
44
request (peer * peer , index int ) error
45
45
}
@@ -52,10 +52,10 @@ type benchmarkBlockHeaders struct {
52
52
hashes []common.Hash
53
53
}
54
54
55
- func (b * benchmarkBlockHeaders ) init (pm * ProtocolManager , count int ) error {
55
+ func (b * benchmarkBlockHeaders ) init (h * serverHandler , count int ) error {
56
56
d := int64 (b .amount - 1 ) * int64 (b .skip + 1 )
57
57
b .offset = 0
58
- b .randMax = pm .blockchain .CurrentHeader ().Number .Int64 () + 1 - d
58
+ b .randMax = h .blockchain .CurrentHeader ().Number .Int64 () + 1 - d
59
59
if b .randMax < 0 {
60
60
return fmt .Errorf ("chain is too short" )
61
61
}
@@ -65,7 +65,7 @@ func (b *benchmarkBlockHeaders) init(pm *ProtocolManager, count int) error {
65
65
if b .byHash {
66
66
b .hashes = make ([]common.Hash , count )
67
67
for i := range b .hashes {
68
- b .hashes [i ] = rawdb .ReadCanonicalHash (pm .chainDb , uint64 (b .offset + rand .Int63n (b .randMax )))
68
+ b .hashes [i ] = rawdb .ReadCanonicalHash (h .chainDb , uint64 (b .offset + rand .Int63n (b .randMax )))
69
69
}
70
70
}
71
71
return nil
@@ -85,11 +85,11 @@ type benchmarkBodiesOrReceipts struct {
85
85
hashes []common.Hash
86
86
}
87
87
88
- func (b * benchmarkBodiesOrReceipts ) init (pm * ProtocolManager , count int ) error {
89
- randMax := pm .blockchain .CurrentHeader ().Number .Int64 () + 1
88
+ func (b * benchmarkBodiesOrReceipts ) init (h * serverHandler , count int ) error {
89
+ randMax := h .blockchain .CurrentHeader ().Number .Int64 () + 1
90
90
b .hashes = make ([]common.Hash , count )
91
91
for i := range b .hashes {
92
- b .hashes [i ] = rawdb .ReadCanonicalHash (pm .chainDb , uint64 (rand .Int63n (randMax )))
92
+ b .hashes [i ] = rawdb .ReadCanonicalHash (h .chainDb , uint64 (rand .Int63n (randMax )))
93
93
}
94
94
return nil
95
95
}
@@ -108,8 +108,8 @@ type benchmarkProofsOrCode struct {
108
108
headHash common.Hash
109
109
}
110
110
111
- func (b * benchmarkProofsOrCode ) init (pm * ProtocolManager , count int ) error {
112
- b .headHash = pm .blockchain .CurrentHeader ().Hash ()
111
+ func (b * benchmarkProofsOrCode ) init (h * serverHandler , count int ) error {
112
+ b .headHash = h .blockchain .CurrentHeader ().Hash ()
113
113
return nil
114
114
}
115
115
@@ -130,11 +130,11 @@ type benchmarkHelperTrie struct {
130
130
sectionCount , headNum uint64
131
131
}
132
132
133
- func (b * benchmarkHelperTrie ) init (pm * ProtocolManager , count int ) error {
133
+ func (b * benchmarkHelperTrie ) init (h * serverHandler , count int ) error {
134
134
if b .bloom {
135
- b .sectionCount , b .headNum , _ = pm .server .bloomTrieIndexer .Sections ()
135
+ b .sectionCount , b .headNum , _ = h .server .bloomTrieIndexer .Sections ()
136
136
} else {
137
- b .sectionCount , _ , _ = pm .server .chtIndexer .Sections ()
137
+ b .sectionCount , _ , _ = h .server .chtIndexer .Sections ()
138
138
b .headNum = b .sectionCount * params .CHTFrequency - 1
139
139
}
140
140
if b .sectionCount == 0 {
@@ -170,7 +170,7 @@ type benchmarkTxSend struct {
170
170
txs types.Transactions
171
171
}
172
172
173
- func (b * benchmarkTxSend ) init (pm * ProtocolManager , count int ) error {
173
+ func (b * benchmarkTxSend ) init (h * serverHandler , count int ) error {
174
174
key , _ := crypto .GenerateKey ()
175
175
addr := crypto .PubkeyToAddress (key .PublicKey )
176
176
signer := types .NewEIP155Signer (big .NewInt (18 ))
@@ -196,7 +196,7 @@ func (b *benchmarkTxSend) request(peer *peer, index int) error {
196
196
// benchmarkTxStatus implements requestBenchmark
197
197
type benchmarkTxStatus struct {}
198
198
199
- func (b * benchmarkTxStatus ) init (pm * ProtocolManager , count int ) error {
199
+ func (b * benchmarkTxStatus ) init (h * serverHandler , count int ) error {
200
200
return nil
201
201
}
202
202
@@ -217,7 +217,7 @@ type benchmarkSetup struct {
217
217
218
218
// runBenchmark runs a benchmark cycle for all benchmark types in the specified
219
219
// number of passes
220
- func (pm * ProtocolManager ) runBenchmark (benchmarks []requestBenchmark , passCount int , targetTime time.Duration ) []* benchmarkSetup {
220
+ func (h * serverHandler ) runBenchmark (benchmarks []requestBenchmark , passCount int , targetTime time.Duration ) []* benchmarkSetup {
221
221
setup := make ([]* benchmarkSetup , len (benchmarks ))
222
222
for i , b := range benchmarks {
223
223
setup [i ] = & benchmarkSetup {req : b }
@@ -239,7 +239,7 @@ func (pm *ProtocolManager) runBenchmark(benchmarks []requestBenchmark, passCount
239
239
if next .totalTime > 0 {
240
240
count = int (uint64 (next .totalCount ) * uint64 (targetTime ) / uint64 (next .totalTime ))
241
241
}
242
- if err := pm .measure (next , count ); err != nil {
242
+ if err := h .measure (next , count ); err != nil {
243
243
next .err = err
244
244
}
245
245
}
@@ -275,14 +275,15 @@ func (m *meteredPipe) WriteMsg(msg p2p.Msg) error {
275
275
276
276
// measure runs a benchmark for a single type in a single pass, with the given
277
277
// number of requests
278
- func (pm * ProtocolManager ) measure (setup * benchmarkSetup , count int ) error {
278
+ func (h * serverHandler ) measure (setup * benchmarkSetup , count int ) error {
279
279
clientPipe , serverPipe := p2p .MsgPipe ()
280
280
clientMeteredPipe := & meteredPipe {rw : clientPipe }
281
281
serverMeteredPipe := & meteredPipe {rw : serverPipe }
282
282
var id enode.ID
283
283
rand .Read (id [:])
284
- clientPeer := pm .newPeer (lpv2 , NetworkId , p2p .NewPeer (id , "client" , nil ), clientMeteredPipe )
285
- serverPeer := pm .newPeer (lpv2 , NetworkId , p2p .NewPeer (id , "server" , nil ), serverMeteredPipe )
284
+
285
+ clientPeer := newPeer (lpv2 , NetworkId , false , p2p .NewPeer (id , "client" , nil ), clientMeteredPipe )
286
+ serverPeer := newPeer (lpv2 , NetworkId , false , p2p .NewPeer (id , "server" , nil ), serverMeteredPipe )
286
287
serverPeer .sendQueue = newExecQueue (count )
287
288
serverPeer .announceType = announceTypeNone
288
289
serverPeer .fcCosts = make (requestCostTable )
@@ -291,10 +292,10 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
291
292
serverPeer .fcCosts [code ] = c
292
293
}
293
294
serverPeer .fcParams = flowcontrol.ServerParams {BufLimit : 1 , MinRecharge : 1 }
294
- serverPeer .fcClient = flowcontrol .NewClientNode (pm .server .fcManager , serverPeer .fcParams )
295
+ serverPeer .fcClient = flowcontrol .NewClientNode (h .server .fcManager , serverPeer .fcParams )
295
296
defer serverPeer .fcClient .Disconnect ()
296
297
297
- if err := setup .req .init (pm , count ); err != nil {
298
+ if err := setup .req .init (h , count ); err != nil {
298
299
return err
299
300
}
300
301
@@ -311,7 +312,7 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
311
312
}()
312
313
go func () {
313
314
for i := 0 ; i < count ; i ++ {
314
- if err := pm .handleMsg (serverPeer ); err != nil {
315
+ if err := h .handleMsg (serverPeer ); err != nil {
315
316
errCh <- err
316
317
return
317
318
}
@@ -336,7 +337,7 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
336
337
if err != nil {
337
338
return err
338
339
}
339
- case <- pm . quitSync :
340
+ case <- h . closeCh :
340
341
clientPipe .Close ()
341
342
serverPipe .Close ()
342
343
return fmt .Errorf ("Benchmark cancelled" )
0 commit comments