-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Calling Debug or Check on a Production Logger is slow #770
Comments
Hello! No, you're not using Zap incorrectly. Logrus is misconfigured in that After fixing the configuration, we get a more accurate idea of logging func BenchmarkLogrus(b *testing.B) {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(ioutil.Discard)
- log.SetLevel(log.WarnLevel)
+ log.SetLevel(log.DebugLevel)
Hope that helped! |
Thanks for your reply. To discard the logs was my intention actually. The CPU profile of my production application shows that zap uses 20% of my application's CPU time. Although I always use the method "check" and the production configuration. Logrus seems to be 20 times faster discarding debug logs in a production environment. Is there a reason for this? |
Oops, you're right. I misread the example. |
Dug into this. Most of the time is spent on |
Calling `time.Now()` and creating an entry is unnecessary if the underlying core has the specified level disabled. To reduce the cost of logs at disabled levels, skip entry creation if the log level is disabled in the core. This special logic does not apply to DPanic or higher logs as they may need to panic/exit even if the entry does not cause any log to be emitted. On my machine, disabled debugging logs are 6x (~60ns to ~10ns). Fixes #770.
One option: the The above benchmark, before:
and after:
Zap is still slower, likely because:
|
Calling `time.Now()` and creating an entry is unnecessary if the underlying core has the specified level disabled. To reduce the cost of logs at disabled levels, skip entry creation if the log level is disabled in the core. This special logic does not apply to DPanic or higher logs as they may need to panic/exit even if the entry does not cause any log to be emitted. On my machine, disabled debugging logs are 6x (~60ns to ~10ns) based on the example in the issue. benchcmp: ``` benchmark old ns/op new ns/op delta BenchmarkDisabledWithoutFields/Zap-12 8.42 1.59 -81.12% BenchmarkDisabledWithoutFields/Zap.Check-12 8.01 1.32 -83.52% BenchmarkDisabledWithoutFields/Zap.Sugar-12 12.4 11.4 -8.06% BenchmarkDisabledWithoutFields/Zap.SugarFormatting-12 117 102 -12.82% ``` Fixes #770.
Calling `time.Now()` and creating an entry is unnecessary if the underlying core has the specified level disabled. To reduce the cost of logs at disabled levels, skip entry creation if the log level is disabled in the core. This special logic does not apply to DPanic or higher logs as they may need to panic/exit even if the entry does not cause any log to be emitted. On my machine, disabled debugging logs are 6x (~60ns to ~10ns) based on the example in the issue. benchcmp: ``` benchmark old ns/op new ns/op delta BenchmarkDisabledWithoutFields/Zap-12 8.42 1.59 -81.12% BenchmarkDisabledWithoutFields/Zap.Check-12 8.01 1.32 -83.52% BenchmarkDisabledWithoutFields/Zap.Sugar-12 12.4 11.4 -8.06% BenchmarkDisabledWithoutFields/Zap.SugarFormatting-12 117 102 -12.82% ``` Fixes uber-go#770.
First of all: thank you for such a great library!
Unfortunately I have some performance issues when calling Check or Debug on a production logger. I am unsure if I am using the library wrong. I am using the following code:
And I get the following results:
Is this performance expected?
The text was updated successfully, but these errors were encountered: