-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
✨ Add customTags in logger middleware Config #2188
Conversation
Can you send here old and new benchmark comparision |
Seems to have slowed down :-( old
new
|
Ok then just try to improve a little bit |
I will try, even though it is a bit difficult for me |
It's hard to optimize this code at my level, so it looks like I'll have to close this PR :-< |
We can try to support you |
Really? Thx ! |
d9cf204
to
2449071
Compare
better than before: goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v2/middleware/logger
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
Benchmark_Logger
Benchmark_Logger-2 2779996 439.7 ns/op 80 B/op 2 allocs/op
Benchmark_Logger-2 2711770 433.0 ns/op 80 B/op 2 allocs/op
Benchmark_Logger-2 2692728 437.2 ns/op 80 B/op 2 allocs/op
Benchmark_Logger-2 2676159 452.4 ns/op 80 B/op 2 allocs/op
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 6.884s |
78e1d4c
to
addc718
Compare
use switch goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v2/middleware/logger
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
Benchmark_Logger
Benchmark_Logger-2 5582337 219.6 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 5000182 237.4 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 5331586 215.4 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 5741889 209.6 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 5.683s
PASS use map goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v2/middleware/logger
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
Benchmark_Logger
Benchmark_Logger-2 4919536 244.3 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 4852894 256.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 4817518 243.4 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 4551956 249.3 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 5.968s
|
I don't think it's a problem with my code that the check didn't pass, right? |
No, will look at the pull request in the next few days |
I'm sorry to bother you, but I'm just confused about the PR not passing. |
its because of the vulnerability check |
addc718
to
34d2a39
Compare
This issue has been fixed and you need to update the code & this change requires a documentation update |
34d2a39
to
4b0e067
Compare
@Skyenought can you check my last comment and refresh the branch |
4e4fa61
to
02ac453
Compare
Now logger support custom tags like "reqHeader:x-key"
|
no i mean to the benchmark you shared at the beginning with the map and the switch in the last one where you compared switch and map there was a gap of 100ns in the first one there was only a gap of 20ns |
The latest comparison is between the map logic of my code and your map logic: if index := strings.Index(tag, ":"); index != -1 {
if logFunc, ok := tagFunctionMap[tag[0:index+1]]; ok {
return logFunc(buf, c, w, tag)
}
}
if index := strings.Index(tag, ":"); index != -1 {
result := subStr(tag, 0, index+1)
logFunc := tagFunctionMap[result]
return logFunc(buf, c, w, tag)
} |
yes i know, i also mean the other comments with the benchmarks |
I find that whenever I use map to match tags, either your changes to the map logic or my changes, it becomes less performant than switch matching |
will push an optimized version later |
Thank you for the code review |
05dabe7 |
ok |
Is it now better/faster on your machine? |
yes, at now faster than before: goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v2/middleware/logger
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
Benchmark_Logger
Benchmark_Logger-2 3469314 362.5 ns/op 16 B/op 1 allocs/op
Benchmark_Logger-2 3439934 351.2 ns/op 16 B/op 1 allocs/op
Benchmark_Logger-2 3618189 333.2 ns/op 16 B/op 1 allocs/op
Benchmark_Logger-2 3367159 344.4 ns/op 16 B/op 1 allocs/op
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 6.262s before goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v2/middleware/logger
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
Benchmark_Logger
Benchmark_Logger-2 3122877 386.0 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 3019996 385.9 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 3146631 382.3 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-2 3159733 388.7 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/gofiber/fiber/v2/middleware/logger 6.380s |
But not faster than the master with the benchmark adjustment? Maybe it's because of the stuff we add to the context. |
if not add something in context, we couldn`t get some message. It's 1:13 am in my time zone, so I'm off to bed. I wish you all the best |
benchmark with format Benchmark_Logger-12 4105185 293.7 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4130638 290.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4085211 288.9 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4149218 292.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4114450 290.6 ns/op 0 B/op 0 allocs/op feature branch: Benchmark_Logger-12 4541797 262.4 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4541694 261.9 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4574413 261.2 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4519794 261.1 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4617871 260.0 ns/op 0 B/op 0 allocs/op benchmark with default format Benchmark_Logger-12 1840008 628.7 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1882804 636.4 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1841458 684.7 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1883836 662.0 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1851812 643.3 ns/op 8 B/op 1 allocs/op feature branch: Benchmark_Logger-12 1690204 808.4 ns/op 56 B/op 3 allocs/op
Benchmark_Logger-12 1479172 758.2 ns/op 56 B/op 3 allocs/op
Benchmark_Logger-12 1578549 771.2 ns/op 56 B/op 3 allocs/op
Benchmark_Logger-12 1557202 763.5 ns/op 56 B/op 3 allocs/op
Benchmark_Logger-12 1551295 828.1 ns/op 56 B/op 3 allocs/op for these allocations i created a task in the code reason for the allocations are the storing of the user values we should try something like this (v3) fiber/middleware/logger/logger.go Lines 104 to 108 in debdb8c
fiber/middleware/logger/logger.go Lines 157 to 159 in debdb8c
but with a sync pool |
After the usage of syncPool and data structs benchmark with format Benchmark_Logger-12 4105185 293.7 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4130638 290.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4085211 288.9 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4149218 292.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4114450 290.6 ns/op 0 B/op 0 allocs/op feature branch: Benchmark_Logger-12 4293021 290.3 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4115019 287.7 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4231435 287.5 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4059115 284.3 ns/op 0 B/op 0 allocs/op
Benchmark_Logger-12 4272568 281.6 ns/op 0 B/op 0 allocs/op benchmark with default format Benchmark_Logger-12 1840008 628.7 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1882804 636.4 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1841458 684.7 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1883836 662.0 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1851812 643.3 ns/op 8 B/op 1 allocs/op feature branch: Benchmark_Logger-12 1907866 663.8 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1835814 641.3 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1710475 633.3 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1789392 652.6 ns/op 8 B/op 1 allocs/op
Benchmark_Logger-12 1888110 645.6 ns/op 8 B/op 1 allocs/op |
@Skyenought @li-jin-gou @hunterzhang86 iam done now -> performance is the same like before but with the feature |
if that is gemerged I will start the release |
very cool👍🏻 |
Almost the same performance now 👍🏻 |
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Explain the details for making this change. What existing problem does the pull request solve?
Fixes #2187
Type of change
Please delete options that are not relevant.
Checklist:
Commit formatting:
Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/