mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 03:05:51 +03:00
[GH-ISSUE #3004] Remove lock in NameServerStats #1108
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#1108
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @divergentdave on GitHub (May 21, 2025).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/3004
NameServerStatscurrently tracks a modified exponentially-weighted moving average of name server latency, using a combination of anAtomicU32and aparking_lot::Mutex. This lock gets taken inside tight loops, such as when sorting connections in a pool.We could replace both fields of
NameServerStatswith a singleAtomicU128from theportable-atomicscrate. This would let us remove the locking, while still ensuring that the smoothed RTT and last update timestamp are updated atomically. The smoothed RTT is currently stored in a 32 byte integer. We can first turn theInstantinsidelast_updateinto aDurationby taking the duration since some baseline time stored in aOnceCell. Then, we can destructure thatDurationusingas_secs()andsubsec_nanos(). These methods return au64andu32respectively. (Theatomic-timecrate does something similar to this) We could set aside a seconds field ofu64::MAXas a sentinel value to representNone. Then, all of these would fit neatly into au128. The documentation forportable-atomicssays that there is broad support for 128-bit atomic operations on modern hardware. Failing that, the crate provides a slower fallback using global locks. VariousNameServerStatsmethods would be changed to do a singlefetch_update()on this packed field, instead of locking the mutex and then doing afetch_update()on the other field.@djc commented on GitHub (May 21, 2025):
Did you see this show up as hot in an actual profile? IMO we should only do this if it does.
@divergentdave commented on GitHub (May 21, 2025):
No, I haven't tried measuring this yet.