net/http: ServeMux excess locking #28785
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
In #25383, a lock contention regression was brought up in
ServeMux
. I believe this lock contention is still present in the mux, and could be removed. Making ServeMux have an atomically loaded handler map can help reduce latency of serving at the cost of more expensive mutations.A sample CL that fixes this regression is https://go-review.googlesource.com/c/go/+/149377 and shows promising speedups on the benchmarks:
However, this change depends on using CompareAndSwap, which is only available for
unsafe.Pointer
values. The reviewer of the CL expressed that usingunsafe
is unacceptable, though I am not really sure why. I have previously proposed thatatomic.Value
should gain these methods in #26728, but the proposal was also declined.Options
Thus, there are a few ways forward that I can think of, but need a decision from the Go team:
unsafe
inServeMux
, and gain the extra efficiency.atomic.Value.CompareAndSwap()
, and prioritize it being added as a public (or private) API, and use it instead.I feel rather helpless with regards to options 1 and 2. I have suggested both, but have received differing reasons for why they aren't acceptable from different Go team members. I'd rather the Go team just pick one of the 4 options above, because the requirements for changing Go are opaque from my POV.
cc: @bradfitz @rsc
The text was updated successfully, but these errors were encountered: