Skip to content

Commit 0488bab

Browse files
committed
[FAB-2207] Make gossip wait time configurable
Integrate gossip/gossip/algo/pull with peer/core.yaml, so it's wait time become configurable. Change-Id: I1661a959b4b771af9c22cb28e1d43c180e98c807 Signed-off-by: Ray Chen <[email protected]>
1 parent 7559dd9 commit 0488bab

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

gossip/gossip/algo/pull.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/hyperledger/fabric/gossip/util"
26+
"github.com/spf13/viper"
2627
)
2728

2829
/* PullEngine is an object that performs pull-based gossip, and maintains an internal state of items
@@ -47,23 +48,25 @@ func init() {
4748
rand.Seed(42)
4849
}
4950

50-
var digestWaitTime = time.Duration(1) * time.Second
51-
var requestWaitTime = time.Duration(1) * time.Second
52-
var responseWaitTime = time.Duration(2) * time.Second
51+
const (
52+
defDigestWaitTime = time.Duration(1) * time.Second
53+
defRequestWaitTime = time.Duration(1) * time.Second
54+
defResponseWaitTime = time.Duration(2) * time.Second
55+
)
5356

5457
// SetDigestWaitTime sets the digest wait time
5558
func SetDigestWaitTime(time time.Duration) {
56-
digestWaitTime = time
59+
viper.Set("peer.gossip.digestWaitTime", time)
5760
}
5861

5962
// SetRequestWaitTime sets the request wait time
6063
func SetRequestWaitTime(time time.Duration) {
61-
requestWaitTime = time
64+
viper.Set("peer.gossip.requestWaitTime", time)
6265
}
6366

6467
// SetResponseWaitTime sets the response wait time
6568
func SetResponseWaitTime(time time.Duration) {
66-
responseWaitTime = time
69+
viper.Set("peer.gossip.responseWaitTime", time)
6770
}
6871

6972
// PullAdapter is needed by the PullEngine in order to
@@ -179,6 +182,7 @@ func (engine *PullEngine) initiatePull() {
179182
engine.Hello(peer, nonce)
180183
}
181184

185+
digestWaitTime := util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime)
182186
time.AfterFunc(digestWaitTime, func() {
183187
engine.processIncomingDigests()
184188
})
@@ -207,6 +211,7 @@ func (engine *PullEngine) processIncomingDigests() {
207211
engine.SendReq(dest, seqsToReq, engine.peers2nonces[dest])
208212
}
209213

214+
responseWaitTime := util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime)
210215
time.AfterFunc(responseWaitTime, engine.endPull)
211216

212217
}
@@ -262,6 +267,8 @@ func (engine *PullEngine) Remove(seqs ...string) {
262267
// OnHello notifies the engine a hello has arrived
263268
func (engine *PullEngine) OnHello(nonce uint64, context interface{}) {
264269
engine.incomingNONCES.Add(nonce)
270+
271+
requestWaitTime := util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime)
265272
time.AfterFunc(requestWaitTime, func() {
266273
engine.incomingNONCES.Remove(nonce)
267274
})

gossip/gossip/algo/pull_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
)
3030

3131
func init() {
32-
requestWaitTime = time.Duration(200) * time.Millisecond
33-
digestWaitTime = time.Duration(100) * time.Millisecond
34-
responseWaitTime = time.Duration(200) * time.Millisecond
32+
SetDigestWaitTime(time.Duration(100) * time.Millisecond)
33+
SetRequestWaitTime(time.Duration(200) * time.Millisecond)
34+
SetResponseWaitTime(time.Duration(200) * time.Millisecond)
3535
}
3636

3737
type messageHook func(interface{})

peer/core.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ peer:
108108
recvBuffSize: 20
109109
# Buffer size of sending messages
110110
sendBuffSize: 20
111+
# Time to wait before pull engine processes incoming digests (unit: second)
112+
digestWaitTime: 1s
113+
# Time to wait before pull engine removes incoming nonce (unit: second)
114+
requestWaitTime: 1s
115+
# Time to wait before pull engine ends pull (unit: second)
116+
responseWaitTime: 2s
111117

112118
# This is an endpoint that is published to peers outside of the organization.
113119
# If this isn't set, the peer will not be known to other organizations.

0 commit comments

Comments
 (0)