The following describes how to performance tune Ubuntu Server virtual machines for use in Azure. Although this article focuses on Ubuntu Server because it’s better established in Azure at this time. It’s worth mentioning that Debian offers better performance and stability overall, albeit at the cost of some of the more recent functionality support available in Ubuntu. Regardless many of the optimizations discussed below apply equally to both although commands and settings may vary occasionally.
Best practice recommendations from Microsoft.
- Don’t use the OS disk for other workloads.
- Use a 1TB disk minimum for all data workloads.
- Use storage accounts in the same datacenter as your virtual machines.
- In need of additional IOPs? Add more, not bigger disks.
- Limit the number of disks in a storage account to no more than 40.
- Use Premium storage for blobs backed by SSDs where necessary.
- Disable ‘barriers’ for all premium disks using ‘Readonly’ or ‘None’ caching.
- Storage accounts have a limit of 20K IOPs and 500TB capacity.
- Enable ‘Read’ caching for small read datasets only, disable it if not.
- Don’t store your Linux swapfile on the temporary drive provided by default.
- Use EXT4 filesystem.
- In Azure IOPs are throttled according to VM size so choose accordingly.
Linux specific optimisations you might also consider.
1. Decrease memory ‘swappiness’ and increase inode caching:
sudo echo vm.swappiness=10 >> /etc/sysctl.conf sudo echo vm.vfs_cache_pressure=50 >> /etc/sysctl.conf
2. Disable CPU scaling / run at maximum frequency all the time:
sudo chmod -x /etc/init.d/ondemand
3. Mount all disks with ‘noatime’ and ‘nobarrier’ (see above) options:
sudo vim /etc/fstab
Add ‘noatime,nobarrier’ to the mount options of all disks.
For more information: https://wiki.archlinux.org/index.php/fstab
4. Upgrade to a more recent Ubuntu kernel image and remove the old:
sudo aptitude update sudo aptitude search linux-image sudo aptitude install -y linux-image-4.4.0-28-generic sudo aptitude remove -y linux-image-3.19.0-65-generic
In the example above the latest available kernel version available is version ‘linux-image-4.4.0-28-generic’ and the version currently installed was ‘linux-image-3.19.0-65-generic’ but these will change of course.
5. Change IO scheduler to something more suited to SSDs (i.e. deadline):
Edit the grub defaults file.
sudo vim /etc/default/grub
Change the following line from
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash elevator=deadline”
For more information: http://stackoverflow.com/questions/1009577/selecting-a-linux-i-o-scheduler
6. Mount a suitably sized data disk:
First start by creating a new 1TB disk using the Azure CLI.
Partition the new disk and format it in ext4 using the following script.
#!/bin/sh</div> hdd="/dev/sdc" for i in $hdd;do echo "n p 1 w "|fdisk $i;mkfs.ext4 $i;done
Mount the disk.
mkdir /mnt/data/ mount -t ext4 /dev/sdc1 /mnt/data/
Obtain UUID of newly mounted disk.
Add the following to /etc/fstab.
UUID=<NEW DISK UUID> / ext4 noatime,defaults,discard 0 0
6. Add a swap file:
sudo dd if=/dev/zero of=/mnt/data/swapfile bs=1G count=32 sudo chmod 600 /mnt/data/swapfile sudo mkswap /mnt/data/swapfile sudo swapon /mnt/data/swapfile echo "/mnt/data/swapfile none swap sw 0 0" >> /etc/fstab
8. Enable Linux Kernel TRIM support for SSD drives:
sudo sed -i 's/exec fstrim-all/exec fstrim-all --no-model-check/g' /etc/cron.weekly/fstrim
For more information: https://www.leaseweb.com/labs/2013/12/ubuntu-14-04-lts-supports-trim-ssd-drives/