Home |
Comics |
Gallery |
(Amazon|
ThinkGeek) wishlist |
Donations |
Impressum |
The Book of Postfix |
Postfix - Einrichtung, Betrieb und Wartung |
Blog
Speed up amavisd-new by using a tmpfs filesystem for $TEMPDIR
Prerequisite
Linux
You need a kernel that is capable of creating and using a tmpfs filesystem.
*BSD
You need a kernel that is capable of creating and using an mfs filesystem.
Why do this at all?
amavisd-new's speed may be limited by the speed and latency of your disk I/O.
By putting the temporary
files into a ramdisk we eliminate precious read/write operations on a slow
mechanical disk.
But is it safe?
Yes.
It is safe because amavisd-new will return a 250 OK only after it reinjected
the mail back into Postfix.
Sizing
If you run n amavisd-new instances and each one accepts mails of
$message_size_limit, then you need a tmpfs of size:
n * (1 + max(expansionfactor)) * $message_size_limit
Let's assume 5 instances, $message_size_limit of 10 MB = 50 MB for the
original mails alone.
Now add space for the unpacked mail: 5*10 MB raw mail size become about 5*8 MB
binary size , unpack at ratio 1:2, become 80 MB.
Sum: 130 MB.
How to do it?
- Find out where amavisd-new has it's $TEMPBASE. Default is
/var/amavis.
- Create a tmpfs entry in /etc/fstab:
- On Linux:
/dev/shm /var/amavis tmpfs defaults,noexec,nodev,nosuid,size=150m,mode=750,uid=7509,gid=54322 0 0
Use the uid of the user your amavisd-new runs as. As gid use
the group clamd runs as. "mode=750" makes sure that other users like
clamd which need to be able to read this directory are able to access
it. Also choose the size sufficiently large!
- On FreeBSD versions prior to 5.x (added by Vivek Khera):
/dev/aacd0s2b /var/amavis mfs rw,-s=65536 0 0
Where the first column is the device on which your swap lives, the second
the mounted directory, and the -s=NNN is the size in 512k blocks. The
example creates a 32Mb MFS file system on /var/amavis.
Prior to 5.x you need in your kernel config file this entry which is
normally the default:
pseudo-device vn #Vnode driver (turns a file into a device)
- On FreeBSD versions 5.x (added by Reinoud Koornstra):
md /var/amavis mfs rw,-s64m 0 0
in 5.x you need:
device md # Memory "disks"
in your kernel configfile (which is the default).
- On OpenBSD (added by Bryan Irvine):
/dev/wd0b /var/amavisd/tmp mfs rw,async,-s=524288 0 0
or from the command line
mount_mfs -s 524288 /dev/wd0b /var/amavisd/tmp/
- On Solaris (added by WC Jones):
in /etc/vfstab:
swap - /var/amavis tmpfs - yes size=200M
or from the command line
mkdir /var/amavis
mount -F tmpfs -o size=200m swap /var/amavis
But see SUNWdrvs8
here
- Stop amavisd-new
- mount /var/amavis
- Start amavisd-new
That's it.
Does it work?
You know the drill: Check your logs!
Case study: Before and after
Before: Left side of the graphs
After: Right side of the graphs
Throughput
Received: we see an increase from 160 mails/minute to 210 m/m.
Sent: we see an increase from 60 mails/minute to 125 m/m.

Queue
The queue used to be filled with mail still left to be scanned. After the
optimiziation there's no queue buildup anymore.
© by Ralf Hildebrandt
This document contains links to external information sources that I do
neither monitor nor control. I explicitly disclaim any liabilities in
respect to external references.
You are getting this document without any guarantees. Any methods
shown above are meant as demonstration and may be wrong in some place.
You may damage your system if you try to follow my hints and
instructions. You do this at your own risk!
|
|
|

|
|
This file was last modified 17. Jan 2007 by root