Optimize client memory usage tracking operation while client eviction is disabled#11348
Conversation
…t eviction is disabled
|
@hpatro can you post some benchmark results as well? please keep me honest (didn't review the code carefully) |
Will gather that shortly.
Correct. Memory introspection is still present but the accounting only happens via the clientsCron and not during input/output buffer modification when client-eviction is not enabled.
When client-eviction is eventually enabled, I'm updating the memory usage and placing it in the correct bucket during the config update itself. This is an O(N) operation (N = number of clients) but with this there is no race condition with client-eviction and client-memory-usage update operation. |
|
ohh, so it's not just the buckets that's not updated, it also means the INFO MEMORY fields are slightly outdated (up to the last second). I'm not sure an O(N) operation on all clients in CONFIG SET is acceptable. i'd rather let it kick in with a delay. @yoav-steinberg maybe you can have a look at this. |
Yes the same behavior as 6.2 |
Worth checking if there are some other slow |
Benchmark updateWith a single
Machinec5.4xlarge Benchmark 1:
|
|
@oranagra Also, I tried switching the config |
|
@hpatro can you measure the LATENCY LATEST or SLOWLOG value of that CONFIG SET? (instantaneous doesn't mean a lot to me). |
|
@hpatro any news here on my last request? |
|
@oranagra Couldn't get back to this earlier. I will try to pull the number this week. |
|
I tested the scenario via running multiple After reaching the desired client count, I ran the following:
And here are the numbers (3 runs):
The time spent for this operation seems to be reasonable to me. I tested few more scenarios with higher payload size via @oranagra Let me know what you think. |
|
ok, so that config takes only some 20ms for a 80k clients. sounds ok to me |
* rename updateClientMemUsage so if there are any in old branches and forks it'll cail to build (due to the role change) * move updateClientMemUsage to create a smaller diff * updateClientMemUsageAndBucket make sure to clear the bucket even if client eviction is disabled * clientsCron call updateClientMemUsageAndBucket when client eviction is enabled * unify test code of new tests and some minior cleanups
|
using |
scan the clients only when the config changes state from enabled to disabled or vice versa. chagne server.client_mem_usage_buckets to be runtime allocated and use it as an indication of the previous config.
|
confirmed that updateClientMemUsage overhead reported in #10981 (comment) on the default benchmark run of redis-benchmark was mitigated: I could check that before it took 1% of cpu cycles in after 0.06% in unstable - c0267b3 ( after Optimize client memory usage tracking operation ) : |
|
@filipecosta90 i'm not sure we can compare a specific function to another one in this case, updateClientMemUsageAndBucket is getting called a lot but immediately returns, and there are other change to compliment that. for this kind of change, i'd rather see the impact on the throughput rather than cost of a specific function (not being a local optimization to a function with equivalent capabilities). |
… is disabled (#11348) ## Issue During the client input/output buffer processing, the memory usage is incrementally updated to keep track of clients going beyond a certain threshold `maxmemory-clients` to be evicted. However, this additional tracking activity leads to unnecessary CPU cycles wasted when no client-eviction is required. It is applicable in two cases. * `maxmemory-clients` is set to `0` which equates to no client eviction (applicable to all clients) * `CLIENT NO-EVICT` flag is set to `ON` which equates to a particular client not applicable for eviction. ## Solution * Disable client memory usage tracking during the read/write flow when `maxmemory-clients` is set to `0` or `client no-evict` is `on`. The memory usage is tracked only during the `clientCron` i.e. it gets periodically updated. * Cleanup the clients from the memory usage bucket when client eviction is disabled. * When the maxmemory-clients config is enabled or disabled at runtime, we immediately update the memory usage buckets for all clients (tested scanning 80000 took some 20ms) Benchmark shown that this can improve performance by about 5% in certain situations. Co-authored-by: Oran Agra <[email protected]> (cherry picked from commit c0267b3)
…ors (#11657) This call is introduced in #8687, but became irrelevant in #11348, and is currently a no-op. The fact is that #11348 an unintended side effect, which is that even if the client eviction config is enabled, there are certain types of clients for which memory consumption is not accurately tracked, and so unlike normal clients, their memory isn't reported correctly in INFO.
…ors (#11657) This call is introduced in #8687, but became irrelevant in #11348, and is currently a no-op. The fact is that #11348 an unintended side effect, which is that even if the client eviction config is enabled, there are certain types of clients for which memory consumption is not accurately tracked, and so unlike normal clients, their memory isn't reported correctly in INFO. (cherry picked from commit af0a4fe)
… is disabled (redis#11348) ## Issue During the client input/output buffer processing, the memory usage is incrementally updated to keep track of clients going beyond a certain threshold `maxmemory-clients` to be evicted. However, this additional tracking activity leads to unnecessary CPU cycles wasted when no client-eviction is required. It is applicable in two cases. * `maxmemory-clients` is set to `0` which equates to no client eviction (applicable to all clients) * `CLIENT NO-EVICT` flag is set to `ON` which equates to a particular client not applicable for eviction. ## Solution * Disable client memory usage tracking during the read/write flow when `maxmemory-clients` is set to `0` or `client no-evict` is `on`. The memory usage is tracked only during the `clientCron` i.e. it gets periodically updated. * Cleanup the clients from the memory usage bucket when client eviction is disabled. * When the maxmemory-clients config is enabled or disabled at runtime, we immediately update the memory usage buckets for all clients (tested scanning 80000 took some 20ms) Benchmark shown that this can improve performance by about 5% in certain situations. Co-authored-by: Oran Agra <[email protected]>
… is disabled (redis#11348) ## Issue During the client input/output buffer processing, the memory usage is incrementally updated to keep track of clients going beyond a certain threshold `maxmemory-clients` to be evicted. However, this additional tracking activity leads to unnecessary CPU cycles wasted when no client-eviction is required. It is applicable in two cases. * `maxmemory-clients` is set to `0` which equates to no client eviction (applicable to all clients) * `CLIENT NO-EVICT` flag is set to `ON` which equates to a particular client not applicable for eviction. ## Solution * Disable client memory usage tracking during the read/write flow when `maxmemory-clients` is set to `0` or `client no-evict` is `on`. The memory usage is tracked only during the `clientCron` i.e. it gets periodically updated. * Cleanup the clients from the memory usage bucket when client eviction is disabled. * When the maxmemory-clients config is enabled or disabled at runtime, we immediately update the memory usage buckets for all clients (tested scanning 80000 took some 20ms) Benchmark shown that this can improve performance by about 5% in certain situations. Co-authored-by: Oran Agra <[email protected]>
…ors (redis#11657) This call is introduced in redis#8687, but became irrelevant in redis#11348, and is currently a no-op. The fact is that redis#11348 an unintended side effect, which is that even if the client eviction config is enabled, there are certain types of clients for which memory consumption is not accurately tracked, and so unlike normal clients, their memory isn't reported correctly in INFO.
Issue
During the client input/output buffer processing, the memory usage is incrementally updated to keep track of clients going beyond a certain threshold
maxmemory-clientsto be evicted. However, this additional tracking activity leads to unnecessary CPU cycles wasted when no client-eviction is required. It is applicable in two cases.maxmemory-clientsis set to0which equates to no client eviction (applicable to all clients)CLIENT NO-EVICTflag is set toONwhich equates to a particular client not applicable for eviction.Solution
maxmemory-clientsis set to0orclient no-evictison. The memory usage is tracked only during theclientCroni.e. it gets periodically updated.Benchmark shown that this can improve performance by about 5% in certain situations.
Testing
Redis Benchmark
During the above benchmark operation, ran the following CPU profiling command.
Machine
c5.4xlarge
Observation
The CPU utilization for
updateClientMemoryUsagedropped from2.39%during write and1.07%during read to0.FlameGraph on the current branch
FlameGraph on the unstable branch