Proxy buffering

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

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 D.
http://nginx.org/en/donation.html

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

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:

On Wed, Dec 18, 2013 at 07:21:13PM +0400, Maxim D. 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

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:

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 D.
http://nginx.org/

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 D.
http://nginx.org/

Great news! Thanks!

Posted at Nginx Forum:

Maxim D. Wrote:

Yes, it’s still in the list.


Maxim D.
http://nginx.org/


nginx mailing list
[email protected]
nginx Info Page

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:

On Fri, May 09, 2014 at 08:07:51AM +0400, Maxim D. 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

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