Welcome! Log In Create A New Profile

Advanced

[nginx] Request body: optimized handling of small chunks.

Maxim Dounin
August 05, 2020 11:44PM
details: https://hg.nginx.org/nginx/rev/f5a2af0e7079
branches:
changeset: 7693:f5a2af0e7079
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Aug 06 05:02:57 2020 +0300
description:
Request body: optimized handling of small chunks.

If there is a previous buffer, copy small chunks into it instead of
allocating additional buffer.

diffstat:

src/http/ngx_http_request_body.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)

diffs (42 lines):

diff -r 0f7f1a509113 -r f5a2af0e7079 src/http/ngx_http_request_body.c
--- a/src/http/ngx_http_request_body.c Thu Aug 06 05:02:55 2020 +0300
+++ b/src/http/ngx_http_request_body.c Thu Aug 06 05:02:57 2020 +0300
@@ -1027,6 +1027,8 @@ ngx_http_request_body_chunked_filter(ngx

for (cl = in; cl; cl = cl->next) {

+ b = NULL;
+
for ( ;; ) {

ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0,
@@ -1061,6 +1063,29 @@ ngx_http_request_body_chunked_filter(ngx
return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
}

+ if (b
+ && rb->chunked->size <= 128
+ && cl->buf->last - cl->buf->pos >= rb->chunked->size)
+ {
+ r->headers_in.content_length_n += rb->chunked->size;
+
+ if (rb->chunked->size < 8) {
+
+ while (rb->chunked->size) {
+ *b->last++ = *cl->buf->pos++;
+ rb->chunked->size--;
+ }
+
+ } else {
+ ngx_memmove(b->last, cl->buf->pos, rb->chunked->size);
+ b->last += rb->chunked->size;
+ cl->buf->pos += rb->chunked->size;
+ rb->chunked->size = 0;
+ }
+
+ continue;
+ }
+
tl = ngx_chain_get_free_buf(r->pool, &rb->free);
if (tl == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Request body: optimized handling of small chunks.

Maxim Dounin 191 August 05, 2020 11:44PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 71
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready