Browse Source

[multiple] add back-pressure gw data pump (fixes #3033)

When server.stream-request-body = 0 (the default), the entire request
body is collected before engaging the backend.  For backends which
require data framing, this could lead to growth in memory use as large
requests were framed all at once.

Prefer to retain large request bodies in temporary files on disk and
frame in portions as write queue to backend drains below a threshold.

x-ref:
  "Memory Growth with PUT and full buffered streams"
  https://redmine.lighttpd.net/issues/3033
master
Glenn Strauss 2 months ago
parent
commit
f2b33e7520
2 changed files with 12 additions and 3 deletions
  1. +10
    -2
      src/gw_backend.c
  2. +2
    -1
      src/mod_fastcgi.c

+ 10
- 2
src/gw_backend.c View File

@ -1963,8 +1963,15 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
return HANDLER_ERROR;
}
}
else if (hctx->wb.bytes_out > bytes_out)
else if (hctx->wb.bytes_out > bytes_out) {
hctx->proc->last_used = log_epoch_secs;
if (hctx->stdin_append
&& chunkqueue_length(&hctx->wb) < 65536 - 16384
&& !chunkqueue_is_empty(&r->reqbody_queue)) {
handler_t rc = hctx->stdin_append(hctx);
if (HANDLER_GO_ON != rc) return rc;
}
}
}
if (hctx->wb.bytes_out == hctx->wb_reqlen) {
@ -2098,7 +2105,8 @@ handler_t gw_handle_subrequest(request_st * const r, void *p_d) {
if ((0 != hctx->wb.bytes_in || -1 == hctx->wb_reqlen)
&& !chunkqueue_is_empty(&r->reqbody_queue)) {
if (hctx->stdin_append) {
if (hctx->stdin_append
&& chunkqueue_length(&hctx->wb) < 65536 - 16384) {
handler_t rca = hctx->stdin_append(hctx);
if (HANDLER_GO_ON != rca) return rca;
}


+ 2
- 1
src/mod_fastcgi.c View File

@ -221,8 +221,9 @@ static handler_t fcgi_stdin_append(handler_ctx *hctx) {
FCGI_Header header;
chunkqueue * const req_cq = &hctx->r->reqbody_queue;
off_t offset, weWant;
const off_t req_cqlen = chunkqueue_length(req_cq);
off_t req_cqlen = chunkqueue_length(req_cq);
int request_id = hctx->request_id;
if (req_cqlen > MAX_WRITE_LIMIT) req_cqlen = MAX_WRITE_LIMIT;
/* something to send ? */
for (offset = 0; offset != req_cqlen; offset += weWant) {


Loading…
Cancel
Save