types_hash_bucket_size

The 'types_hash_bucket_size' directive sets the hash bucket size for the MIME type hash table in NGINX.

Syntaxtypes_hash_bucket_size size;
Default64;
Contexthttp, server, location
Arguments1

Description

The 'types_hash_bucket_size' directive in NGINX allows administrators to specify the size of the hash buckets used for storing MIME types. This directive is crucial for performance optimization because the hash table is used to store the mappings of file extensions to their MIME types, which are determined during file requests. If a MIME type is requested that is not found in the hash table, the server needs to create a new entry, which can lead to performance hits if the buckets are too small. The size of each bucket is typically specified in bytes, and it should be set according to the number of MIME types expected to be used by an application.

The directive can take a parameter that specifies the bucket size. The recommended size is usually determined based on the specific use case and the expected complexity of MIME type mappings in the application. If there are a large number of different MIME types, increasing the bucket size can help minimize lookup times and collisions within the hash table. It is important for server administrators to test and profile their NGINX configurations to determine the optimal value for this directive, particularly in environments where performance is a critical concern.

Config Example

http {
    types_hash_bucket_size 128;
    include mime.types;
}

Setting the size too small can result in hash collisions and decreased performance.

Excessively large bucket sizes can waste memory, especially if the number of MIME types is low.

Changes to this directive require a reload of the NGINX configuration for the changes to take effect.

← Back to all directives