I'm running a site with a popular 99% static html page (1 MB) on Amazon EC2 micro instance which receives around 35,000 pageviews a day. The site is only changing once every 3-4 hours or so and it is already running mod_deflate getting the page size to around 100KB.

I'm wondering if there is any way to tell apache2 that the page should be in memory at all times?

Or is it already cached by apache2 or disk in some way (running ubuntu, ext3)?


(Half-)technical points

linux (and other Unix-like systems, and probably any other descent OS for servers) will keep recently/often used file data in RAM. In linux this is called the "pagecache".

For directories, linux also keeps recently looked-up file names, and recently listed directories in "dentry" (directory entry). This way looking-up the same name again and again does not cause a disk access, and does not even need to go though the specific file-system layer code (say, ext3).

So linux keeps both file data and meta-data in RAM if a file is often used. This occurs in the kernel, so:

  • Apache and other linux processes do not have to do anything;
  • different processes share the linux file-system caching features; if some programs needs to read a file another program recently read (or wrote), it will benefit from the cache.

If every program had to implement its own disk cache, than these would each take memory, even if they needed the same files. (Also it would get messy if some process was swap-out, with its RAM file cache!)

But the fact that a file is often entirely read, a thus is entirely cached in RAM, does not mean that repeated read only accesses to this file do not cause any disk access: since linux like other Un*x has a concept of file last access time (atime), it will have to update the file meta-data on disk regularly - unless your turn off access time updating at the fs level (option noatime). Before doing so, you will have to make sure that nothing depends on correct access times. This is mostly an issue with personal computers, where atime update prevents disk sleep, it probably does not matter much on servers. I mention that mostly for completeness.

The real question

Have you profiled your system? Have you identified specific performance problems?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.