Skip to content

Commit

Permalink
rpc,base: move HeartbeatInterval from const into Config
Browse files Browse the repository at this point in the history
This enables dramatically shortening the runtime of the nodedialer tests from
over 3s to less than 50ms.

Release note: None
  • Loading branch information
ajwerner committed Mar 8, 2019
1 parent 3c72ce9 commit 2d0c3bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions pkg/rpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pkg/rpc/nodedialer/nodedialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2d0c3bf

Please sign in to comment.