My 11G Dell R610 is over a decade old – and it’s beginning to show it’s age. The performance per watt is eye watering, so it’s vital that I squeeze every last drop of FLOPS from this computational dinosaur.
Changing the Virtual Machine Clock Source from ‘xen’ to ‘tsc’
For Linux virtual machines running on a Xen hypervisor, this is the BIGGEST change you can make by far. This reduced my CPU usage by 50% in both domU and nested virtualisation like docker. Changing the clock source from ‘xen’ to ‘tsc’ speeds up system calls, which subsequently boosted my service response time and performance by a very noticeable margin.
I discovered this after seeing the following warning when starting Redis in Docker:
# WARNING Your system is configured to use the 'xen' clocksource which might lead to degraded performance.
DEGRADED PERFORMANCE?! Not on my watch.
This is not a new discovery, it just doesn’t seem to be very well documented considering how much of the internet runs on the Xen Hypervisor. I could only find this slideshow from someone at Netflix and this AWS post. As far as I can understand, the default clock source defualts to xen in order to stop clock drift on VMs. However, as far as I can tell this is much less of a problem on modern x86 platforms than it once was, and I haven’t yet experienced any problems after a few months of uptime. Point being, I don’t think there are many reasons not to do this. Change the clock source on the virtual machine (persistent on boot) with:
# nano /etc/default/grub
Find GRUB_CMDLINE_LINUX and add clocksource=tsc tsc=reliable in addition to anything there.
# update-grub
# reboot
That’s it! Check the clock source is now tsc by running:
cat /sys/devices/system/clocksource/clocksource0/current_clocksource
You can change it temporarily, which is detailed in the AWS post linked above.
That’s it! Enjoy your free performance.