diff options
author | Dmitry Volyntsev <xeioex@nginx.com> | 2025-01-03 22:25:15 -0800 |
---|---|---|
committer | Dmitry Volyntsev <xeioexception@gmail.com> | 2025-01-06 15:52:14 -0800 |
commit | 855aa4c9fac01bd9fbdb1602b523edc00117ff09 (patch) | |
tree | 15d959648fd516e8257b9d97bfd815cf6a1c5c13 /nginx/ngx_js.c | |
parent | 4fb1c0ca6c950dc0460eaeec1ba3e96a53070878 (diff) | |
download | njs-855aa4c9fac01bd9fbdb1602b523edc00117ff09.tar.gz njs-855aa4c9fac01bd9fbdb1602b523edc00117ff09.zip |
Modules: removed extra VM creation per server.
Previously, when js_import was declared in http or stream blocks, an extra
copy of the VM instance was created for each server block. This was not
needed and consumed a lot of memory for configurations with many server
blocks.
This issue was introduced in 9b674412 (0.8.6) and was
partially fixed for location blocks only in 685b64f0 (0.8.7).
Diffstat (limited to 'nginx/ngx_js.c')
-rw-r--r-- | nginx/ngx_js.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 12b577a2..5c2a44cb 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -3343,6 +3343,16 @@ ngx_js_merge_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf, ngx_array_t *imports, *preload_objects, *paths; ngx_js_named_path_t *import, *pi, *pij, *preload; + if (prev->imports != NGX_CONF_UNSET_PTR && prev->engine == NULL) { + /* + * special handling to preserve conf->engine + * in the "http" or "stream" section to inherit it to all servers + */ + if (init_vm(cf, (ngx_js_loc_conf_t *) prev) != NGX_OK) { + return NGX_ERROR; + } + } + if (conf->imports == NGX_CONF_UNSET_PTR && conf->type == prev->type && conf->paths == NGX_CONF_UNSET_PTR @@ -3851,6 +3861,9 @@ ngx_js_init_conf_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf, return NGX_ERROR; } + ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "js vm init %s: %p", + conf->engine->name, conf->engine); + cln = ngx_pool_cleanup_add(cf->pool, 0); if (cln == NULL) { return NGX_ERROR; @@ -4039,6 +4052,10 @@ ngx_js_merge_conf(ngx_conf_t *cf, void *parent, void *child, ngx_js_loc_conf_t *conf = child; ngx_conf_merge_uint_value(conf->type, prev->type, NGX_ENGINE_NJS); + if (prev->type == NGX_CONF_UNSET_UINT) { + prev->type = NGX_ENGINE_NJS; + } + ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); ngx_conf_merge_size_value(conf->reuse, prev->reuse, 128); ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384); |