From 2d0c3bf53cbd899f6e88e771433f16d932d7acf0 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Thu, 7 Mar 2019 16:58:20 -0500 Subject: [PATCH] rpc,base: move HeartbeatInterval from const into Config This enables dramatically shortening the runtime of the nodedialer tests from over 3s to less than 50ms. Release note: None --- pkg/base/config.go | 10 ++++++++++ pkg/rpc/context.go | 7 +++---- pkg/rpc/nodedialer/nodedialer_test.go | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/base/config.go b/pkg/base/config.go index fedf799bdf6c..b937d2b867bc 100644 --- a/pkg/base/config.go +++ b/pkg/base/config.go @@ -61,6 +61,10 @@ const ( // leader lease active duration should be of the raft election timeout. defaultRangeLeaseRaftElectionTimeoutMultiplier = 3 + // defaultHeartbeatInterval is the default value of HeartbeatInterval used + // by the rpc context. + defaultHeartbeatInterval = 3 * time.Second + // rangeLeaseRenewalFraction specifies what fraction the range lease // renewal duration should be of the range lease active time. For example, // with a value of 0.2 and a lease duration of 10 seconds, leases would be @@ -178,6 +182,11 @@ type Config struct { // it is set to the arbitrary length of six times the Metrics sample interval. // See the comment in server.Config for more details. HistogramWindowInterval time.Duration + + // HeartbeatInterval controls how often a Ping request is sent on peer + // connections to determine connection health and update the local view + // of remote clocks. + HeartbeatInterval time.Duration } func wrapError(err error) error { @@ -200,6 +209,7 @@ func (cfg *Config) InitDefaults() { cfg.HTTPAddr = defaultHTTPAddr cfg.SSLCertsDir = DefaultCertsDirectory cfg.certificateManager = lazyCertificateManager{} + cfg.HeartbeatInterval = defaultHeartbeatInterval } // HTTPRequestScheme returns "http" or "https" based on the value of Insecure. diff --git a/pkg/rpc/context.go b/pkg/rpc/context.go index 82d20f866f33..4e06bb8d7efe 100644 --- a/pkg/rpc/context.go +++ b/pkg/rpc/context.go @@ -59,7 +59,6 @@ func init() { } const ( - defaultHeartbeatInterval = 3 * time.Second // The coefficient by which the maximum offset is multiplied to determine the // maximum acceptable measurement latency. maximumPingDurationMult = 2 @@ -404,10 +403,10 @@ func NewContext( var cancel context.CancelFunc ctx.masterCtx, cancel = context.WithCancel(ambient.AnnotateCtx(context.Background())) ctx.Stopper = stopper + ctx.heartbeatInterval = baseCtx.HeartbeatInterval ctx.RemoteClocks = newRemoteClockMonitor( - ctx.LocalClock, 10*defaultHeartbeatInterval, baseCtx.HistogramWindowInterval) - ctx.heartbeatInterval = defaultHeartbeatInterval - ctx.heartbeatTimeout = 2 * defaultHeartbeatInterval + ctx.LocalClock, 10*ctx.heartbeatInterval, baseCtx.HistogramWindowInterval) + ctx.heartbeatTimeout = 2 * ctx.heartbeatInterval stopper.RunWorker(ctx.masterCtx, func(context.Context) { <-stopper.ShouldQuiesce() diff --git a/pkg/rpc/nodedialer/nodedialer_test.go b/pkg/rpc/nodedialer/nodedialer_test.go index a8a17a6579c6..c6df9dbff7ca 100644 --- a/pkg/rpc/nodedialer/nodedialer_test.go +++ b/pkg/rpc/nodedialer/nodedialer_test.go @@ -228,6 +228,7 @@ func newTestServer( func newTestContext(clock *hlc.Clock, stopper *stop.Stopper) *rpc.Context { cfg := testutils.NewNodeTestBaseContext() cfg.Insecure = true + cfg.HeartbeatInterval = 10 * time.Millisecond return rpc.NewContext( log.AmbientContext{Tracer: tracing.NewTracer()}, cfg,