From 0488bab26530b1fea690a7ea4bf7b306a9c8e7d5 Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Mon, 13 Feb 2017 18:29:05 +0800 Subject: [PATCH] [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 --- gossip/gossip/algo/pull.go | 19 +++++++++++++------ gossip/gossip/algo/pull_test.go | 6 +++--- peer/core.yaml | 6 ++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gossip/gossip/algo/pull.go b/gossip/gossip/algo/pull.go index 1d372f21a70..6ccca81ae49 100644 --- a/gossip/gossip/algo/pull.go +++ b/gossip/gossip/algo/pull.go @@ -23,6 +23,7 @@ import ( "time" "github.com/hyperledger/fabric/gossip/util" + "github.com/spf13/viper" ) /* PullEngine is an object that performs pull-based gossip, and maintains an internal state of items @@ -47,23 +48,25 @@ func init() { rand.Seed(42) } -var digestWaitTime = time.Duration(1) * time.Second -var requestWaitTime = time.Duration(1) * time.Second -var responseWaitTime = time.Duration(2) * time.Second +const ( + defDigestWaitTime = time.Duration(1) * time.Second + defRequestWaitTime = time.Duration(1) * time.Second + defResponseWaitTime = time.Duration(2) * time.Second +) // SetDigestWaitTime sets the digest wait time func SetDigestWaitTime(time time.Duration) { - digestWaitTime = time + viper.Set("peer.gossip.digestWaitTime", time) } // SetRequestWaitTime sets the request wait time func SetRequestWaitTime(time time.Duration) { - requestWaitTime = time + viper.Set("peer.gossip.requestWaitTime", time) } // SetResponseWaitTime sets the response wait time func SetResponseWaitTime(time time.Duration) { - responseWaitTime = time + viper.Set("peer.gossip.responseWaitTime", time) } // PullAdapter is needed by the PullEngine in order to @@ -179,6 +182,7 @@ func (engine *PullEngine) initiatePull() { engine.Hello(peer, nonce) } + digestWaitTime := util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime) time.AfterFunc(digestWaitTime, func() { engine.processIncomingDigests() }) @@ -207,6 +211,7 @@ func (engine *PullEngine) processIncomingDigests() { engine.SendReq(dest, seqsToReq, engine.peers2nonces[dest]) } + responseWaitTime := util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime) time.AfterFunc(responseWaitTime, engine.endPull) } @@ -262,6 +267,8 @@ func (engine *PullEngine) Remove(seqs ...string) { // OnHello notifies the engine a hello has arrived func (engine *PullEngine) OnHello(nonce uint64, context interface{}) { engine.incomingNONCES.Add(nonce) + + requestWaitTime := util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime) time.AfterFunc(requestWaitTime, func() { engine.incomingNONCES.Remove(nonce) }) diff --git a/gossip/gossip/algo/pull_test.go b/gossip/gossip/algo/pull_test.go index ed8499d0995..9c1b59979e4 100644 --- a/gossip/gossip/algo/pull_test.go +++ b/gossip/gossip/algo/pull_test.go @@ -29,9 +29,9 @@ import ( ) func init() { - requestWaitTime = time.Duration(200) * time.Millisecond - digestWaitTime = time.Duration(100) * time.Millisecond - responseWaitTime = time.Duration(200) * time.Millisecond + SetDigestWaitTime(time.Duration(100) * time.Millisecond) + SetRequestWaitTime(time.Duration(200) * time.Millisecond) + SetResponseWaitTime(time.Duration(200) * time.Millisecond) } type messageHook func(interface{}) diff --git a/peer/core.yaml b/peer/core.yaml index fabea5a05bb..dc451d6d28e 100644 --- a/peer/core.yaml +++ b/peer/core.yaml @@ -108,6 +108,12 @@ peer: recvBuffSize: 20 # Buffer size of sending messages sendBuffSize: 20 + # Time to wait before pull engine processes incoming digests (unit: second) + digestWaitTime: 1s + # Time to wait before pull engine removes incoming nonce (unit: second) + requestWaitTime: 1s + # Time to wait before pull engine ends pull (unit: second) + responseWaitTime: 2s # This is an endpoint that is published to peers outside of the organization. # If this isn't set, the peer will not be known to other organizations.