Skip to content
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

socket: amortise cost of querying OS time counter #149

Merged
merged 2 commits into from
Apr 19, 2018

Conversation

domodwyer
Copy link

#116 adds a much needed ability to shrink the connection pool, but requires
tracking the last-used timestamp for each socket after every operation. Frequent
calls to time.Now() in the hot-path reduced read throughput by ~6% and increased
the latency (and variance) of socket operations as a whole.

This PR adds a periodically updated time value to amortise the cost of the last-
used bookkeeping, restoring the original throughput at the cost of approximate
last-used values (configured to be ~25ms of potential skew).

On some systems (currently including FreeBSD) querying the time counter also
requires a syscall/context switch.

Fixes #142.


x => 860240ea96bd411b6f6165bb634ac6209981f2c5-select-zipfian-throughput.log
y => coarsetime-select-zipfian-throughput.log

     n   min   max  median  average    stddev      p99
x 3600 49235 64286 59562.5 59583.09 2117.0586 63637.03
y 3600 60846 64790 63199.0 63203.38  373.3961 64129.00

  54000        56000         58000        60000         62000        64000
 |--+------------+-------------+------------+-------------+------------+-------|
                                +--------+---------+
1    ---------------------------|        |         |----------------------
                                +--------+---------+
                                                                +-++
2                                                           ----| ||-----
                                                                +-++
Legend: 1=data$x, 2=data$y

At 95% probablitiy:
===> average is statistically significant     (p=0.000000, diff ~3620.294167)
===> variance is statistically significant    (p=0.000000)

#116 adds a much needed ability to shrink the connection pool, but requires
tracking the last-used timestamp for each socket after every operation. Frequent
calls to time.Now() in the hot-path reduced read throughput by ~6% and increased
the latency (and variance) of socket operations as a whole.

This PR adds a periodically updated time value to amortise the cost of the last-
used bookkeeping, restoring the original throughput at the cost of approximate
last-used values (configured to be ~25ms of potential skew).

On some systems (currently including FreeBSD) querying the time counter also
requires a syscall/context switch.

Fixes #142.
@domodwyer domodwyer force-pushed the feature/amortised-time-query branch from 00e46a5 to e45b6c9 Compare April 19, 2018 10:21
@domodwyer domodwyer merged commit caed401 into development Apr 19, 2018
@domodwyer domodwyer deleted the feature/amortised-time-query branch April 19, 2018 10:49
libi pushed a commit to libi/mgo that referenced this pull request Dec 1, 2022
globalsign#116 adds a much needed ability to shrink the connection pool, but requires
tracking the last-used timestamp for each socket after every operation. Frequent
calls to time.Now() in the hot-path reduced read throughput by ~6% and increased
the latency (and variance) of socket operations as a whole.

This PR adds a periodically updated time value to amortise the cost of the last-
used bookkeeping, restoring the original throughput at the cost of approximate
last-used values (configured to be ~25ms of potential skew).

On some systems (currently including FreeBSD) querying the time counter also
requires a syscall/context switch.

Fixes globalsign#142.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants