-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Optimization: remove updateClientMemUsage from i/o threads.
#10401
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
Optimization: remove updateClientMemUsage from i/o threads.
#10401
Conversation
oranagra
left a comment
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
…only if we're not threading.
|
@oranagra Please re-review. |
|
@yoav-steinberg we can notice a reduction of the CPU cycles on updateClientMemUsage from 2.2% -> 1.5% but the increase in ops/sec is not very significant ( as expected the measurements of throughput and latency are done without the profiler ). Nonetheless, if we look at the impact in latency ( 0.5% drop we can associate it with the drop on the CPU cycles spent on updateClientMemUsage ). WRT to measured changes on throughput and latency:
This is small improvement but nonetheless is a reduction that we should merge IMHO. Agree? confirmation that indeed the function is less heavy on CPU nowunstable (af6d5c5) total CPU time of updateClientMemUsage + children's: ~2.2% of CPU cyles wip_optimize_updateClientMemUsage, (406aea4): benchmarksteps: results for unstable unstable (af6d5c5) : results for wip_optimize_updateClientMemUsage, (406aea4) : |
|
@filipecosta90 Thanks for the analysis. Please note that this fix merges |
…10401) In a benchmark we noticed we spend a relatively long time updating the client memory usage leading to performance degradation. Before redis#8687 this was performed in the client's cron and didn't affect performance. But since introducing client eviction we need to perform this after filling the input buffers and after processing commands. This also lead me to write this code to be thread safe and perform it in the i/o threads. It turns out that the main performance issue here is related to atomic operations being performed while updating the total clients memory usage stats used for client eviction (`server.stat_clients_type_memory[]`). This update needed to be atomic because `updateClientMemUsage()` was called from the IO threads. In this commit I make sure to call `updateClientMemUsage()` only from the main thread. In case of threaded IO I call it for each client during the "fan-in" phase of the read/write operation. This also means I could chuck the `updateClientMemUsageBucket()` function which was called during this phase and embed it into `updateClientMemUsage()`. Profiling shows this makes `updateClientMemUsage()` (on my x86_64 linux) roughly x4 faster.
In a benchmark done by @filipecosta90 he noticed we spend a relatively long time updating the client memory usage leading to performance degradation.
Before #8687 this was performed in the client's cron and didn't affect performance. But since introducing client eviction we need to perform this after filling the input buffers and after processing commands. This also lead me to write this code to be thread safe and perform it in the i/o threads.
It turns out that the main performance issue here is related to atomic operations being performed while updating the total clients memory usage stats used for client eviction (
server.stat_clients_type_memory[]). This update needed to be atomic becauseupdateClientMemUsage()was called from the IO threads.In this PR I make sure to call
updateClientMemUsage()only from the main thread. In case of threaded IO I call it for each client during the "fan-in" phase of the read/write operation. This also means I could chuck theupdateClientMemUsageBucket()function which was called during this phase and embed it intoupdateClientMemUsage().Profiling shows this makes
updateClientMemUsage()(on my x86_64 linux) roughly x4 faster.This is still a WIP since I need to clean up the code and it requires some attention during review to make sure all threading issues are resolved and client eviction wasn't broken in any way including when running with read/write io threads.
Attached are my profiling flame graphs.