Postfix Queue on a Ram Drive – Screencast

Placing the Postfix queue on a ram drive could boost your MTA’s performance quite a bit.
The queue behaviour takes up a lot of system IO, which affects your email throughput.

There are some big disadvantages of using a ram drive for the queue. So please read before setting this up. It may not be a valid solution for your environment.

What is a Ram Drive?

A ram drive is a volume that sits on the RAM instead of a hard drive.
This makes the volume very fast for reading and writing, as everything is done in memory.
But because it is located in memory, you will loose everything after a reboot.

Advantages of working with a Ram Drive

Each email that you send or receive goes in the Postfix queue. The default location is /var/spool/postfix
If you take a look at this folder, you will see a list of subdirectories that will hold your email at one point.
When dealing with high volumes of emails, files tend to move around in these folders and will cause a bit of an IO load on the system.

Why this may not be for you

  • You could lose all of your pending emails in case of a system restart
  • A Ram Drive takes resources from your server’s memory. Depending on how much RAM you have, and how big the volume needs to be, it could get pricy
  • You could lose all of your pending emails in case of a system restart

Placing the Postfix queue on a ram drive

Screencast – Postfix Queue on a Ram Drive

Some stats for the demo server

  • In this example I will work with a CentOS server
  • It has 4GB of RAM
  • 8GB of disk space
  • It is running locally on a Virtual Box
  • Postfix is set up with the default settings

Checking the current volume

First, lets see what we have on our server by running the df command:

[root@screencast ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_screencast-lv_root
4.1G 778M 3.2G 20% /
tmpfs 1.9G 4.0K 1.9G 1% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot

We can see that we have a “tmpfs” volume that has a size of 1.9GB and is mounted on /dev/shm.
This is the RAM drive we will be working with.

Setting the queue location in postfix

The queue location is indicated in the main.cf file.
Look for the entry:
queue_directory = /var/spool/postfix
Change it to:
queue_directory = /dev/shm/postfix

We now have a problem. The queue folders are missing from /dev/shm.
And whenever we reboot the server, they will be gone.

To solve the issue, we will edit the /etc/init.d/postfix file.
Find the lines:
# Source function library.
. /etc/rc.d/init.d/functions
And add the following line before: mkdir /dev/shm/postfix

Postfix will take care of the rest.

Increasing the size of the ram drive

If you want to change the size of the ram drive, you will have to edit the /etc/fstab file:

#
# /etc/fstab
# Created by anaconda on Sun Feb 16 13:20:11 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_screencast-lv_root / ext4 defaults 1 1
UUID=793b30bb-b199-4e05-b38d-7c0a754775c0 /boot ext4 defaults 1 2
/dev/mapper/vg_screencast-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0

Change the tmpfs line so instead of defaults, it will indicate:
size=3072m
note the “m”

Now, lets remount the volume – **You will loose any data on it**
mount -o remount tmpfs

Restarting Postfix

The last thing that we need to do is restart postfix.

Now you have the Postfix queue on a ram drive. So I will remind you again. You will lose all data on the drive when rebooting.

You can read more about Postfix performance tuning:

Join my Online Postfix Class
Join my Online Postfix Class
I am working on a new Postfix training class that will be launching soon. The course includes:
  • Understanding the Logs files
  • Troubleshooting
  • Performance
  • Rate limiting
  • DKIM/DMARC/SPF
  • And much More

Powered by WordPress. Designed by Woo Themes