• Harkrishn Patro's avatar
    Optimize number of realloc syscall during multi/exec flow (#10921) · a3704d4e
    Harkrishn Patro authored
    ## Issue
    During the MULTI/EXEC flow, each command gets queued until the `EXEC`
    command is received and during this phase on every command queue, a
    `realloc` is being invoked. This could be expensive based on the realloc
    behavior (if copy to a new memory location). 
    
    
    ## Solution
    In order to reduce the no. of syscall, couple of optimization I've used.
    
    1. By default, reserve memory for atleast two commands. `MULTI/EXEC` for a
    single command doesn't have any significance. Hence, I believe customer wouldn't use it.
    2. For further reservation, increase the memory allocation in exponent growth (power of 2).
    This reduces the no. of `realloc` call from `N` to `log(N)` times.
    
    ## Other changes:
    
    * Include multi exec queued command array in client memory consumption calculation
    (affects client eviction too)
    a3704d4e
multi.c 16.8 KB