Caching needed, but makes kitty sad.

Jessica Hawkwell root at varusonline.com
Sat Jun 20 21:20:24 MSD 2009


Arvind Jayaprakash wrote:
> On Jun 12, Jessica Hawkwell wrote:
>   
>> Hai peeps! =^_^=
>>
>> I have a system that stores a lot of images in a database.  What I'm 
>> running is an avatar site, and there are times when it seems everyone has 
>> decided to update their avatars all at the same time.  With nearly 70% of 
>> our non-static image requests being little 32x32 icons for all the items 
>> that can be equipped, mass amounts of icon loads sometimes makes the site 
>> run about a second or two slower than usual.
>>
>> I came to the obvious conclusion the best way to resolve this is to have 
>> nginx cache these little item icons.  Unfortunately, I have tried and 
>> failed to make this happen.  I think having nginx caching them would 
>> greatly improve performance since it would not have to access the back-end 
>> FastCGI servers to get the icons, they'd be local (which is always faster, 
>> so yay).  Below is the server block in question, I apologize in advance if 
>> the regex for /avatars/ causes any negative side effects.
>>
>>        server {
>>                listen 80;
>>                server_name varusonline.com;
>>                root /usr/local/www/varusonline.com/;
>>
>>                location / {
>>                        gzip on;
>>                        gzip_types image/png image/gif image/jpeg text/plain 
>> text/javascript text/css;
>>                }
>>
>>                location /avatars/ {
>>                        rewrite 
>> ^/avatars/([-0-9]+)(|_head|_full)\.(png|gif|jpg)(\?(.*))?$ 
>> /avatar.php?u=$1&show=$2&format=$3&$5 last;
>>                }
>>
>>                location /domains/ {
>>                        rewrite 
>> ^/domains/([a-z]+)/([-0-9a-z.,]+)/([-0-9a-z.]+)?(\?(.*))?$ 
>> /domains.php?$1=$2&item=$3&$5 last;
>>                }
>>
>>                location /img_view/ {
>>                        set $img $document_uri;
>>                        rewrite ^/img_view/(avi|bod)-([0-9]+).png$ 
>> /img_view.php?subset=$1&img_id=$2 last;
>>                        set $droot /usr/local/www/caches/img_view/;
>>
>>                        proxy_store $droot${img};
>>
>>                        if (!-f $droot${img}) {
>>                                fastcgi_pass fcgi;
>>                        }
>>
>>                        if (-f $droot${img}) {
>>                                expires max;
>>                        }
>>                }
>>
>>                location ~ \.php$ {
>>                        fastcgi_pass fcgi;
>>                }
>>        }
>>
>> Through all of this with everything I have tried, the cache folder is still 
>> empty, which makes this little kitty sad.  Is there a way to make nginx 
>> cache images from just that one script?
>>     
>
> Is your php script returning the appropriate cache control headers?
>
>
>   
The PHP script returns a 60 second cache control header, which seems to 
have no effect on nginx.  I've got a solution in place for the item 
icons (FastCGI data store).  The big one now is having nginx cache the 
actual avatars, which proves to be difficult.

-------------------
Owner, Varus Online
http://varusonline.com/
Member Support: 530 383 3059

--- Useful Links ---
Frequently Asked Questions: http://varusonline.com/forum/viewtopic.php?t=461
Newbie Guide: http://varusonline.com/forum/viewtopic.php?t=7430
Useful Tips: http://varusonline.com/forum/viewtopic.php?t=6803

When taking over the world, use zombie squirrels.
Nobody will ever see it coming.  >.>






More information about the nginx mailing list