In any system, the biggest bottlenecks will usually be related to I/O. What this means practically is two things:
But moving across the boundaries of memory, disk, and network is usually cumbersome. For example, storing things on disks is programmatically easy, but slow. Storing things in memory, in a persistent way, can be hard. This is more true for a shared-nothing architecture like PHP rather than Java, so you may have to deal with some shared memory libraries and SysV IPC-style calls.
Enter tmpfs
, the linux shared-memory file system. You can mount it just like ext3
, create files, and otherwise treat it like a normal disk, but it’s in memory! Awesome!
On RHEL, Fedora, CentOS – not sure about others – there is a tmpfs
drive mounted under /dev/shm
by default. One other note: since it is memory, its contents will be lost upon reboot. I usually re-create any directories I need in the /etc/rc.d/rc.local
script. Note, however, that this is the last file to run on boot, so if you have a service or daemon that assumes a folder in /dev/shm
, you will need to create it in the service’s startup script (usually in /etc/init.d
).