Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Mod cache questions |
|
Author |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Mon 27 Apr '15 20:49 Post subject: Mod cache questions |
|
|
I'm making use of Apache 2.4.10 on Ubuntu 15.04 for one of my websites and my entire server runs on a SSD and is virtualised in Hyper-V.
1. 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)
2. 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).
3. 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.
Quote: |
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. |
Source: http://www.philchen.com/2009/02/09/some-tuning-tips-for-apache-mod_cache-mod_disk_cache
4. So which is the best caching method memory or disk?
5. 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.. |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 28 Apr '15 6:55 Post subject: |
|
|
1. Mainly for static or not-very-dynamic text content. Images and the ilk are already binary (see #2)
2. I think this is true however converting the human readable (you know, text) content to binary before sending it over the wire also takes time. With cached content that process has already been done and stored as binary.
3. See #1, dynamic by definition is changing however things that do not change often can benefit I would expect. Obviously php scripts are running through an interpreter, so add some time to the mix. If this is cached, that may not need to happen. Whether or not Apache's cache modules help here I'm not so sure about. There are or have been in the past PHP specific cache's, the php gurus here would know this.
4. You're using an SSD, what is an SSD but memory. It's not as fast as RAM obviously but it's still memory and a whole lot faster than an HDD. That said, the SSD or HDD is storage and does not disappear on restart. Memory cache does, I think, so you are re-caching everything once every time you have to restart. You first few visitors are the ones that pay the highest price.
5. I think the answer to this is already above. Apache is either reading uncached or cached content off the drive, which is faster?
But this is all just my opinion. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Fri 01 May '15 20:58 Post subject: |
|
|
2. What do you mean, aren't all my files already binary?
Perhaps I can see performance improvements because files don't have to be gziped/deflated every time? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 02 May '15 2:15 Post subject: |
|
|
Well, I used to cache. If I open the cache files the text files are still text and the binary files are still binary so I suppose I am wrong.
Having reread on it, its use is for caching stuff on faster drives (why not just have it on the faster drive in the first place), when proxying (to lessen the need to grab the content from the backend) and dynamic cgi content (to not need to run perl or whatever over again as often). |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 04 May '15 11:21 Post subject: |
|
|
If you have static content and use mod deflate it doesn't make any sence to use the cache.
If you pull stuff from a remote server and or cache generated page then it is a good solution.
Unless you store your files in memory --> http://httpd.apache.org/docs/2.4/mod/mod_file_cache.html |
|
Back to top |
|
|
|
|
|
|