-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor client outbound queues #3733
Conversation
Investigating |
7072394
to
bc0d67f
Compare
e18c7c1
to
e260af9
Compare
4K+64K buffers vs
8 byte message:
48000 byte message:
|
f48254b
to
9aa4d4f
Compare
cf1eed9
to
2b37beb
Compare
928f520
to
14f3abb
Compare
e72f9b7
to
0f7e419
Compare
@derekcollison Review comments addressed! |
Let's squash down to 1 commit.. |
0f7e419
to
1ac2726
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Also try to reduce flakiness of `TestClusterQueueSubs` and `TestCrossAccountServiceResponseTypes`
1ac2726
to
e4b6ba2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This extends the previous work in #3733 with the following: 1. Remove buffer coalescing, as this could result in a race condition during the `writev` syscall in rare circumstances 2. Add a third buffer size, to ensure that we aren't allocating more than we need to without coalescing 3. Refactor buffer handling in the WebSocket code to reduce allocations and ensure owned buffers aren't incorrectly being pooled resulting in further race conditions Fixes nats-io/nats.ws#194. Signed-off-by: Neil Twigg <neil@nats.io>
Previously, dynamically-sized buffers were used and discarded often in the client outbound queues. This PR removes the dynamic sizing and instead replaces them with fixed-size coalesced buffers, as well as a
sync.Pool
to enable efficient buffer reuse. The result is that the server now allocates dramatically less memory when sending data to clients.The following results are generated by running
-bench=BenchmarkJetStreamConsume -benchtime=100000x -memprofile=
.Memory allocations on
main
(2.9.10) as of this morning:Memory allocations on this PR:
I don't know if this will make a huge difference to throughput in the usual case, but for servers that are pushing a lot of traffic or handling a large number of concurrent clients, this should reduce the GC burden noticeably and, with any luck, bring load averages down a little bit.
There are a couple TODOs around WebSockets but figured they would be better dealt with separately.
Signed-off-by: Neil Twigg neil@nats.io
/cc @nats-io/core