Skip to content

Commit

Permalink
[FAB-7034] Configure orderer keepalive params
Browse files Browse the repository at this point in the history
Currently the gRPC server keepalive parameters
are hard-coded to the defaults set in the
core/comm package.  This change makes the
following settings configurable:

- minimum permitted interval for client
 pings on the peer endpoint

- keepalive interval and timeout for
 server to client pings

Change-Id: I5f4c4b330f7d31483b63e8fd293039fd1bb352b9
Signed-off-by: Gari Singh <[email protected]>
  • Loading branch information
mastersingh24 committed Nov 22, 2017
1 parent 9359c72 commit d972b54
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
10 changes: 9 additions & 1 deletion orderer/common/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type General struct {
ListenAddress string
ListenPort uint16
TLS TLS
Keepalive Keepalive
GenesisMethod string
GenesisProfile string
SystemChannel string
Expand All @@ -86,7 +87,14 @@ type General struct {
BCCSP *bccsp.FactoryOpts
}

// TLS contains config for TLS connections.
// Keepalive contains configuration for gRPC servers
type Keepalive struct {
ServerMinInterval time.Duration
ServerInterval time.Duration
ServerTimeout time.Duration
}

// TLS contains configuration for TLS connections.
type TLS struct {
Enabled bool
PrivateKey string
Expand Down
12 changes: 11 additions & 1 deletion orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
_ "net/http/pprof" // This is essentially the main package for the orderer
"os"
"time"

"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/crypto"
Expand Down Expand Up @@ -172,7 +173,16 @@ func initializeServerConfig(conf *config.TopLevel) comm.ServerConfig {
secureOpts.ClientRootCAs = clientRootCAs
logger.Infof("Starting orderer with %s enabled", msg)
}
return comm.ServerConfig{SecOpts: secureOpts}
kaOpts := comm.DefaultKeepaliveOptions()
// keepalive settings
// ServerMinInterval must be greater than 0
if conf.General.Keepalive.ServerMinInterval > time.Duration(0) {
kaOpts.ServerMinInterval = conf.General.Keepalive.ServerMinInterval
}
kaOpts.ServerInterval = conf.General.Keepalive.ServerInterval
kaOpts.ServerTimeout = conf.General.Keepalive.ServerTimeout

return comm.ServerConfig{SecOpts: secureOpts, KaOpts: kaOpts}
}

func initializeBootstrapChannel(conf *config.TopLevel, lf ledger.Factory) {
Expand Down
38 changes: 26 additions & 12 deletions orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,33 @@ func TestInitializeProfilingService(t *testing.T) {
}

func TestInitializeServerConfig(t *testing.T) {
initializeServerConfig(
&config.TopLevel{
General: config.General{
TLS: config.TLS{
Enabled: true,
ClientAuthEnabled: true,
Certificate: "main.go",
PrivateKey: "main.go",
RootCAs: []string{"main.go"},
ClientRootCAs: []string{"main.go"},
},
conf := &config.TopLevel{
General: config.General{
TLS: config.TLS{
Enabled: true,
ClientAuthEnabled: true,
Certificate: "main.go",
PrivateKey: "main.go",
RootCAs: []string{"main.go"},
ClientRootCAs: []string{"main.go"},
},
})
},
}
sc := initializeServerConfig(conf)
defaultOpts := comm.DefaultKeepaliveOptions()
assert.Equal(t, defaultOpts.ServerMinInterval, sc.KaOpts.ServerMinInterval)
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerInterval)
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerTimeout)
testDuration := 10 * time.Second
conf.General.Keepalive = config.Keepalive{
ServerMinInterval: testDuration,
ServerInterval: testDuration,
ServerTimeout: testDuration,
}
sc = initializeServerConfig(conf)
assert.Equal(t, testDuration, sc.KaOpts.ServerMinInterval)
assert.Equal(t, testDuration, sc.KaOpts.ServerInterval)
assert.Equal(t, testDuration, sc.KaOpts.ServerTimeout)

goodFile := "main.go"
badFile := "does_not_exist"
Expand Down
12 changes: 12 additions & 0 deletions sampleconfig/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ General:
ClientAuthEnabled: false
ClientRootCAs:

# Keepalive settings for the GRPC server.
Keepalive:
# ServerMinInterval is the minimum permitted time between client pings.
# If clients send pings more frequently, the server will
# disconnect them.
ServerMinInterval: 60s
# ServerInterval is the time between pings to clients.
ServerInterval: 7200s
# ServerTimeout is the duration the server waits for a response from
# a client before closing the connection.
ServerTimeout: 20s

# Log Level: The level at which to log. This accepts logging specifications
# per: fabric/docs/Setup/logging-control.md
LogLevel: info
Expand Down

0 comments on commit d972b54

Please sign in to comment.