[PATCH] HTTP: allow tuning test_types_hash
Danila Vershinin
dvershinin at cloudlinux.com
Tue Mar 14 11:09:48 UTC 2023
# HG changeset patch
# User Danila Vershinin <dvershinin at cloudlinux.com>
# Date 1678790847 -28800
# Tue Mar 14 18:47:27 2023 +0800
# Node ID ccb905b26f0efcd6eb3814ca9900616bb8095bec
# Parent 8771d35d55d0a2b1cefaab04401d6f837f5a05a2
HTTP: allow tuning test_types_hash.
In edge cases, with admittedly unnecessary long or numerous MIME type
entries in config, users are presented with a startup error message
asking to adjust test_types_hash_* directives which do not actually
exist. This adds those directives.
diff -r 8771d35d55d0 -r ccb905b26f0e src/http/ngx_http.c
--- a/src/http/ngx_http.c Fri Mar 10 07:43:50 2023 +0300
+++ b/src/http/ngx_http.c Tue Mar 14 18:47:27 2023 +0800
@@ -2083,6 +2083,9 @@
ngx_str_t *default_types)
{
ngx_hash_init_t hash;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
if (*keys) {
@@ -2092,8 +2095,8 @@
hash.hash = types_hash;
hash.key = NULL;
- hash.max_size = 2048;
- hash.bucket_size = 64;
+ hash.max_size = cmcf->test_types_hash_max_size;
+ hash.bucket_size = cmcf->test_types_hash_bucket_size;
hash.name = "test_types_hash";
hash.pool = cf->pool;
hash.temp_pool = NULL;
@@ -2122,8 +2125,8 @@
hash.hash = prev_types_hash;
hash.key = NULL;
- hash.max_size = 2048;
- hash.bucket_size = 64;
+ hash.max_size = cmcf->test_types_hash_max_size;
+ hash.bucket_size = cmcf->test_types_hash_bucket_size;
hash.name = "test_types_hash";
hash.pool = cf->pool;
hash.temp_pool = NULL;
diff -r 8771d35d55d0 -r ccb905b26f0e src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Fri Mar 10 07:43:50 2023 +0300
+++ b/src/http/ngx_http_core_module.c Tue Mar 14 18:47:27 2023 +0800
@@ -778,6 +778,20 @@
#endif
+ { ngx_string("test_types_hash_bucket_size"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, test_types_hash_bucket_size),
+ NULL },
+
+ { ngx_string("test_types_hash_max_size"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_core_main_conf_t, test_types_hash_max_size),
+ NULL },
+
ngx_null_command
};
@@ -3401,6 +3415,9 @@
cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT;
cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT;
+ cmcf->test_types_hash_max_size = NGX_CONF_UNSET_UINT;
+ cmcf->test_types_hash_bucket_size = NGX_CONF_UNSET_UINT;
+
return cmcf;
}
@@ -3424,6 +3441,12 @@
cmcf->variables_hash_bucket_size =
ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size);
+ ngx_conf_init_uint_value(cmcf->test_types_hash_max_size, 2048);
+ ngx_conf_init_uint_value(cmcf->test_types_hash_bucket_size, 64);
+
+ cmcf->test_types_hash_bucket_size =
+ ngx_align(cmcf->test_types_hash_bucket_size, ngx_cacheline_size);
+
if (cmcf->ncaptures) {
cmcf->ncaptures = (cmcf->ncaptures + 1) * 3;
}
diff -r 8771d35d55d0 -r ccb905b26f0e src/http/ngx_http_core_module.h
--- a/src/http/ngx_http_core_module.h Fri Mar 10 07:43:50 2023 +0300
+++ b/src/http/ngx_http_core_module.h Tue Mar 14 18:47:27 2023 +0800
@@ -168,6 +168,9 @@
ngx_uint_t variables_hash_max_size;
ngx_uint_t variables_hash_bucket_size;
+ ngx_uint_t test_types_hash_bucket_size;
+ ngx_uint_t test_types_hash_max_size;
+
ngx_hash_keys_arrays_t *variables_keys;
ngx_array_t *ports;
More information about the nginx-devel
mailing list