labels_hash_bucket_size

Defines the size of the hash buckets for storing global key-value labels in NGINX.

Syntaxlabels_hash_bucket_size number;
Defaultnone
Contexthttp
Arguments1

Description

The labels_hash_bucket_size directive configures the bucket size for the hash table used to store global key-value labels defined in the NGINX configuration. This directive is critical for efficiently managing the storage of these labels, which can be used dynamically in request processing, logging, and configuration purposes.

This directive accepts a numerical argument that specifies the bucket size in bytes. The choice of bucket size can affect the performance and memory consumption of the hash table. A larger bucket size may reduce hash collisions at the cost of increased memory use, while a smaller size may lead to more collisions and thus degrade performance. It's important to choose a bucket size that is appropriate for the expected number of labels and their combined sizes, to balance memory efficiency and access speed.

Typically, the default bucket sizes are set to 32, 64, or 128 bytes, based on the architecture's cache line size. Users are encouraged to adjust this setting in relation to their specific usage scenarios to optimize performance, especially in cases where a large number of labels are being utilized.

Config Example

http {
    labels_hash_bucket_size 64;
    label environment production;
    label region us-west-1;
}

Setting a bucket size too small can lead to poor performance due to increased hash collisions.

Changing this value requires restarting NGINX for the new settings to take effect.

← Back to all directives