Browse Source

[multiple] perf: reuse large buffers w/ backend

personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
3d8d56d8de
  1. 10
      src/gw_backend.c
  2. 4
      src/mod_cgi.c
  3. 3
      src/mod_fastcgi.c
  4. 2
      src/mod_proxy.c
  5. 2
      src/mod_scgi.c
  6. 2
      src/mod_sockproxy.c
  7. 2
      src/mod_wstunnel.c

10
src/gw_backend.c

@ -1067,7 +1067,7 @@ static gw_handler_ctx * handler_ctx_init(size_t sz) {
hctx->fde_ndx = -1;
/*hctx->response = buffer_init();*//*(allocated when needed)*/
/*hctx->response = chunk_buffer_acquire();*//*(allocated when needed)*/
hctx->request_id = 0;
hctx->gw_mode = GW_RESPONDER;
@ -1089,7 +1089,7 @@ static gw_handler_ctx * handler_ctx_init(size_t sz) {
static void handler_ctx_free(gw_handler_ctx *hctx) {
/* caller MUST have called gw_backend_close(srv, hctx) if necessary */
if (hctx->handler_ctx_free) hctx->handler_ctx_free(hctx);
buffer_free(hctx->response);
chunk_buffer_release(hctx->response);
chunkqueue_free(hctx->rb);
chunkqueue_free(hctx->wb);
@ -1113,7 +1113,7 @@ static void handler_ctx_clear(gw_handler_ctx *hctx) {
if (hctx->wb) chunkqueue_reset(hctx->wb);
hctx->wb_reqlen = 0;
buffer_reset(hctx->response);
if (hctx->response) buffer_string_set_length(hctx->response, 0);
hctx->fd = -1;
hctx->fde_ndx = -1;
@ -2040,13 +2040,13 @@ static handler_t gw_recv_response(server *srv, gw_handler_ctx *hctx) {
gw_host *host = hctx->host;
/*(XXX: make this a configurable flag for other protocols)*/
buffer *b = hctx->opts.backend == BACKEND_FASTCGI
? buffer_init()
? chunk_buffer_acquire()
: hctx->response;
handler_t rc = http_response_read(srv, hctx->remote_conn, &hctx->opts,
b, hctx->fd, &hctx->fde_ndx);
if (b != hctx->response) buffer_free(b);
if (b != hctx->response) chunk_buffer_release(b);
switch (rc) {
default:

4
src/mod_cgi.c

@ -91,7 +91,7 @@ static handler_ctx * cgi_handler_ctx_init(void) {
force_assert(hctx);
hctx->response = buffer_init();
hctx->response = chunk_buffer_acquire();
hctx->fd = -1;
hctx->fdtocgi = -1;
@ -99,7 +99,7 @@ static handler_ctx * cgi_handler_ctx_init(void) {
}
static void cgi_handler_ctx_free(handler_ctx *hctx) {
buffer_free(hctx->response);
chunk_buffer_release(hctx->response);
free(hctx);
}

3
src/mod_fastcgi.c

@ -400,7 +400,8 @@ static handler_t fcgi_recv_parse(server *srv, connection *con, struct http_respo
}
if (0 == con->file_started) {
if (!hctx->response) {
hctx->response = buffer_init_buffer(hdrs);
hctx->response = chunk_buffer_acquire();
buffer_copy_buffer(hctx->response, hdrs);
}
}
else if (hctx->gw_mode == GW_AUTHORIZER &&

2
src/mod_proxy.c

@ -984,7 +984,7 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p
if (con->mode == p->id) {
handler_ctx *hctx = con->plugin_ctx[p->id];
hctx->gw.create_env = proxy_create_env;
hctx->gw.response = buffer_init();
hctx->gw.response = chunk_buffer_acquire();
hctx->gw.opts.backend = BACKEND_PROXY;
hctx->gw.opts.pdata = hctx;
hctx->gw.opts.headers = proxy_response_headers;

2
src/mod_scgi.c

@ -285,7 +285,7 @@ static handler_t scgi_check_extension(server *srv, connection *con, void *p_d, i
handler_ctx *hctx = con->plugin_ctx[p->id];
hctx->opts.backend = BACKEND_SCGI;
hctx->create_env = scgi_create_env;
hctx->response = buffer_init();
hctx->response = chunk_buffer_acquire();
}
return HANDLER_GO_ON;

2
src/mod_sockproxy.c

@ -152,7 +152,7 @@ static handler_t mod_sockproxy_connection_accept(server *srv, connection *con, v
handler_ctx *hctx = con->plugin_ctx[p->id];
hctx->opts.backend = BACKEND_PROXY;
hctx->create_env = sockproxy_create_env_connect;
hctx->response = buffer_init();
hctx->response = chunk_buffer_acquire();
con->http_status = -1; /*(skip HTTP processing)*/
}

2
src/mod_wstunnel.c

@ -522,7 +522,7 @@ static handler_t wstunnel_handler_setup (server *srv, connection *con, plugin_da
hctx->gw.create_env = wstunnel_create_env;
hctx->gw.handler_ctx_free = wstunnel_handler_ctx_free;
hctx->gw.backend_error = wstunnel_backend_error;
hctx->gw.response = buffer_init();
hctx->gw.response = chunk_buffer_acquire();
hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_INIT;
hctx->frame.ctl.siz = 0;

Loading…
Cancel
Save