• Moti Cohen's avatar
    Add KEYSIZES section to INFO (#13592) · 2ec78d26
    Moti Cohen authored
    This PR adds a new section to the `INFO` command output, called
    `keysizes`. This section provides detailed statistics on the
    distribution of key sizes for each data type (strings, lists, sets,
    hashes and zsets) within the dataset. The distribution is tracked using
    a base-2 logarithmic histogram.
    
    # Motivation
    Currently, Redis lacks a built-in feature to track key sizes and item
    sizes per data type at a granular level. Understanding the distribution
    of key sizes is critical for monitoring memory usage and optimizing
    performance, particularly in large datasets. This enhancement will allow
    users to inspect the size distribution of keys directly from the `INFO`
    command, assisting with performance analysis and capacity planning.
    
    # Changes
    New Section in `INFO` Command: A new section called `keysizes` has been
    added to the `INFO` command output. This section reports a per-database,
    per-type histogram of key sizes. It provides insights into how many keys
    fall into specific size ranges (represented in powers of 2).
    
    **Example output:**
    ```
    127.0.0.1:6379> INFO keysizes
    # Keysizes
    db0_distrib_strings_sizes:1=19,2=655,512=100899,1K=31,2K=29,4K=23,8K=16,16K=3,32K=2
    db0_distrib_lists_items:1=5784492,32=3558,64=1047,128=676,256=533,512=218,4K=1,8K=42
    db0_distrib_sets_items:1=735564=50612,8=21462,64=1365,128=974,2K=292,4K=154,8K=89,
    db0_distrib_hashes_items:2=1,4=544,32=141169,64=207329,128=4349,256=136226,1K=1
    ```
    ## Future Use Cases:
    The key size distribution is collected per slot as well, laying the
    groundwork for future enhancements related to Redis Cluster.
    2ec78d26
server.c 294 KB