InstanceResourceQuota

= Instance Resource Quota =

Each nova flavor can be assigned extra specs which allow to specify resources quota/limits. Currently these limits can be applied to CPU, disk IO and network bandwidth.

Extra specs?

Extra specs are additional information set per flavor. They are used here to apply quota but there are not limited to this feature. One can set extra specs to specify where a kind of flavor must be run, etc.

https://blueprints.launchpad.net/nova/+spec/quota-instance-resource

How it works
Nova can use libvirt features to set limits when a new VM is spawned.

CPU
CPU quota are handled by using cgroups.

IO
IO throttling are handled by QEMU. It's like using libvirt's blkdeviotune.

Note that libvirt has also a blkiotune feature that make use of cgroups but this is not used by Nova.

Network
Traffic shaping -- i.e. limit inbound/outbound bandwidth -- is achieved by using tc. Note that libvirt uses tc to allow traffic shaping by network interface. If libvirt was using cgroups to control bandwidth, all network interfaces of a guest would be constrained since cgroups work at process level.

Configure Nova via CLI
The following examples make use of nova-manage and python-novaclient.

IO limits
Since QEMU 1.1

Nova Extra Specs keys:


 * disk_write_bytes_sec
 * disk_read_bytes_sec
 * disk_read_iops_sec
 * disk_write_iops_sec
 * disk_total_bytes_sec
 * disk_total_iops_sec

Examples
nova-manage:

nova-manage flavor set_key --name m1.small --key quota:disk_read_bytes_sec --value 10240000 nova-manage flavor set_key --name m1.small --key quota:disk_write_bytes_sec --value 10240000

python-novaclient with admin credentials:

nova flavor-key m1.small set quota:disk_read_bytes_sec=10240000 nova flavor-key m1.small set quota:disk_write_bytes_sec=10240000

CPU limits
Nova Extra Specs keys:


 * cpu_shares
 * cpu_quota
 * cpu_period

cpu_shares

The optional shares element specifies the proportional weighted share for the domain. If this is omitted, it defaults to the OS provided defaults. NB, There is no unit for the value, it's a relative measure based on the setting of other VM, e.g. A VM configured with value 2048 will get twice as much CPU time as a VM configured with value 1024. Since 0.9.0

cpu_period

The optional period element specifies the enforcement interval (unit: microseconds). Within period, each vcpu of the domain will not be allowed to consume more than quota worth of runtime. The value should be in range [1000, 1000000]. A period with value 0 means no value. Only QEMU driver support since 0.9.4, LXC since 0.9.10

cpu_quota

The optional quota element specifies the maximum allowed bandwidth (unit: microseconds). A domain with a negative quota indicates that the domain has infinite bandwidth, which means that it is not bandwidth controlled. The value should be in range [1000, 18446744073709551] or less than 0. A quota with value 0 means no value. You can use this feature to ensure that all vcpus run at the same speed. Only QEMU driver support since 0.9.4, LXC since 0.9.10.

Examples
nova-manage:

nova-manage flavor set_key --name m1.small --key quota:cpu_quota --value 5000 nova-manage flavor set_key --name m1.small --key quota:cpu_period --value 2500

python-novaclient with admin credentials:

nova flavor-key m1.small set quota:cpu_quota=10240000 nova flavor-key m1.small set quota:cpu_period=10240000

Bandwidth limits
Nova Extra Specs keys:


 * vif_inbound_average
 * vif_outbound_average
 * vif_inbound_peak
 * vif_outbound_peak
 * vif_inbound_burst
 * vif_outbound_burst

Incoming and outgoing traffic can be shaped independently. The bandwidth element can have at most one inbound and at most one outbound child elements. Leaving any of these children element out result in no QoS applied on that traffic direction. So, when you want to shape only network's incoming traffic, use inbound only, and vice versa. Each of these elements have one mandatory attribute average. It specifies average bit rate on interface being shaped. Then there are two optional attributes: peak, which specifies maximum rate at which bridge can send data, and burst, amount of bytes that can be burst at peak speed. Accepted values for attributes are integer numbers, The units for average and peak attributes are kilobytes per second, and for the burst just kilobytes. The rate is shared equally within domains connected to the network. See libvirt QoS.

Examples
nova-manage:

nova-manage flavor set_key --name m1.small --key quota:vif_inbound_average --value 10240 nova-manage flavor set_key --name m1.small --key quota:vif_outbound_average --value 10240

python-novaclient with admin credentials:

nova flavor-key m1.small set quota:vif_inbound_average=10240 nova flavor-key m1.small set quota:vif_outbound_average=10240

Memory limits
Currently there is no implementation of libvirt memtune in nova. See https://blueprints.launchpad.net/nova/+spec/flavor-quota-memory

Unset limits
To unset a quota, just run:

nova flavor-key unset

Example
nova flavor-key m1.small unset quota:vif_inbound_average

Configure Nova via Horizon
The aforementioned examples make use of nova-manage and python-novaclient but extra specs can also be set in Horizon.

With admin credentials, go to [Admin] > [System] > [Flavors] to display all the flavors. Click on "More" on the right of a flavor and choose "View Extra Specs" in the dropdown menu. Now you can add extra specs by clicking on "Create".