Setting up hashes设置哈希
To quickly process static sets of data such as server names, map directive’s values, MIME types, names of request header strings, nginx uses hash tables. 为了快速处理静态数据集,例如服务器名称、map指令的值、MIME类型、请求头字符串的名称,nginx使用哈希表。During the start and each re-configuration nginx selects the minimum possible sizes of hash tables such that the bucket size that stores keys with identical hash values does not exceed the configured parameter (hash bucket size). 在启动和每次重新配置期间,nginx选择哈希表的最小可能大小,以便存储具有相同哈希值的密钥的存储桶大小不超过配置的参数(哈希存储桶大小)。The size of a table is expressed in buckets. 表的大小用桶表示。The adjustment is continued until the table size exceeds the hash max size parameter. 继续调整,直到表大小超过哈希最大大小参数。Most hashes have the corresponding directives that allow changing these parameters, for example, for the server names hash they are server_names_hash_max_size and server_names_hash_bucket_size.大多数哈希具有允许更改这些参数的相应指令,例如,对于服务器名称哈希,它们是server_names_hash_max_size和server_names_hash_bucket_size。
The hash bucket size parameter is aligned to the size that is a multiple of the processor’s cache line size. 哈希桶大小参数与处理器缓存线大小的倍数对齐。This speeds up key search in a hash on modern processors by reducing the number of memory accesses. 这通过减少内存访问的数量,在现代处理器上加快了哈希中的键搜索。If hash bucket size is equal to one processor’s cache line size then the number of memory accesses during the key search will be two in the worst case — first to compute the bucket address, and second during the key search inside the bucket. 如果哈希桶大小等于一个处理器的缓存线大小,那么在最坏的情况下,密钥搜索期间的内存访问次数将为两次-第一次是计算桶地址,第二次是在桶内进行键搜索期间。Therefore, if nginx emits the message requesting to increase either hash max size or hash bucket size then the first parameter should first be increased.因此,如果nginx发出请求增加哈希最大大小或哈希桶大小的消息,则应首先增加第一个参数。