Optimize virtual machine network performance

Due to the virtual nature of a VM’s network interface controller (NIC), the VM loses a portion of its allocated host network bandwidth. This can reduce the workload efficiency of the VM. To minimize the negative impact on virtual NIC (vNIC) throughput, you can use several methods.

Procedure

  • Use any of the following methods and observe if it has a beneficial effect on your VM network performance:
    • Enable the vhost_net module

      On the host, ensure the vhost_net kernel feature is enabled:

      # lsmod | grep vhost
      vhost_net              32768  1
      vhost                  53248  1 vhost_net
      tap                    24576  1 vhost_net
      tun                    57344  6 vhost_net

      If the output of this command is blank, enable the vhost_net kernel module:

      # modprobe vhost_net
    • Configure multi-queue virtio-net

      To configure the multi-queue virtio-net feature for a VM, use the virsh edit command to edit to the XML configuration of the VM. In the XML, add the following to the <devices> section, and replace N with the number of vCPUs in the VM, up to 16:

      
                      <interface type="network">
                        <source network="default"/>
                        <model type="virtio"/>
                        <driver name="vhost" queues="N"/>
                      </interface>
                    

      If the VM is running, restart it for the changes to take effect.

  • Batching network packets

    In Linux VM configurations with a long transmission path, batching packets before submitting them to the kernel might improve cache utilization. To configure packet batching, use the following command on the host, and replace tap0 with the name of the network interface that the VMs use:

    # ethtool -C tap0 rx-frames 64
  • SR-IOV

    If your host NIC supports single-root I/O virtualization (SR-IOV), use SR-IOV device assignment for your vNICs.

    For more information, see Managing SR-IOV devices.