IO performance, or the read/write latency of a web server can seriously impact the overall page load times of your server. Making a simple change to the IO scheduler that’s built into the kernel can decrease your IO latency by 20% or more. You’ll need shell access and root access to make these changes, but the commands you’ll use are relatively simple. If you are on a shared hosting plan unfortunately, these changes are probably beyond your control. If you have a VPS or dedicated server, you should be good to go!
Standard Disclaimer: This posting should be a safe way to get you started on optimizing your IO scheduler or “elevator”. However, you should take precautions with testing and changing this option(s). You’ll have to assume all responsibility for these changes and testing. As with all server changes, what works great for one user or server doesn’t can seriously impair the performance of another environment. You assume all responsibility for any changes you make to your own server environment. To begin, we’ll need to check the schedulers that are available to you.
You may need to substitute the sda portion of the command with your disk devices, which may be sda, sdb, sdc or hda, hdb, etc. If you receive the output below, you’ve picked an invalid device.
cat: /sys/block/sda/queue/scheduler: No such file or directory
In this example, the output shows we have four schedulers available and the one listed in the brackets is the current scheduler.
noop anticipatory deadline [cfq]
By default, most Linux installations default to cfq, Completely Fair Queuing. This scheduler tries to balance IO among all the processes fairly. This isn’t the best option for web servers.
Next, you’ll have to decide which scheduler to use. We can eliminate the anticipatory scheduler, it’s designed for desktop systems. The noop is the best for SANs, NAS devices and high end RAID controllers. If you don’t know what these are, you can probably rule out noop. For most users and admins, deadline is the best option.
Let’e begin by temporarily setting the IO scheduler for your sda device. Setting the IO scheduler using this command, will only set the scheduler until you reboot the server. This will allow you to change the IO scheduler and perform your tests before you change the scheduler. In this case, we are using the deadline scheduler from the list above when we checked the available schedulers.
echo deadline > /sys/block/sda/queue/scheduler
Once you are happy with the IO scheduler change, we should set it permanently. There are two ways to do this. One is designed for someone who is comfortable editing their grub.conf boot options, the second method is easier for a new server administrator.
Method 1: Editing the grub.conf file
Add elevator=deadline option to your kernel boot options. Replace deadline with the name of the scheduler you selected after testing. Using this method, you will only have to add one entry, and it will affect all of your disk devices by default.
Method 2: Add the commands you used for testing to your /etc/rc.local file
Use the command you used for testing, and appending it to your /etc/rc.local file.
echo “echo deadline > /sys/block/sda/queue/scheduler” >> /etc/rc.local”
If you have multiple devices, you’ll have to repeat the this command for each device. The advantage to using this method, is the ability to specify different IO schedulers for different disk devices.
You’re done! Once you’ve chosen the right IO scheduler for your environment, you’ll find that your server will perform better under heavy load as well as casual use. Be sure to leave a comment and let us know what IO scheduler you chose as well as how you implemented it!