Skip to content

Commit 32723e5

Browse files
committed
gossip: use crtime.Mono
crtime.NowMono is a little more efficient. I haven't seen this on any profiles but noted it when reviewing some code recently. We also remove an extra clock reading that wasn't needed. Epic: none Release note: None
1 parent 31baea9 commit 32723e5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

pkg/gossip/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ go_library(
3838
"//pkg/util/syncutil",
3939
"//pkg/util/timeutil",
4040
"//pkg/util/uuid",
41+
"@com_github_cockroachdb_crlib//crtime",
4142
"@com_github_cockroachdb_errors//:errors",
4243
"@com_github_cockroachdb_logtags//:logtags",
4344
"@com_github_cockroachdb_redact//:redact",

pkg/gossip/gossip.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
6767
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
6868
"github.com/cockroachdb/cockroach/pkg/util/uuid"
69+
"github.com/cockroachdb/crlib/crtime"
6970
"github.com/cockroachdb/errors"
7071
"github.com/cockroachdb/logtags"
7172
"github.com/cockroachdb/redact"
@@ -1619,7 +1620,7 @@ func (g *Gossip) TestingAddInfoProtoAndWaitForAllCallbacks(
16191620
method: func(_ string, _ roachpb.Value) {
16201621
wg.Done()
16211622
},
1622-
schedulingTime: timeutil.Now(),
1623+
schedulingTime: crtime.NowMono(),
16231624
})
16241625
cb.cw.mu.Unlock()
16251626
}

pkg/gossip/infostore.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/cockroachdb/cockroach/pkg/util/stop"
2323
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
2424
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
25+
"github.com/cockroachdb/crlib/crtime"
2526
"github.com/cockroachdb/errors"
2627
"github.com/cockroachdb/redact"
2728
)
@@ -77,7 +78,7 @@ type callback struct {
7778
// a callback.
7879
type callbackWorkItem struct {
7980
// schedulingTime is the time when the callback was scheduled.
80-
schedulingTime time.Time
81+
schedulingTime crtime.Mono
8182
method Callback
8283
key string
8384
content roachpb.Value
@@ -266,17 +267,17 @@ func (is *infoStore) launchCallbackWorker(ambient log.AmbientContext, cw *callba
266267

267268
// Execute all the callbacks in the queue, making sure to update the
268269
// metrics accordingly.
270+
afterQueue := crtime.NowMono()
269271
for _, work := range wq {
270-
afterQueue := timeutil.Now()
271-
queueDur := afterQueue.Sub(work.schedulingTime)
272+
queueDur := work.schedulingTime.Sub(afterQueue)
272273
is.metrics.CallbacksPending.Dec(1)
273274
if queueDur >= minCallbackDurationToRecord {
274275
is.metrics.CallbacksPendingDuration.RecordValue(queueDur.Nanoseconds())
275276
}
276277

277278
work.method(work.key, work.content)
278279

279-
afterProcess := timeutil.Now()
280+
afterProcess := crtime.NowMono()
280281
processDur := afterProcess.Sub(afterQueue)
281282
is.metrics.CallbacksProcessed.Inc(1)
282283
if processDur > minCallbackDurationToRecord {
@@ -469,7 +470,7 @@ func (is *infoStore) runCallbacks(key string, content roachpb.Value, callbacks .
469470
}
470471

471472
// Add the callbacks to the callback work list.
472-
beforeQueue := timeutil.Now()
473+
beforeQueue := crtime.NowMono()
473474
for _, cb := range callbacks {
474475
cb.cw.mu.Lock()
475476
is.metrics.CallbacksPending.Inc(1)

0 commit comments

Comments
 (0)