Nginx's hash tables

Thibault Koechlin thibault.koechlin at
Mon Apr 11 13:26:52 MSD 2011

Hello everyone,

I'm currently working on a module for Nginx, and I use a ngx_hash_t
where the actual keyname is an URI. Even with very few elements,(11) I
got the error message "could not build the xxx hash, you should
increase ...". So, I am looking for some information about nginx's hash
init, to understand what is going wrong.

Hash init structure goes as follow in my case, directly taken from

 hash_init.hash      = [pointer to a previously allocated hash_t]
 hash_init.key       = &ngx_hash_key_lc; //Function used to create keys
 hash_init.max_size  = 1024*10; //(1) This is the thing I don't get
 hash_init.bucket_size = 64; //(2) Number of entries in one bucket or
bucket size in bytes ?      = "hash_name";
 hash_init.pool           = cf->pool; //Pool used for hash's allocations
 hash_init.temp_pool      = NULL; //(3) ?

My question are about (1) and (2), and how to eval the needed size
properly. The hash_init function receives an array (ngx_array_t) of
ngx_hash_key_t, so the "real" data is already allocated, and the hash
table only contains pointers to the real data. So, what does max_size
(1) exactly corresponds to ? Regarding (2), I'd like to know if it is
really the size of one bucket in bytes ?


More information about the nginx-devel mailing list