I'm making use of Apache 2.4.10 on Ubuntu 15.04 and my entire server runs on a SSD and is virtualised in Hyper-V.
- When should I enable mod cache in Apache 2.4?
Currently I have pretty good TTFB for static files. (0.015 - 0.020 seconds TTFB, when the ping is ~7ms)
- I doubt using a cache makes any sense here since I assume most of the TTFB is caused by setting up the TCP connection. -Is this assumption correct?
I've noticed that dynamic content e.g PHP scripts are having a much higher TTFB (e.g. 0.085-0.120 seconds).
- Would enabling caching in Apache make the loading of this dynamic content any faster?
I've read that I should use mod_disk_cache because it makes use of sendfile API in Linux which makes it faster than mod_mem_cache, others say the mem_cache is faster.
The first performance decision I made was to use –enable-disk-cache after doing some research I found that contrary to what you would think, disk cache is faster then memory cache when it comes to Apache mod_cache and OS interaction. The reason why is when you use mod_mem_cache the process of reading a file into memory, basically copying its data into RAM and thus kernel buffer in order to deliver it is not optimal. When using mod_disk_cache Linux uses the sendfile API, which does not require the server to read the file before delivering it. The server identifies the file to deliver and the destination via the API, the OS then reads and delivers the file, so no read API or memory for the payload is required, and the OS can just use the file system cache. So the kernel acts as a buffer, increasing cache speed.
So which is the best caching method memory or disk?
Does it even make sense to use mod_disk_cache on the same drive as the web folder? I would assume it would just use a different directory to load the cached files, instead of reading the source files. But I don't see why this would be any faster..