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
net/http: ServeMux benchmark regression #25383
Comments
It seems like the commit you're pointing to was a race bugfix, so it's not the type of performance regression that can be easily fixed or reverted. Do you have any ideas on how to get the numbers back to 1.10 levels? |
@mvdan, I'm not familiar with
I've reported it for completeness as it showed pretty high delta. |
@mvdan it's the defer, some If that's acceptable, I can push a PR sometime this week (or even better if you wanna do ;)). |
Change https://golang.org/cl/113996 mentions this issue: |
Change https://golang.org/cl/116378 mentions this issue: |
@odeke-em, want to post an update on this now that 116378 is submitted? Or bump to Go 1.12 or Unplanned? |
Also, add a benchmark variant ("SkipServe") that only benchmarks the ServeMux handler selection path. name old time/op new time/op delta ServeMux_SkipServe-4 74.2µs ± 2% 60.6µs ± 1% -18.31% (p=0.000 n=10+9) name old alloc/op new alloc/op delta ServeMux_SkipServe-4 2.62kB ± 0% 0.00kB ±NaN% -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ServeMux_SkipServe-4 180 ± 0% 0 ±NaN% -100.00% (p=0.000 n=10+10) Updates #25383 Change-Id: Icfbb3b977e309093d032e922d1b4f254df6f5955 Reviewed-on: https://go-review.googlesource.com/116378 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
CL 96575 introduced concurrency protection for ServeMux.shouldRedirect with a read lock and deferred unlock. However, the change produced a noticeable regression. Instead add the suffix "RLocked" to the function name to declare that we should hold the read lock as a pre-requisite before calling it, hence avoiding the defer altogether. Benchmarks: name old time/op new time/op delta ServeMux-8 63.3µs ± 0% 54.6µs ± 0% -13.74% (p=0.000 n=9+9) ServeMux_SkipServe-8 41.4µs ± 2% 32.7µs ± 1% -21.05% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ServeMux-8 17.3kB ± 0% 17.3kB ± 0% ~ (all equal) ServeMux_SkipServe-8 0.00B 0.00B ~ (all equal) name old allocs/op new allocs/op delta ServeMux-8 360 ± 0% 360 ± 0% ~ (all equal) ServeMux_SkipServe-8 0.00 0.00 ~ (all equal) Updates #25383 Updates #25482 Change-Id: I2ffa4eafe165faa961ce23bd29b5653a89facbc2 Reviewed-on: https://go-review.googlesource.com/113996 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@odeke-em - Just wanted to check on this. I just re-ran the benchmarks from the current tip 510eea2 and 1.10.2
It seems we have a measurable improvement. Is there still anything else you would like to do on this ? |
Thank you for the reminder @agnivade! @carl-mastrangelo's nice CL https://go-review.googlesource.com/c/144937 aka commit 1645dfa massively levelled the ground so we are good now 1645dfa -- I had an almost similar change with longest prefix matching by sorting by length but didn't get the wins in his CL, cool stuff @carl-mastrangelo! With that I am going to close this issue, @bradfitz or anyone else please feel free to reopen or bump to Unplanned. |
@odeke-em I appreciate the call out, but I don't believe my change fixed this. I sent out https://go-review.googlesource.com/c/go/+/149377 which brings the latency down to the pre-lock levels. |
@carl-mastrangelo, thanks for the humility! For clarity, I should have spelled out that this issue was combated by a collective of fixes: and others that I might not have seen, which have brought the levels down to as @agnivade reported in #25383 (comment) |
The issue originally was a regression in performance, which is fixed (even improved) now. Although, changes were made in other areas, but it eventually improved performance. I think this issue can be closed, because the regression does not exist any more. Otherwise, we should re-title it to "net/http: remove mutex locks in ServeMux" because that is what this should be about. |
I replied before I noticed that @bradfitz reopened it. @carl-mastrangelo was just stating that he didn't think his CL fixed this issue but I explained why I mentioned his CL and how it contributed to bringing the regressions down in #25383 (comment). @bradfitz could you please reconsider closing this issue as it was about a regression that has been erased as mentioned in #25383 (comment) but also just by @agnivade in #25383 (comment)? |
Sure. Carl, file a new bug if you want to track lock removal. |
There is notable difference in Go1.10.2 and tip BenchmarkServeMux results:
The most significant impact comes from additional synchronization added in 2fd1b52. The commit message lacks benchmarks info, so I think it's worthwhile to report regression anyway and decide whether it can be addressed or not (we can't just remove locking if it's needed there, but there can be other options).
There are other causes of slowdown as commit right behind 2fd1b52 is still slower (but the delta is more tolerable):
The text was updated successfully, but these errors were encountered: