# Nginx & long poll: Best practices to reduce memory and bandwidth footprint

**URL:** <https://www.ruby-forum.com/t/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint/213478>\
**Category:** NGINX\
**Created:** [November 3, 2011, 10:18am UTC](https://www.ruby-forum.com/t/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint/213478 "2011-11-03T10:18:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 3, 2011, 10:18am UTC](https://www.ruby-forum.com/t/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint/213478/1 "2011-11-03T10:18:48Z")

</div>

Can someone please answer this question on [serverfault.com](http://serverfault.com)?

> <https://serverfault.com/questions/327301/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint>

-Quintin

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [November 4, 2011, 4:16am UTC](https://www.ruby-forum.com/t/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint/213478/2 "2011-11-04T04:16:14Z")

</div>

## Posting the contents inline. Can someone review this?

I use nginx in this mode for [BOSH](http://xmpp.org/extensions/xep-0206.html) and chat clients along with gzip.

location ~\* /http-bind/ {  
proxy\_buffering off;  
keepalive\_timeout 55;  
access\_log off;  
tcp\_nodelay on;  
proxy\_pass [http://x.x.x.x:1111](http://x.x.x.x:1111);  
}

Is this the best approach to **managing long polling** in nginx.

I also use just one worker process for altogether for web & chat (single  
CPU). Is that fine?

-Quintin

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [November 4, 2011, 1:51pm UTC](https://www.ruby-forum.com/t/nginx-long-poll-best-practices-to-reduce-memory-and-bandwidth-footprint/213478/3 "2011-11-04T13:51:51Z")

</div>

On 4 November 2011 05:15, Quintin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> proxy_pass http://x.x.x.x:1111;
> 
> ```
> 
> }
> 
> Is this the best approach to **managing long polling** in nginx.
> 
> I also use just one worker process for altogether for web & chat (single  
> CPU). Is that fine?

It looks fine. Use that until you have a performance problem, and then  
gather evidence identifying your bottleneck before changing anything.

You might as well start with n worker processes though, where n is the  
number of cores on your CPU. Give yourself a few thousand  
worker\_connections, because you’ll have a relatively large number of  
relatively idle sockets.

Long-polling is very simple and nginx is good at it. I would advise not  
to  
try to fix anything until you find a real problem.

Thomas
