# Ngix Performace as a Reverse Proxy

**URL:** <https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999>\
**Category:** NGINX\
**Created:** [October 26, 2012, 6:37am UTC](https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999 "2012-10-26T06:37:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 26, 2012, 6:37am UTC](https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999/1 "2012-10-26T06:37:33Z")

</div>

Hi,

We have been doing some testing with Nginx as a reverse proxy. We have  
been comparing it to a number of solutions which it easily beats, like  
IIS and Apache with mod\_proxy etc. However, as an experiment we have  
been comparing it to an adapted NIO server written in Java. This seems  
to be out performing Nginx in the reverse proxy role by a factor of 3  
times. We are convinced our configuration is wrong. Both run on the same  
box (at different times) with the same sysctl settings (see below). We  
also saw some spikes, up to 3 seconds per request at times, and some at  
10 over a 1 million request test of 1000 concurrent clients.

We are using a fairly straight forward configuration for Nginx. Since we  
have two processors on the box we tried worker\_processes of 4 with  
worker\_connections of 6000, then we tried worker\_processes of 40 with  
worker\_connections of 5000. No change. We need to be able to support  
responsive Ajax requests with strategies like HTTP streaming and long  
polling in our setup.

Any ideas what we can do to boost our throughput and latency?

[root@dc1dmzngx02 apachebench]# uname -a  
Linux dc1dmzngx02 2.6.32-220.13.1.el6.x86\_64 #1 SMP Tue Apr 17 23:56:34  
BST 2012 x86\_64 x86\_64 x86\_64 GNU/Linux

[root@dc1dmzngx02 apachebench]# cat /etc/sysctl.conf

# Kernel sysctl configuration file for Red Hat Linux

# 

# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and

# sysctl.conf(5) for more details.

# High perf config

net.core.somaxconn = 12048  
net.core.rmem\_default = 262144  
net.core.wmem\_default = 262144  
net.core.rmem\_max = 16777216  
net.core.wmem\_max = 16777216  
net.ipv4.tcp\_rmem = 4096 4096 16777216  
net.ipv4.tcp\_wmem = 4096 4096 16777216  
net.ipv4.tcp\_mem = 786432 2097152 3145728  
net.ipv4.tcp\_max\_syn\_backlog = 16384  
net.core.netdev\_max\_backlog = 20000  
net.ipv4.tcp\_fin\_timeout = 15  
net.ipv4.tcp\_max\_syn\_backlog = 16384  
net.ipv4.tcp\_tw\_reuse = 1  
net.ipv4.tcp\_tw\_recycle = 1  
net.ipv4.tcp\_max\_orphans = 131072

# Controls IP packet forwarding

net.ipv4.ip\_forward = 0

# Controls source route verification

net.ipv4.conf.default.rp\_filter = 1

# Do not accept source routing

net.ipv4.conf.default.accept\_source\_route = 0

# Controls the System Request debugging functionality of the kernel

kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.

# Useful for debugging multi-threaded applications.

kernel.core\_uses\_pid = 1

# Controls the use of TCP syncookies

net.ipv4.tcp\_syncookies = 1

# Disable netfilter on bridges.

net.bridge.bridge-nf-call-ip6tables = 0  
net.bridge.bridge-nf-call-iptables = 0  
net.bridge.bridge-nf-call-arptables = 0

# Controls the maximum size of a message, in bytes

kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue

kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes

kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages

kernel.shmall = 4294967296

Thanks,  
Niall

---

<div class="post-metadata">

**Author:** ![Niall\_GallagherSY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a5b964/32.png) [@Niall\_GallagherSY](https://www.ruby-forum.com/u/Niall_GallagherSY)\
**Post date:** [October 26, 2012, 2:05pm UTC](https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999/2 "2012-10-26T14:05:03Z")

</div>

On 26 Oct2012, at 08:36 , Niall Gallagher - Yieldbroker  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> We have been doing some testing with Nginx as a reverse proxy. We have been  
> comparing it to a number of solutions which it easily beats, like IIS and Apache  
> with mod\_proxy etc. However, as an experiment we have been comparing it to an  
> adapted NIO server written in Java. This seems to be out performing Nginx in the  
> reverse proxy role by a factor of 3 times. We are convinced our configuration is  
> wrong. Both run on the same box (at different times) with the same sysctl settings  
> (see below). We also saw some spikes, up to 3 seconds per request at times, and  
> some at 10 over a 1 million request test of 1000 concurrent clients.
> 
> We are using a fairly straight forward configuration for Nginx. Since we have  
> two processors on the box we tried worker\_processes of 4 with worker\_connections  
> of 6000, then we tried worker\_processes of 40 with worker\_connections of 5000. No  
> change. We need to be able to support responsive Ajax requests with strategies  
> like HTTP streaming and long polling in our setup.
> 
> Any ideas what we can do to boost our throughput and latency?

Buffers. nginx should not write/read anything to/from disk while proxing  
for maximum performance. Check your average request and response sizes  
and tune buffers sizes accordingly (look at proxy\_buffers,  
proxy\_buffer\_size, proxy\_max\_temp\_file\_size documentation).

---

<div class="post-metadata">

**Author:** ![Niall\_GallagherSY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a5b964/32.png) [@Niall\_GallagherSY](https://www.ruby-forum.com/u/Niall_GallagherSY)\
**Post date:** [October 28, 2012, 11:26pm UTC](https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999/3 "2012-10-28T23:26:46Z")

</div>

According to documentation for proxy\_buffering

“For Comet applications based on long-polling it is important to set  
proxy\_buffering to off, otherwise the asynchronous response is buffered  
and the Comet does not work.”

I have tried the following and am not getting better results, however  
its still being outperformed by the Java HTTP proxy by about 10% - 15%.

worker\_processes 2;  
worker\_cpu\_affinity 01 10;  
worker\_rlimit\_nofile 20000;

However spikes of up to 20 seconds are still frequent under high load.

---

<div class="post-metadata">

**Author:** ![Niall\_GallagherSY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a5b964/32.png) [@Niall\_GallagherSY](https://www.ruby-forum.com/u/Niall_GallagherSY)\
**Post date:** [October 29, 2012, 10:12am UTC](https://www.ruby-forum.com/t/ngix-performace-as-a-reverse-proxy/223999/4 "2012-10-29T10:12:54Z")

</div>

On 29 Oct2012, at 02:26 , Niall Gallagher - Yieldbroker  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> According to documentation for proxy\_buffering
> 
> “For Comet applications based on long-polling it is important to set  
> proxy\_buffering to off, otherwise the asynchronous response is buffered and the  
> Comet does not work.”  
> I have tried the following and am not getting better results, however its still  
> being outperformed by the Java HTTP proxy by about 10% - 15%.

Try to set  
postpone\_output 0;
