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

storage: Disable timed mutex by default #13388

Merged
merged 2 commits into from
Feb 3, 2017

Conversation

bdarnell
Copy link
Contributor

@bdarnell bdarnell commented Feb 2, 2017

These messages currently trigger very often and scare users because
they look like exceptions or crashes. We should only have them enabled
on our test clusters where we are watching for them.


This change is Reviewable

@a-robinson
Copy link
Contributor

:lgtm:


Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


pkg/storage/timedmutex.go, line 97 at r1 (raw file):

	tm.mu.Lock()
	atomic.StoreInt32(&tm.isLocked, 1)
	tm.lockedAt = timeutil.Now()

Should we avoid doing this if cb is nil? I'm not sure how expensive getting the current time is (although I probably should know it...)


Comments from Reviewable

@a-robinson
Copy link
Contributor

Reviewed 1 of 1 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


Comments from Reviewable

@bdarnell
Copy link
Contributor Author

bdarnell commented Feb 2, 2017

Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


pkg/storage/timedmutex.go, line 97 at r1 (raw file):

Previously, a-robinson (Alex Robinson) wrote…

Should we avoid doing this if cb is nil? I'm not sure how expensive getting the current time is (although I probably should know it...)

Good idea; I added a second commit.

Getting the current time is a system call (I saw tons of these when running cockroach under strace last week; this is probably where they were coming from). System calls are 100ns (4x more expensive than a mutex lock/unlock pair) according to https://gist.github.com/nelsnelson/3955759


Comments from Reviewable

@petermattis
Copy link
Collaborator

Getting the current time is a system call.

Eh? I'm pretty sure time.Now() does not involve a system call on Darwin or Linux but a call to the CPU timestamp counter + invocation of code provided by the kernel in a page shared with the user process. On Linux, this involves __vdso_gettimeofday.

@tamird
Copy link
Contributor

tamird commented Feb 2, 2017

Reviewed 1 of 1 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@bdarnell
Copy link
Contributor Author

bdarnell commented Feb 3, 2017

Eh? I'm pretty sure time.Now() does not involve a system call on Darwin or Linux but a call to the CPU timestamp counter + invocation of code provided by the kernel in a page shared with the user process. On Linux, this involves __vdso_gettimeofday.

Ah, interesting. I called it a system call because it showed up in strace, but I guess that's not true.

These messages currently trigger very often and scare users because
they look like exceptions or crashes. We should only have them enabled
on our test clusters where we are watching for them.
@a-robinson
Copy link
Contributor

Ah, interesting. I called it a system call because it showed up in strace, but I guess that's not true.

I tried benchmarking it for fun, and on my macbook I get

time.Now() = 11.0 ns/op
mutex.Lock() + mutex.Unlock() = 23.8 ns/op
int++ = 0.32 ns/op

So it's definitely not going through a system call.

@bdarnell
Copy link
Contributor Author

bdarnell commented Feb 3, 2017

on my macbook...it's definitely not going through a system call.

Note that the vsdo trick Peter mentioned is linux-specific. MacOS has its own trick to get the time without a system call, but you can't automatically generalize from one platform to the other.

@bdarnell bdarnell merged commit c4813a0 into cockroachdb:master Feb 3, 2017
@bdarnell bdarnell deleted the disable-timed-mutex branch February 3, 2017 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants