Forum: NGINX Proxy buffering

88222b6555406f8f6ba58b515f36c99f?d=identicon&s=25 Andrew Tynefield (Guest)
on 2013-11-15 05:37
(Received via mailing list)
Hello all,

I've configured nginx as a load balancing proxy for my backend servers.
My
backend is expecting multi-part uploads for large files in small chunks
(5-15mb). The issue I'm encountering, is that I would like for nginx to
just pass the chunked data along to the backend servers and not buffer
the
requests.

Current configuration:

upstream riak-cs {
                server 192.168.1.19:8080;
                server 192.168.1.22:8080;
                #least_conn;
}

server {
        listen 80;
        server_name cs.domain.com *.cs.domain.com;
        location / {
                proxy_pass http://riak-cs;
                proxy_set_header Host $host;
                proxy_connect_timeout 59s;
                proxy_send_timeout   600;
                proxy_read_timeout   600;
                proxy_buffering off;
                proxy_pass_header Server;
                add_header Backend $proxy_host:$proxy_port;
                add_header Upstream-Response-Time
$upstream_response_time;

        }

}

user              nginx;
worker_processes  4;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  4096;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local]
"$request"
'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay     on;
    keepalive_requests 100;
    client_max_body_size 1000M;
    keepalive_timeout  3;
    reset_timedout_connection on;
    underscores_in_headers on;

    include /etc/nginx/conf.d/*.conf;

}


I have tried disabling buffers as shown above, however, when I capture
the
packets on the backend servers, I see that the stream of data doesn't
occur
until after the full body of the upload has completed.

[ jedi ] ~ # nginx -v
nginx version: nginx/1.4.3

If I enabled info error logging, I see:
2013/11/14 22:34:47 [warn] 2698#0: *1 a client request body is buffered
to
a temporary file /var/cache/nginx/client_temp/0000000001, client:
192.168.1.1, server: cs.domain.com, request: "PUT
/huge/Windows7Ultimate.iso?partNumber=1&uploadId=1RjFvAcQTsWmpnIYD7nL7Q==
HTTP/1.1", host: "big.cs.domain.com"

How can I prevent this all together?

Thanks,
Andrew
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-11-15 11:52
(Received via mailing list)
Hello!

On Thu, Nov 14, 2013 at 10:37:03PM -0600, Andrew Tynefield wrote:

> I've configured nginx as a load balancing proxy for my backend servers. My
> backend is expecting multi-part uploads for large files in small chunks
> (5-15mb). The issue I'm encountering, is that I would like for nginx to
> just pass the chunked data along to the backend servers and not buffer the
> requests.

[...]

>                 proxy_buffering off;

[...]

> I have tried disabling buffers as shown above, however, when I capture the
> packets on the backend servers, I see that the stream of data doesn't occur
> until after the full body of the upload has completed.

The proxy_buffering directive disables response buffering, not
request buffering.

As of now, there is no way to prevent request body buffering in
nginx.  It's always fully read by nginx before a request is passed
to an upstream server.  It's basically a part of nginx being a
web accelerator - it handles slow communication with clients by
itself and only asks a backend to process a request when
everything is ready.

Implementing unbuffered uploads is in plans, no ETA though.

--
Maxim Dounin
http://nginx.org/en/donation.html
2974d09ac2541e892966b762aad84943?d=identicon&s=25 Downchuck (Guest)
on 2013-12-18 07:35
(Received via mailing list)
Is there a large technical barrier to implementing this feature? Patches
have been available for some time at: http://yaoweibin.cn/patches/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244680,245610#msg-245610
7422029315159e28058c11bbb0fc2140?d=identicon&s=25 "Pasi Kärkkäinen" <pasik@iki.fi> (Guest)
on 2013-12-18 11:46
(Received via mailing list)
On Wed, Dec 18, 2013 at 01:34:37AM -0500, Downchuck wrote:
> Is there a large technical barrier to implementing this feature? Patches
> have been available for some time at: http://yaoweibin.cn/patches/
>

Hi,

Based on my testing the no_buffer v8 patch works OK with nginx 1.4.x!
http://yaoweibin.cn/patches/nginx-1.4.2-no_buffer-v8.patch

Maxim: Have you taken a look at the no_buffer-v8 patch?

It would be very nice to get this feature upstreamed to nginx..

Thanks,

-- Pasi
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-12-18 16:21
(Received via mailing list)
Hello!

On Wed, Dec 18, 2013 at 12:45:37PM +0200, Pasi Kärkkäinen wrote:

> Maxim: Have you taken a look at the no_buffer-v8 patch?
>
> It would be very nice to get this feature upstreamed to nginx..

While it looks mostly working (some parts seems to be missing
though - e.g., using chunked encoding requires appropriate headers
to be sent to upstream, and HTTP/1.1 used), it seems to introduce
too much code duplication.  It needs to be addressed somehow
before we'll able to commit it.

I'll plan to work on this and related problems at the start of
next year.

--
Maxim Dounin
http://nginx.org/
7422029315159e28058c11bbb0fc2140?d=identicon&s=25 "Pasi Kärkkäinen" <pasik@iki.fi> (Guest)
on 2013-12-19 20:16
(Received via mailing list)
On Wed, Dec 18, 2013 at 07:21:13PM +0400, Maxim Dounin wrote:
> Hello!
>

Hi,

> > http://yaoweibin.cn/patches/nginx-1.4.2-no_buffer-v8.patch
>
OK.

> I'll plan to work on this and related problems at the start of
> next year.
>

That sounds good!

Thanks,

-- Pasi
2974d09ac2541e892966b762aad84943?d=identicon&s=25 JSurf (Guest)
on 2014-05-08 10:45
(Received via mailing list)
> I'll plan to work on this and related problems at the start of
> next year.
>

Hi, is this still somewhere on the priority list ?
The upload_buffer patch attached to this thread does not apply to 1.6.x
without changes

It would be a great addition to this cool server.
When dealing with big file uploads there are a lot of problems to deal
with
if this is not implemented. (client timeout while nginx copies request
to
proxy, session timeouts during uploads in backend server, since he does
not
know a transfer is going on, ...)

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244680,249929#msg-249929
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-05-09 06:08
(Received via mailing list)
Hello!

On Thu, May 08, 2014 at 04:45:18AM -0400, JSurf wrote:

> > I'll plan to work on this and related problems at the start of
> > next year.
> >
>
> Hi, is this still somewhere on the priority list ?

Yes, it's still in the list.

--
Maxim Dounin
http://nginx.org/
2974d09ac2541e892966b762aad84943?d=identicon&s=25 JSurf (Guest)
on 2014-05-09 11:39
(Received via mailing list)
Great news! Thanks!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244680,249983#msg-249983
2974d09ac2541e892966b762aad84943?d=identicon&s=25 sleepingstu (Guest)
on 2014-07-25 09:52
(Received via mailing list)
Maxim Dounin Wrote:
-------------------------------------------------------
> Yes, it's still in the list.
>
> --
> Maxim Dounin
> http://nginx.org/
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx


Hi Maxim,

Am sure you are fed up with people asking but I don't suppose you'd
happen
have a rough ETA of when you might expect this feature to be introduced?

Sounds like this feature would help a lot of people, me included.

Stu

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244680,252035#msg-252035
7422029315159e28058c11bbb0fc2140?d=identicon&s=25 Pasi Kärkkäinen (Guest)
on 2014-10-03 12:12
(Received via mailing list)
On Fri, May 09, 2014 at 08:07:51AM +0400, Maxim Dounin wrote:
> Yes, it's still in the list.
>

Any updates about the no_buffer feature?

Would it make sense to merge the existing no_buffer patch as a baseline,
and then add incremental fixes/enhancements over time?

(http://yaoweibin.cn/patches/nginx-1.4.2-no_buffer-v8.patch)


Thanks,

-- Pasi
7422029315159e28058c11bbb0fc2140?d=identicon&s=25 Pasi Kärkkäinen (Guest)
on 2014-11-25 20:41
(Received via mailing list)
Hello again,

Any thoughts about the proxy no_buffer feature?

Proxy buffering (for uploads) is an actual problem for many nginx proxy
setups,
because uploads are saved to nginx local disk first while processing,
which makes the uploads slow, and in the case of big upload filesizes
also there's the problem of filling the nginx server disks / temp
directories unnecessarily.

The nginx-1.4.2-no_buffer-v8.patch below fixes the problem with nginx
1.4,
but I think you had some comments about the implementation not being
directly suitable for upstreaming to nginx.

Are there plans for different implementation of this no_buffer feature?


Thanks,

-- Pasi
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.