bad performance with nginx cache

Franchoze Eric franchoze at
Fri Aug 27 14:10:50 MSD 2010


On these week I tried speed up nginx work with turning on cache for graphics files specified by extentions (jpg, png, bmp, etc.) in config file. On system without any load client (web browser) loaded pages for the same time - with cache or without cache. But after installing same configuration on real server I realized the following issue:

1. Nginx can not speed up more then 150Mbit/s is cache is no hard drive. Can speed up to 200Mbit/s if cache is on tmpfs.
2. Load time from client begins to be 2-3 times lager then without cache if traffic is about 150Mbit/s. This happens for all files even if they were not specified in nginx.conf.

Does anybody have successful nginx cache run with throughput 500-600Mbit/s? Does it speed up or lower end client page load speed?

My configuration is SMP machine with nginx worker per cpu.
    proxy_cache_path  /var/www/cache2 levels=1:2 keys_zone=my-cache:512m max_size=3000m inactive=10m;
    proxy_temp_path /var/www/cache2/tmp;
    proxy_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
        location  ~*(|||||*\.(jpe?g|gif|png|tif|svg|ico|bmp)$ {
                        proxy_pass http://$host$request_uri;
                        proxy_buffering on;
                        proxy_buffers 256 4k;
                        proxy_buffer_size 4k;
                        proxy_cache_min_uses 1; #minimal requests to put object to cache
                        proxy_cache my-cache;
                        proxy_cache_valid  200 301 302 304 60m; #page ok
                        proxy_cache_valid  404  10m; #server not found

                       log_format cache '***$time_local '
                          '$upstream_cache_status '
                        'Cache-Control: $upstream_http_cache_control '
                        'Expires: $upstream_http_expires '
                        '"$request" ($status) ';

                        access_log /var/log/nginx/cache_nginx_access_limited.log cache;

I would like to hear if there are any weak places in the cache or limitations. So maybe we can speed up it. I'm not yet very familiar with modern cache techniques but maybe we can use libvarnish to increase performance.
I will be also ok if nginx could skip doing caching if time to fetch object from cache is bigger than download it.

Any ideas are welcome.


More information about the nginx-devel mailing list