Improving Apache HTTPD performance using CacheFile and MMapFile directives

Brunda K
Brunda’s Tech Notes
2 min readAug 8, 2023

--

In this article, I would like to write about the experimental module — mod_file_cache.so. This module provides an option to enhance the performance of Apache Web Server that serves many static files from the filesystem.

Each time a static file is requested, the Apache WebServer opens the file and writes the contents of the file to network socket on which the connection was accepted on. An experimental module called mod_file_cache.so aims to improve the performance of the server if the following conditions are met:

  • There are many static files that are served
  • These files change infrequently or predictably at the same time.

mod_file_cache.so provides two options to speed up the performance. The module could either be instructed to open a set of static files and mmap them or open the files and cache the file handles in a cache that the webserver creates and maintains.

The CacheFile directive of mod_file_cache opens an active handle or file descriptor to the file (or files) listed in the configuration directive and places these open file handles in the cache.

The MMapFile directive maps one or more files (given as whitespace separated arguments) into memory at server startup time. They are automatically unmapped on a server shutdown.

In case of MMapFile, the file is mapped into the virtual address region of the process at process startup. In case of CacheFile, the process opens an file descriptor to the file. Both these operations are done at process startup time, thereby saving the costs involved with file I/O during request processing.

Drawbacks

It is important to be aware that any changes done to the files whose file handles have been cached or which have been mmaped will not be reflected when the file is served by the webserver unless the server is stopped and restarted.

It is also not clear if this approach works with NFS mounted files.

Hence, it may be necessary to experiment and ascertain if the CacheFile and MMapFile directives work fine in any given environment before using them in production environments.

--

--