# How to keep "hot" files in memory?

**URL:** <https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466>\
**Category:** NGINX\
**Created:** [August 29, 2012, 12:40pm UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466 "2012-08-29T12:40:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 29, 2012, 12:40pm UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/1 "2012-08-29T12:40:51Z")

</div>

Dear all.

We use nginx to server lots of static content with high traffic loads.  
And  
the server is getting slower, because slower SATA drive.

So I think how to keep “hot” files in memory without other  
software,just  
like varnish or squid? Does someone has worked out modules for nginx?

Thanks.

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 29, 2012, 12:48pm UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/2 "2012-08-29T12:48:26Z")

</div>

Linux will automatically keep recently accessed files in spare ram  
Also you can use a ram disk/tmpfs in a proxy cache setup if really  
needed

Richard K.  
Systems Developer | M247 Limited  
Internal Dial 2210 | Mobile +44 7970 621236

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf  
Of Roast  
Sent: 29 August 2012 10:40  
To: nginx  
Subject: how to keep “hot” files in memory?

Dear all.

We use nginx to server lots of static content with high traffic loads.  
And the server is getting slower, because slower SATA drive.

So I think how to keep “hot” files in memory without other  
software,just like varnish or squid? Does someone has worked out modules  
for nginx?

Thanks.

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 30, 2012, 11:17am UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/3 "2012-08-30T11:17:15Z")

</div>

Hello,

You could try open\_file\_cache

[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#open_file_cache)

Best regards

Posted at Nginx Forum:

> **[Re: how to keep "hot" files in memory?](https://forum.nginx.org/read.php?2,230263,230317#msg-230317)**
>
> Dear all. We use nginx to server lots of static content with high traffic loads. And the server is getting slower, because slower SATA drive. So I think how to keep "hot" files in memory without other software,just like varnish or squid?...

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 31, 2012, 2:50am UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/4 "2012-08-31T02:50:27Z")

</div>

Thanks.

But it seems open\_file\_cache not cache the content of the file, am I  
right?

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 31, 2012, 3:43am UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/5 "2012-08-31T03:43:02Z")

</div>

Thanks.

Memcached module is a better solution, it will reduce much disk IO.

But it seems not high efficiency, we just want keep hot file in shared  
memory at millions of static file. But the cache algorithms of memcached  
is  
LRU, so without big memory the cache will be set and then will be delete  
frequently. Am I right?

And I think, maybe we need a moudle to solve this problem?

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 31, 2012, 3:16am UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/6 "2012-08-31T03:16:44Z")

</div>

Check out memcached module for nginx.  
[Module ngx\_http\_memcached\_module](http://wiki.nginx.org/HttpMemcachedModule). It required you to install  
memcached however.

Regards

---

<div class="post-metadata">

**Author:** ![Roast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b19c9b/32.png) [@Roast](https://www.ruby-forum.com/u/Roast)\
**Post date:** [August 31, 2012, 8:20pm UTC](https://www.ruby-forum.com/t/how-to-keep-hot-files-in-memory/222466/7 "2012-08-31T20:20:00Z")

</div>

Hello!

On Wed, Aug 29, 2012 at 06:39:51PM +0800, Roast wrote:

> Dear all.
> 
> We use nginx to server lots of static content with high traffic loads. And  
> the server is getting slower, because slower SATA drive.
> 
> So I think how to keep “hot” files in memory without other software,just  
> like varnish or squid? Does someone has worked out modules for nginx?

Normally OS will do right thing in keeping hot files in memory  
without any other software. You may want to make sure OS isn’t  
low on memory though and have some memory to cache files.

Maxim D.
