In the daily use of a web server some services fall on the with increasing requests longer and longer to process a request and thus load the server.
A typical example is the interface between the mail server and the virus scanner: Amavis, which temporarily saves the e-mails and reads them again. This naturally creates a high demand for access to the hard disks or SSDs in larger systems.
Here it is possible to store these file operations in the working memory in order to guarantee a considerably faster processing.
Other examples would be the /tmp directory itself in the php session files, or even log files.
When saving in RAM, there is always the risk of loss due to a defect in the system or a server restart. You should therefore always only save unimportant Data store there, or provide for a regular backup.
A RAMDISK for Amavis can be easily created with a few commands.
To set up a ramdisk we need the directory where Amavis stores the files and the user and group ID.
Both can be done most easily with
grep 'amavis' /etc/passwd
read out.
amavis:x:497:497:Amavis email scan user:/var/amavis:/bin/sh
The path in this example is /var/amavis. The temporary files are then stored in the /var/amavis/tmp directory. For this directory we want to create a ramdisk.
The user ID is the first number 497 followed by the group ID which in this case is also 497.
In /etc/fstab we now enter the following line to ensure that the ramdisk is created even after a reboot
tmpfs /var/amavis/tmp tmpfs defaults,size=256m,mode=750,uid=497,gid=497 0 0
The size of the ramdisk should not be too small, because amavis will reject emails if the limit is exceeded. 256MB are sufficient in most cases.
You can determine the current demand with
you -hs /var/amavis/tmp
investigate. The result e.g. 11M /var/amavis/tmp then indicates how many megabytes are already in the directory. It should also be noted, however, that on days with a high mail volume due to Spam or large file attachments of course more space is needed.
In an emergency, however, the ramdisk can still be removed or enlarged.
Now we can simply mount the ramdisk with
mount /var/amavis/tmp
Via
df -h
tmpfs 512M 0 512M 0% /var/amavis/tmp
we can then detect that our ramdisk is active and empty.
From now on amavis processing is extremely fast.