[PATCH] HTTP/2: premalloc http2 recv_buffer in init_conf
Kasei Wang
kasei at kasei.im
Mon Sep 7 12:06:06 UTC 2020
# HG changeset patch
# User Kasei Wang <kasei at kasei.im>
# Date 1599480224 -28800
# Mon Sep 07 20:03:44 2020 +0800
# Node ID 1532a8fca7b24c3c3aa5cddd3362402d15f57a4f
# Parent 87d2ea860f380dc8418c97c0163412f53c2d008e
HTTP/2: premalloc http2 recv_buffer in init_conf
There is no need to check if h2mcf->recv_buffer malloced every time.
diff -r 87d2ea860f38 -r 1532a8fca7b2 src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c Mon Sep 10 18:57:39 2018 +0300
+++ b/src/http/v2/ngx_http_v2.c Mon Sep 07 20:03:44 2020 +0800
@@ -233,7 +233,6 @@
ngx_pool_cleanup_t *cln;
ngx_http_connection_t *hc;
ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_v2_main_conf_t *h2mcf;
ngx_http_v2_connection_t *h2c;
c = rev->data;
@@ -243,17 +242,6 @@
c->log->action = "processing HTTP/2 connection";
- h2mcf = ngx_http_get_module_main_conf(hc->conf_ctx, ngx_http_v2_module);
-
- if (h2mcf->recv_buffer == NULL) {
- h2mcf->recv_buffer = ngx_palloc(ngx_cycle->pool,
- h2mcf->recv_buffer_size);
- if (h2mcf->recv_buffer == NULL) {
- ngx_http_close_connection(c);
- return;
- }
- }
-
h2c = ngx_pcalloc(c->pool, sizeof(ngx_http_v2_connection_t));
if (h2c == NULL) {
ngx_http_close_connection(c);
diff -r 87d2ea860f38 -r 1532a8fca7b2 src/http/v2/ngx_http_v2_module.c
--- a/src/http/v2/ngx_http_v2_module.c Mon Sep 10 18:57:39 2018 +0300
+++ b/src/http/v2/ngx_http_v2_module.c Mon Sep 07 20:03:44 2020 +0800
@@ -334,6 +334,10 @@
ngx_http_v2_main_conf_t *h2mcf = conf;
ngx_conf_init_size_value(h2mcf->recv_buffer_size, 256 * 1024);
+ h2mcf->recv_buffer = ngx_pcalloc(cf->pool, h2mcf->recv_buffer_size);
+ if (h2mcf->recv_buffer == NULL) {
+ return NGX_CONF_ERROR;
+ }
return NGX_CONF_OK;
}
More information about the nginx-devel
mailing list