# Using nginx to cache file serving

**URL:** <https://www.ruby-forum.com/t/using-nginx-to-cache-file-serving/237903>\
**Category:** NGINX\
**Created:** [December 5, 2013, 12:00pm UTC](https://www.ruby-forum.com/t/using-nginx-to-cache-file-serving/237903 "2013-12-05T12:00:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 5, 2013, 12:00pm UTC](https://www.ruby-forum.com/t/using-nginx-to-cache-file-serving/237903/1 "2013-12-05T12:00:37Z")

</div>

Hi  
We are using nginx & SATA disks on several of our file servers.However  
after  
hitting 12MBytes/s of port speed (server nic is a 1gbps), the server  
gets  
down to it’s knees. SSH becomes very slow/unresponsive and our users  
complain about slow speeds and dropped connections. Our  
users/downloaders  
have very slow speed (like 512kbits/s) so there are lots of users  
downloading from each server. I thought the problem was from using SATA  
disk  
and the bottleneck was the HDD IO speed.So we ordered a new server with  
SAS  
hdds & RAID0, the performance has been great and our server is serving  
about  
20MBytes/s, (same provider)  
However I’m still not satisfied.  
1.Is there any configuration options I’m missing? I’m using the default  
config.  
2. Both servers rams are fully utilized and the memory is 100% filled,  
When  
I stop nginx the memory is still used up but why? (there is no other  
service  
running on the server)  
If this is the nginx cache, why it’s not emptied when I exit/kill nginx  
processes?  
3. My most important question is, Is it possible/wise that I use the SAS  
server as a rev-proxy/cache to serve the downloads from the SATA server?  
My  
idea is when a user connects to the SAS server to download a file, The  
SAS  
server requests the file from the SATA server(using the internal  
connection  
in datacenter), caches it on it’s fast disk, then serves the file to my  
slow  
downloader. This way the SATA HDD doesn’t have to seek to the file  
location  
each time and since there are lots of downloaders this happens a lot.

Sorry for the long message and thank you for your time  
Mojiz

Posted at Nginx Forum:

> **[using nginx to cache file serving](https://forum.nginx.org/read.php?2,245244,245244#msg-245244)**
>
> Hi We are using nginx & SATA disks on several of our file servers.However after hitting 12MBytes/s of port speed (server nic is a 1gbps), the server gets down to it's knees. SSH becomes very slow/unresponsive and our users complain about slow...

---

<div class="post-metadata">

**Author:** ![mojiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@mojiz](https://www.ruby-forum.com/u/mojiz)\
**Post date:** [December 5, 2013, 12:14pm UTC](https://www.ruby-forum.com/t/using-nginx-to-cache-file-serving/237903/2 "2013-12-05T12:14:04Z")

</div>

1. Depends a lot on your environment. If you are sure you are I/O bound,  
there isn’t too much you can tweak.

2. How are you measuring this? It’s normal for there to be very little  
“free” memory on Linux due to buffers and filesystem caches. Look at the  
-/+ buffers/cache line for your available memory. If you are actually  
running out of memory and hitting swap, this is likely why performance  
is  
so low.

3. Take a look at ngx\_slowfs\_cache, it sounds like it might fit the bill

- 

[http://labs.frickle.com/nginx\_ngx\_slowfs\_cache](http://labs.frickle.com/nginx_ngx_slowfs_cache)

Rich.

---

<div class="post-metadata">

**Author:** ![mojiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@mojiz](https://www.ruby-forum.com/u/mojiz)\
**Post date:** [December 5, 2013, 3:39pm UTC](https://www.ruby-forum.com/t/using-nginx-to-cache-file-serving/237903/3 "2013-12-05T15:39:46Z")

</div>

Thanks for the answeres.  
about the memory the problem is I’m hitting this on only some of my  
servers  
but not all, one of my servers has only 3GB memory which 1G is used but  
on  
another 16GB/16GB is used.  
The ngx\_slowfs\_cache module is usefull when the server has 2 type disks,  
SATA and SAS, but I have two servers which I want to do the proxying.  
I’m looking at the included proxy module  
something like this:

proxy\_buffers 10240 128k; #needs 1.2GB memory  
proxy\_cache\_path /dev/sas\_disk/cache;  
proxy\_max\_temp\_file\_size 2048m;

proxy\_store is tempting:

proxy\_store on;  
proxy\_temp\_path /dev/sas\_disk/temp;  
root /dev/sas\_disk/www;

is this what i’m looking for?

Posted at Nginx Forum:

> **[Re: using nginx to cache file serving](https://forum.nginx.org/read.php?2,245244,245251#msg-245251)**
>
> Hi We are using nginx & SATA disks on several of our file servers.However after hitting 12MBytes/s of port speed (server nic is a 1gbps), the server gets down to it's knees. SSH becomes very slow/unresponsive and our users complain about slow...
