-
Notifications
You must be signed in to change notification settings - Fork 18k
time: Now is "slow" #57749
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
Comments
For what it's worth we already have a benchmark for When I run
You got similar results on your "other computer." So tell us more about the computer on which |
Here is the result:
Both computers run a similar OS: ArchLinux, kernel updated today. |
There must be some relevant difference between them. Try building a trivial Go program that calls |
@pierrre, are you in a VM? What type? |
Hello, I will try to run strace, but I don't have access to the other computer today, so I will come back later. @bradfitz no I'm not using a VM Yes my production environment is running in a VM, but I didn't talk about it in this issue. |
FYI on my "slow" computer, strace shows
repeated thousands of times with almost no interruption. I will try on my "fast" computer later (I don't have access to it right now) |
That looks like the "slow" computer is somehow missing the VDSO that contains a non-syscall implementation of |
You could try searching Given that you see the system calls with strace, that means that VDSO is indeed falling back to system calls (or, less likely, the VDSO doesn't exist at all, but I don't think modern Linux ever omits it entirely). This is the source of the slowness (it is not a Go issue), the remaining question is why it is falling back. |
You can look at:
To see the available and current clock source. The clock source needs to be |
It could be related to one of https://bugzilla.kernel.org/show_bug.cgi?id=202525 or https://bugzilla.kernel.org/show_bug.cgi?id=216146 (both of which should result in dmesg warnings). |
Here is the result of strace on my "fast" computer:
repeated thousands of times |
I asked several coworkers at my company to run the same benchmark on various computer models: 5 of them have an Intel CPU, and the benchmark result is "fast": 30ns 1 has exactly the same model/CPU as I have: ThinkPad 14S Gen 1, AMD Ryzen 7 PRO 4750U
And he can reproduce the "slow" benchmark result: ~2000ns !
|
About the clock source: On my "slow" computer:
On my "fast" computer:
As far as I know, I didn't configure anything related to the clock source when I installed these 2 computers |
About dmesg: On my "slow" computer:
On my "fast" computer:
I don't really know how to interpret this |
OK I understand, feel free to close this issue if there is nothing we can do on Go side. |
This is the immediate problem. The kernel has decided that the TSC is not reliable and disabled its use. There is nothing we can do in Go. I suggest reaching out on one of the kernel bugs. https://bugzilla.kernel.org/show_bug.cgi?id=202525 has the same kernel warnings, though a slightly different CPU model. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Disclaimer: yes I know, I'm trying to do something "silly" (benchmarking
time.Now()
).But it has a real impact in production for me.
Context: I'm trying to measure the execution time of a function that is "fast" (below 1 microsecond).
I ran a benchmark on my function (with
testing.B
), so I know it's fast (below 1 microsecond).But I want to measure its execution time while it's running in production (and report it in my metrics).
So I did something simple:
Then I noticed that the measured duration was much higher than the time measured in my benchmark (around 5 microseconds, vs 1 microsecond in my benchmark).
So I did a benchmark that calls
time.Now()
:(Yes I closed all other running apps)
I'm very surprised, because this time (2249ns) is very high.
If I remember correctly, on my other computer it was 2 orders of magnitude lower (30ns)
I did a profiling of my benchmark.
All the CPU time is spent in
time.now()
(yes, lower casenow
)My question: how can I measure the execution time of a function, if calling
time.Now()
is slower than calling my function ?Feel free to close this issue if you think it's not a problem.
What did you expect to see?
Calling
time.Now()
should take approximately 30ns.This is the benchmark result on my other computer:
What did you see instead?
Calling
time.Now()
takes 2249ns, which is slower than the execution time of the function I'm trying to measure.The text was updated successfully, but these errors were encountered: