XenScheduling
From Granizada
If you are a Xen user, you should read the documentation for the xm command (the man page and the user manual seem to have complementary failings.) Apart from a bit of background, everything in the rest of this article can be found there although maybe in a more terse form.
Resource Management
One of the main reasons to virtualise servers is that resource management is much easier. Resource management means that limits are set on what CPU, I/O bandwidth, network bandwidth and so on a virtual machine can use. Nearly PC-based virtual systems (certainly including Xen, VMware, KVM) offer only crude controls compared to midrange and mainframe facilities. One way of measuring flexibility in a virtual system is by how fine-grained the resource management is. As usual with Xen there are some effective tools but they are clunky.
This article only talks about allocating CPU time in Xen. Partly because that keeps the discussion simple but also because if you throttle CPU you are often throttling other resource usage as well -- although not necessarily in a linear relationship. And mostly because Xen gives very few other options! However if you want to throttle I/O then here's a hint: look at tuning the Linux I/O scheduler using iotune, assuming you're using the CFQ scheduler.
CPU Schedulers
CPU schedulers in Xen are much like CPU schedulers in Linux: there are alternatives, the differences can be important but obscure, and the default works pretty well. And just like the Linux kernel (currently, they are working on it), you must choose a scheduler at boot time and you can't change your mind later. You do this on the Xen commandline, where you set things such as the console for Dom0, with the sched= parameter. That is for advanced usage, if you are starting out just be aware it is possible. The default CPU scheduler for Xen is called the SEDF (Simple Earliest Deadline First) scheduler. By default every VM gets an equal amount of CPU. If one VM wants to chew up CPU, it is prevented from doing so unless the rest of the system has no need for those cycles.
There are two xm commands relevant to CPU scheduling:
- xm sched-credit. This applies to all schedulers, and allows you to set a weight (how much CPU is allocated relative to other VMs) and an optional cap (maximum amount of CPU regardless of how much spare capacity there is.) By default all weights are set equally. You can display current weights in Python-friendly format with xm sched-credit -d <domainname>. You set weights with ''xm sched-credit -d <domainname> -w <weight>
- xm sched-sedf. This only applies to the SEDF scheduler, and applies the concept of weighting with some insight as to how SEDF interprets it. You don't need to used sched-sedf, but if you do you can define for example what is meant by one particular slice. It allows you to fiddle with algorithm-specific constants.