# Nginx cache is slow

**URL:** <https://www.ruby-forum.com/t/nginx-cache-is-slow/210874>\
**Category:** NGINX\
**Created:** [August 19, 2011, 9:58am UTC](https://www.ruby-forum.com/t/nginx-cache-is-slow/210874 "2011-08-19T09:58:31Z")\
**Posts on this page:** 2\
**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:** [August 19, 2011, 9:58am UTC](https://www.ruby-forum.com/t/nginx-cache-is-slow/210874/1 "2011-08-19T09:58:31Z")

</div>

Nginx 1.1.0

location / {  
uwsgi\_cache tna;  
uwsgi\_cache\_use\_stale error timeout http\_500;  
uwsgi\_cache\_valid any 10m;  
uwsgi\_cache\_key $request\_uri;

include /etc/nginx/params\_uwsgi;  
uwsgi\_intercept\_errors off;  
uwsgi\_pass unix:/tmp/uwsgi-tna.sock;  
}

I made a simple test: $ ab -c 10 -n 10000 http://… on localhost.  
I am sure that the request is sent to uWSGI only once and is then  
cached.  
result: Requests per second: 3712.93 [#/sec] (mean)

Meanwhile, on the same machine and the same nginx for static file  
reaches the result:  
Requests per second: 4826.62 [#/sec] (mean)

How is that static files are faster to 30%! from the cache based on  
static files ?

Posted at Nginx Forum:

> **[Nginx cache is slow](https://forum.nginx.org/read.php?2,214027,214027#msg-214027)**
>
> Nginx 1.1.0 location / { uwsgi\_cache tna; uwsgi\_cache\_use\_stale error timeout http\_500; uwsgi\_cache\_valid any 10m; uwsgi\_cache\_key $request\_uri; include /etc/nginx/params\_uwsgi; uwsgi\_intercept\_errors off; uwsgi\_pass u

---

<div class="post-metadata">

**Author:** ![ddarko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@ddarko](https://www.ruby-forum.com/u/ddarko)\
**Post date:** [August 19, 2011, 10:34am UTC](https://www.ruby-forum.com/t/nginx-cache-is-slow/210874/2 "2011-08-19T10:34:24Z")

</div>

Hello!

On Fri, Aug 19, 2011 at 03:58:09AM -0400, ddarko wrote:

> uwsgi\_pass unix:/tmp/uwsgi-tna.sock;
> 
> How is that static files are faster to 30%! from the cache based on  
> static files ?

Cached response require additional reading of original response  
headers, as well as calculating cache key and parsing the headers  
in question (which may be an issue on cpu-bound servers). So I  
would expect it to be somewhat slower than plain static files.

While 30% looks a bit too many, it certainly depens havily on  
response sizes involved as well as type of a limiting factor (i.e.  
cpu or disk bound). In worst case I would expect cache to be 2x  
slower compared to static files (though it’s unlikely to happen in  
real life).

Maxim D.
