Table of Contents

About

Apache support mmap-ing a specified list of files that will be mapped in memory for every process. This can be quite useful for caching static files into memory in order to reduce the IO overhead when reading these files from the hard-drive.

Requirements

The script assumes that the cache and file_cache modules are enabled in Apache. For example, on Debian distribution one would issue:

a2enmod cache file_cache

in order to enable the modules.

Usage

The file in the Code section needs to be edited in order to set the include and exclude regex as well as a path to scan in. The output of the script will be a list of instructions that can be saved to an Apache configuration file.

An example output snippet generated by the script would be:

MMapFile /srv/www/wiki/lib/plugins/indexmenu/images/simple/joinbottom.gif
MMapFile /srv/www/wiki/lib/plugins/indexmenu/images/simple/folderh.gif
MMapFile /srv/www/wiki/lib/plugins/indexmenu/images/simple/plus.gif
MMapFile /srv/www/wiki/lib/plugins/indexmenu/images/simple/base.gif
MMapFile /srv/www/wiki/lib/plugins/indexmenu/images/gnome.png
...

The output of this script can then be redirected to an Apache configuration file, for example, by running:

./generatemmap.sh > /etc/apache2/conf-available/dokuwiki-mmap.conf

After which the configuration file has to be enabled:

a2enconf dokuwiki-mmap

and finally, Apache has to be restated:

service apache2 restart

Code

generatemmap.sh
#!/bin/sh
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3      ##
###########################################################################
 
INCLUDE_REGEX="^.+?\.(yuv|tif|tga|gif|bmp|webp|tiff|png|jp(2|e|eg|g)|ico|ilbm|svg|mid|midi|iso|mpg|jar|mpeg|qt|mov|avi|wav|mp3|mp4|mpeg|swf|flv|x-flv|m4a|deb|rpm|exe|bz2|Z|zip|lha|lzx|tar|txt|tgz|gz|inc|pdf|psd|ai|eps|ps|ram|rar|3ds|bin|cab|dll|7z|ppt|pps|ppsx|pptx|doc|html|htm|css|js)$"
EXCLUDE_REGEX="^.+?/(data|cache|opt)/.+?$"
 
SCAN_DIRECTORY="/srv/www/wiki"
 
find $SCAN_DIRECTORY \
	-regextype posix-extended \
	-regex $INCLUDE_REGEX \
	! -iregex $EXCLUDE_REGEX \
	| awk '{ print "MMapFile",$1 }'

apache/mmap_cache_files.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.