Re: freeing buffers after sending them

2016-10-12 Thread Valentin V. Bartenev
On Wednesday 12 October 2016 15:05:48 George . wrote:
> Hi Valentin,
> 
> Than you for your fast and correct reply.
> 
> Yes, you are right, it was oversight that r->out->buf if taken from
> pipe->pool, which is actually  r->pool.
> What if we pfree this bufs from  r->pool? Who holds the reference after
> sending these buffers (except may be in NGX_THREADS version)?
> 
[..]

These buffers are reused for continuing sending response.

  wbr, Valentin V. Bartenev

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: freeing buffers after sending them

2016-10-12 Thread George .
Hi Valentin,

Than you for your fast and correct reply.

Yes, you are right, it was oversight that r->out->buf if taken from
pipe->pool, which is actually  r->pool.
What if we pfree this bufs from  r->pool? Who holds the reference after
sending these buffers (except may be in NGX_THREADS version)?


On Wed, Oct 12, 2016 at 2:30 PM, Valentin V. Bartenev 
wrote:

> 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)
>
> ___
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: freeing buffers after sending them

2016-10-12 Thread Valentin V. Bartenev
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)

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


freeing buffers after sending them

2016-10-12 Thread George .
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)


@@ -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)
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel