Installing and Tuning the XanMod Kernel on a VPS
XanMod is a "general-purpose Linux kernel distribution with custom settings and new features". From the perspective of someone using a low-end VPS for say hosting a website, XanMod has several advantages over the kernel builds included with your Linux Distribution. First of all, it's almost always going to be more up to date. This means that XanMod has support for features like swapfiles and the newest performance and security patches. This is part of the reason why installing XanMod usually provides a significant improvement to general performance. Secondly, XanMod has tuned scheduler and networking settings by default. It also has support for schedulers and algorithms that are most likely not available in your distro's kernel builds. Two of these are BBR and CAKE. These are respectively congestion control and queue management algorithms. They provide a significant boost to networking speed compared to more traditional options which you are more than likely already using. Under heavy network load, whether in the form of many users accessing your website, or a few downloading large files these algorythms generally significantly improve speed and decrease CPU usage. Google's findings over here show how much of a difference BBR can make.
However although XanMod is generally very stable it's not as well tested as the kernal that ships with your distro, and you may experience problems. I personally have never had a single problem with XanMod.
This guide assumes you are running a recent version of Debian or Ubuntu
Firstly, add the XanMod repo to APT
echo 'deb http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list && wget -qO - https://dl.xanmod.org/gpg.key | sudo apt-key add -
Next, update and install XanMod
sudo apt update && sudo apt install linux-xanmod
Your server is most likely running an Intel Processor, so install the latest microcode
sudo apt install intel-microcode iucode-tool
Although Xanmod's default configuration is fine, it may be worth tuning some settings especially if you have users with large latencies.
Here are the values I use in /etc/sysctl.conf
vm.swappiness = 0 net.core.default_qdisc = cake net.ipv4.tcp_congestion_control = bbr net.core.netdev_budget = 200000 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_rmem = 4096 87380 8388608 net.ipv4.tcp_wmem = 4096 65536 8388608
To avoid excess swapping, I use vm.swappiness = 0. If you have ample RAM in your VPS, this may stop random slowdowns. I set the queue manager and congestion control to cake and bbr respectively. The congestion control should be BBR by default, but it's worth making sure. The next values affect the buffers for TCP traffic. The higher these are, the more memory usage and overhead you will get but the higher speed you will get relative to latency. The three values in the final two lines set the minimum, default and maximum TCP buffers. If you have a very fast connection (Above 1Gbps) or have a lot of traffic over long latencies you might need to increase these values. If you have little RAM or CPU power, and have little bandwidth over short latencies you should turn these values down. This article goes more into depth about these settings. For my use case, these setting improved the loading time of web pages hosted on the server, and increased download speed of large files significantly over the Debian 9 stable kernel with default settings. This is also a good read regarding these values.