# Nginx VS Nginx + Varnish

**URL:** <https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564>\
**Category:** NGINX\
**Created:** [October 9, 2008, 10:50pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564 "2008-10-09T22:50:07Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 9, 2008, 10:50pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/1 "2008-10-09T22:50:07Z")

</div>

Hey,

Do you think it’s a good idea to add Varnish to Nginx to serve static  
files?

I’m running a dedicated server with 2GB RAM and a pentium dual core  
E2180 for static files.

I’m only using Nginx 0.6.32 on Centos 5/linux 2.6.24: no database, no  
php, no gzip mod…

Nginx sends 60 images/seconde (max 100 images/sec) among 3.200.000 jpeg  
images (one image = 5-10kB).

Thanks in advance!

## My Nginx file :

user nginx nginx;  
worker\_processes 4;

events  
{  
worker\_connections 1024;  
}

http  
{  
include mime.types;  
default\_type application/octet-stream;

access\_log off;

sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;

client\_body\_timeout 5;  
client\_header\_timeout 5;  
keepalive\_timeout 5 5;  
send\_timeout 5;

gzip off;

server  
{  
listen 80;

```
     root /home/www;

     expires 90d;

     # CSS & Javascript files configuration
     location ~* ^.+.(css|js)$
        {
           gzip_static on;
           gzip_http_version 1.1;
           gzip_proxied off;
           gzip_min_length 0;
           gzip_disable "MSIE [1-6]\.";
           gzip_vary off;
        }
  }

```

}

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 2:04am UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/2 "2008-10-10T02:04:29Z")

</div>

From my experience, 60 small static files / second used 2% cpu on a  
OS X Xeon Server. Are you suspecting that your server is being limited  
in some way ?

Cheers

Dave

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 9:58am UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/3 "2008-10-10T09:58:55Z")

</div>

I think you should increase this, as you have more CPU and also you are  
using 4 workers. Try to set this at lets say “worker\_connections  
2048;”. It might work.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/4 "2008-10-10T14:38:03Z")

</div>

Compression, gzip. You should try it, maybe for jpeg is not actually  
worth it… Hmm, try what can i say.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/5 "2008-10-10T14:03:50Z")

</div>

Dave C. wrote:

> From my experience, 60 small static files / second used 2% cpu on a  
> OS X Xeon Server. Are you suspecting that your server is being limited  
> in some way ?

Right now, I don’t have problems.

I just want to optimize my web server for the best result (it takes  
400-500ms to serve a 5kB image).

[http://img29.picoodle.com/img/img29/3/10/10/f\_monitoring0m\_f2441cf.png](http://img29.picoodle.com/img/img29/3/10/10/f_monitoring0m_f2441cf.png)

[http://img33.picoodle.com/img/img33/3/10/10/f\_monitoring0m\_bb25457.png](http://img33.picoodle.com/img/img33/3/10/10/f_monitoring0m_bb25457.png)

Those images show my web site performance (from [pingdom.com](http://pingdom.com) and  
[site-perf.com](http://site-perf.com)).

I’m wondering if there is something to reduce those timings…

Thanks.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 3:01pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/6 "2008-10-10T15:01:13Z")

</div>

Have you actually tried putting varnish/ncache in place and benchmarking  
the before/after results? As I’ve found with all server set-ups: YMMV.

Gen G. wrote:

> 400-500ms to serve a 5kB image).
> 
> Thanks.
> 
> Attachments:  
> [http://www.ruby-forum.com/attachment/2797/monitoring00.png](http://www.ruby-forum.com/attachment/2797/monitoring00.png)

–

_Phillip B Oldham_  
The Activity People  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

_Policies_

This e-mail and its attachments are intended for the above named  
recipient(s) only and may be confidential. If they have come to you in  
error, please reply to this e-mail and highlight the error. No action  
should be taken regarding content, nor must you copy or show them to  
anyone.

This e-mail has been created in the knowledge that Internet e-mail is  
not a 100% secure communications medium, and we have taken steps to  
ensure that this e-mail and attachments are free from any virus. We must  
advise that in keeping with good computing practice the recipient should  
ensure they are completely virus free, and that you understand and  
observe the lack of security when e-mailing us.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/7 "2008-10-10T15:44:51Z")

</div>

> Compression, gzip. You should try it, maybe for jpeg is not actually  
> worth it… Hmm, try what can i say.

I already use static gzip on css and javascript file.  
And for jpeg, it is not worth it, indeed.

Moreover, if you look at the monitoring image (in attachment), the loss  
of time is while sending request and receiving http-headers from server  
(25% of the total time).

I was wondering if we can reduce it?

PS: watch the last line of the image in attachment: it’s the javascript  
from Google Analytics, and the timing is really, really short!

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/8 "2008-10-10T15:50:34Z")

</div>

> Have you actually tried putting varnish/ncache in place and benchmarking  
> the before/after results? As I’ve found with all server set-ups: YMMV.

I’m trying to get tips and advices from experienced users like you  
before diving in the benchmarking work.

And don’t worry, I will share my varnish+nginx benchmarks and  
experiences at the end… ^\_-

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 10, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/9 "2008-10-10T16:15:19Z")

</div>

On Fri, Oct 10, 2008 at 02:03:50PM +0200, Gen G. wrote:

> [http://img29.picoodle.com/img/img29/3/10/10/f\_monitoring0m\_f2441cf.png](http://img29.picoodle.com/img/img29/3/10/10/f_monitoring0m_f2441cf.png)
> 
> [http://img33.picoodle.com/img/img33/3/10/10/f\_monitoring0m\_bb25457.png](http://img33.picoodle.com/img/img33/3/10/10/f_monitoring0m_bb25457.png)
> 
> Those images show my web site performance (from [pingdom.com](http://pingdom.com) and  
> [site-perf.com](http://site-perf.com)).
> 
> I’m wondering if there is something to reduce those timings…

What I see on these images is that TCP connection times are about  
100ms-500ms. These values depend on client speed connection and kernel  
internel processing only. User-level applications can not affect on it.  
Thus, if you have 100-500ms TCP round trip, then small data chunks  
will be processed in the same time, even if nginx will not block on disk  
reads.

As to disk blocking, you have 30G images and 2G memory. nginx is  
probably  
blocking on disk - see “wa” percents in top. You may try to increase  
worker\_processes to 10-20.

As to using varnish+nginx, I think varnish will not help in this case.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 11, 2008, 1:30am UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/10 "2008-10-11T01:30:30Z")

</div>

oh yes I forgot, I have confronted one of the developers on #varnish  
with my results. The said developer stated that nginx currently does  
have the edge performance wise, even though they have the “superior”  
architecture.

-Victor

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 11, 2008, 1:26am UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/11 "2008-10-11T01:26:04Z")

</div>

I have tried both approaches. nginx on ZFS (arc caching) is superior in  
performance to varnish in front of nginx. I can easily choke varnish  
with many requests.

[http://letsgetdugg.com/view/Nginx\_hidden\_performance\_option](http://letsgetdugg.com/view/Nginx_hidden_performance_option)

works very well for us in our production environment.

-Victor

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 12, 2008, 11:33am UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/12 "2008-10-12T11:33:13Z")

</div>

On Sat, Oct 11, 2008 at 7:26 AM, Victor I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

On Sat, Oct 11, 2008 at 7:30 AM, Victor I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> oh yes I forgot, I have confronted one of the developers on #varnish  
> with my results. The said developer stated that nginx currently does  
> have the edge performance wise, even though they have the “superior”  
> architecture.

and would this be on solaris only? or does it apply to other platforms  
as well?

-jf

–  
In the meantime, here is your PSA:  
“It’s so hard to write a graphics driver that open-sourcing it would not  
help.”  
– Andrew Fear, Software Product Manager, NVIDIA Corporation

> **[An Interview With Linus Torvalds: Linux and Git - Part 1](https://www.tag1.com/blog/interview-linus-torvalds-linux-and-git/?utm_source=kerneltrap.org&utm_medium=redirect)**
>
> An Interview With Linus Torvalds: Linux and Git - Part 1 30 Years Of Linux Jeremy Andrews - Founding Partner/CEO April 28, 2021 Share /\* Hide More...

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 12, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/13 "2008-10-12T20:22:39Z")

</div>

don’t know, benchmark and find out. I have seen nginx edge out varnish  
in performance on solaris and freebsd.

-Victor

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 14, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/14 "2008-10-14T20:24:14Z")

</div>

Serving thumbnails efficiently is not easy. See  
[YouTube&nbsp;Architecture - High Scalability -](http://highscalability.com/youtube-architecture) (scroll down to  
‘Serving thumbnails’).

You’re spending a good chunk of time doing disk seeks. Even if read  
time is 0, average seek time is about 10ms. So you’re looking at a  
limit of 100 images/sec. This is the ideal case. Add read time + TCP  
delays + other delays, you’re looking 50-60 images/sec.

Serve off memory, try using memcache.

-praveen

On Fri, Oct 10, 2008 at 5:03 AM, Gen G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Attachments:  
> [http://www.ruby-forum.com/attachment/2797/monitoring00.png](http://www.ruby-forum.com/attachment/2797/monitoring00.png)
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Praveen

Can you yell “Movie!” in a crowded firestation?

> **[TigerTrail � Artikel & Berita Gaming Indonesia](http://tigertrail.net)**
>
> TigerTrail: berita, review, panduan, dan opini seputar dunia gaming. Update rutin tentang game PC, konsol, dan mobile untuk pemain Indonesia.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 14, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/15 "2008-10-14T21:40:37Z")

</div>

Yes. There is caching at the OS level too, which needs to be tuned  
(like cache sizes, inode vs content etc). I did not look at your  
benchmarks, but was commenting more on Gen’s post. In the graphs he’s  
given, the latency between connect and sending first byte (the green  
part) is high, which might explain disk seek/read.

-p

On Tue, Oct 14, 2008 at 11:36 AM, Victor I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> umm, linux file cache? solaris ZFS ARC cache? who says you will be doing  
> disk seeks for frequently used files?
> 
> seems like varnish is clashing with what is already in place.
> 
> ## -Victor
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Praveen

Can you yell “Movie!” in a crowded firestation?

> **[TigerTrail � Artikel & Berita Gaming Indonesia](http://tigertrail.net)**
>
> TigerTrail: berita, review, panduan, dan opini seputar dunia gaming. Update rutin tentang game PC, konsol, dan mobile untuk pemain Indonesia.

---

<div class="post-metadata">

**Author:** ![gennix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@gennix](https://www.ruby-forum.com/u/gennix)\
**Post date:** [October 14, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/nginx-vs-nginx-varnish/150564/16 "2008-10-14T20:36:17Z")

</div>

umm, linux file cache? solaris ZFS ARC cache? who says you will be doing  
disk seeks for frequently used files?

seems like varnish is clashing with what is already in place.

-Victor
