Make the network of your VMs fly with the virtio driver
Bring gigabit to your VM’s NIC!
I. About the virtio driver
It’s part of KVM best practices to enable the virtio driver.
KVM can provide two type of devices to the guest operating system:
- emulated
- para-virtualized
Compared to emulated devices, para-virtualized devices provide lower latency and higher throughput for I/O operations of guest operating systems. KVM includes the VirtIO API to para-virtualize devices.
The VirtIO API is a high performance API written by Rusty Russell which uses virtual I/O. It para-virtualized devices use to increase speed and efficiency. The VirtIO API specifies an interface (virtio net) between virtual machines and hypervisors that is independent of the hypervisor. In typical situations, VirtIO para-virtualized devices provide lower latency and higher throughput for I/O operations of guest operating systems. VirtIO para-virtualized devices are especially useful for guest operating systems that run I/O heavy tasks and applications.
II. Syndrome
Pick up 2 instances, from one run:
$ iperf -s |
When the driver is disable:
ubuntu@vm-without-virtio:~$ iperf -c 192.168.22.49 -i1 -t 10 |
When the driver is enable:
ubuntu@vm-with-virtio:~$ iperf -c 192.168.22.47 -i1 -t 10 |
III. Enable it!
First of all, we have to verify that virtio is in the list of supported devices:
$ sudo kvm -net nic,model=? |
Nova manages this via the libvirt template in /usr/share/pyshared/nova/virt/libvirt.xml.template
with:
<interface type='bridge'>
<source bridge='${nic.bridge_name}'/>
<mac address='${nic.mac_address}'/>
#if $getVar('use_virtio_for_bridges', True)
<model type='virtio'/>
You also have to enable the flag in your nova.conf:
--libvirt_use_virtio_for_bridges=true
This will enable the -device virtio-net-pci
in kvm.
Simply restart libvirt-bin and let’s roll!
It could be a shame to don’t use this option since obviously everyone’s network use Gigabit connection ;-)
Comments