Skip to content

Commit

Permalink
[FAB-2207] Make gossip wait time configurable
Browse files Browse the repository at this point in the history
Integrate gossip/gossip/algo/pull with peer/core.yaml, so it's wait
time become configurable.

Change-Id: I1661a959b4b771af9c22cb28e1d43c180e98c807
Signed-off-by: Ray Chen <ray@hyperchain.cn>
  • Loading branch information
oldsharp committed Feb 16, 2017
1 parent 7559dd9 commit 0488bab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
19 changes: 13 additions & 6 deletions gossip/gossip/algo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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)

}
Expand Down Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions gossip/gossip/algo/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
6 changes: 6 additions & 0 deletions peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0488bab

Please sign in to comment.