• yoav-steinberg's avatar
    Optimization: remove `updateClientMemUsage` from i/o threads. (#10401) · cf6dcb7b
    yoav-steinberg authored
    In a benchmark we 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
    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.
    cf6dcb7b
server.h 162 KB