freeing buffers after sending them

Valentin V. Bartenev vbart at nginx.com
Wed Oct 12 11:30:48 UTC 2016


On Wednesday 12 October 2016 13:22:08 George . wrote:
> Hi all,
> 
> What do you think about freeing buffers after being sent by send_chain?
> Because we have a special case were we use 4 megabyte buffer instead of
> nginx default 8 * 8 K and we found that these buffers are actually freed
> after request had been finished, so if there hundreds of slow downstream
> connection nginx will eat a lot of RAM.
> 
> I'm just curious if I explicitly return already consumed buffer with
> ngx_pfree  will affect something (our bunch of tests shows at least there
> is not crash or unexpected behaviour)
> 


Buffers are not allocated from "c->pool", so 
the code below does nothing except wasting CPU.

And this is the only reason, why the patch doesn't
break everything.

  wbr, Valentin V. Bartenev



> 
> @@ -284,6 +284,13 @@ ngx_http_write_filter(ngx_http_request_t *r,
> ngx_chain_t *in)
> 
>      chain = c->send_chain(c, r->out, limit);
> 
> +    /* free buffs that are already sent */
> +    for (cl = r->out; cl; /* void */) {
> +        ln = cl;
> +        cl = cl->next;
> +        ngx_pfree(c->pool, ln->buf);
> +    }
> +
>      ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
>                     "http write filter %p", chain)



More information about the nginx-devel mailing list