Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvserver: cache the storeClockTimestamp every tick #142037

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

iskettaneh
Copy link
Contributor

@iskettaneh iskettaneh commented Feb 26, 2025

Instead of calculating the time now() multiple times during the tick. This commit caches timestamp during the tick(), and then it gets reused instead of redoing the work again.

Preliminary testing showed that this reduces the clock mutex contention by 50%.

Fixes: #142049
Release note: None

Copy link

blathers-crl bot commented Feb 26, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@miraradeva miraradeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani)


-- commits line 4 at r1:
nit: Maybe r.store.Clock().NowAsClockTimestamp() to be more precise here (instead of time now()).

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @iskettaneh)


pkg/kv/kvserver/replica_raft.go line 1474 at r1 (raw file):

	storeClockTimestamp := r.store.Clock().NowAsClockTimestamp()

	// Update lastTickTimestamp so that we don't have to redo the work multiple

nit: consider expanding this comment to say something about mutex contention we avoid. Maybe even specifically giving the example of SupportExpired will help.

Instead of calculating the r.store.Clock().NowAsClockTimestamp()
multiple times during the tick, this commit caches timestamp
during the tick(), and then it gets reused instead of redoing
the work again.

Preliminary testing showed  that this reduces the clock mutex
contention by 50%.

Fixes: cockroachdb#142049

Release note: None
@iskettaneh
Copy link
Contributor Author

TFTR!

bors r+

@craig craig bot merged commit ed91342 into cockroachdb:master Feb 26, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kvserver: cache the r.store.Clock().NowAsClockTimestamp() every tick
4 participants