Improving Image Conversion Performance with /dev/shm tmpfs in Qunar's Group Buying Backend
The article describes how Qunar's group‑buying backend faced IO bottlenecks during large‑scale image conversion and solved the issue by moving intermediate files to a memory‑based tmpfs filesystem (/dev/shm), achieving a dramatic load reduction without code changes or server restarts.
Qunar's group‑buying backend originally used ImageMagick's convert and Google gm commands to compress and reformat uploaded images, generating up to 13 different sizes per image. When the number of concurrent editors grew, the IO load on the single physical server became a bottleneck, causing slowdowns and unresponsiveness.
The proposed solution focused on reducing IO by using a memory‑based filesystem (tmpfs) mounted at /dev/shm . Standard IO‑optimization methods such as faster disks (SCSI/SSD) or increasing filesystem cache were either impractical or already maximized, leaving the in‑memory filesystem as the viable option.
By creating a directory on /dev/shm and linking it to the backend's temporary image conversion path, all intermediate files are written to RAM instead of disk. This change lowered the server load from around 40 to about 1.x, without any code modifications or system reboots.
Typical commands used:
mkdir /dev/shm/tuanpic
ln -s /dev/shm/tuanpic /tuan/image/convert/temp/pathTo control the size of the tmpfs mount, the /etc/fstab entry can be edited:
tmpfs /your/mount/point tmpfs defaults,size=5% 0 0or the filesystem can be mounted directly:
sudo mkdir /your/mount/point
sudo mount -t tmpfs none -o size=2G /your/mount/pointBecause the tmpfs resides in RAM, it must be managed carefully: intermediate files are removed after being copied to their final disk location to avoid exhausting memory and causing OOM conditions.
The same technique was previously applied in 2011 to store PHP session files in /dev/shm , eliminating session blocking and outperforming alternatives like memcached.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.