Performance tuning

From OpenVZ Virtuozzo Containers Wiki
(Redirected from OpenVZ performance tuning)
Jump to: navigation, search

<translate> This page describes how to improve the performance of an OpenVZ system.

HW node environment tuning[edit]

Disable unnecessary services[edit]

Disable all default services that you do not need to use and then reboot your host.

For example, the audit daemon can significantly decrease performance of linux kernel system calls (up to ~20%) even if you do not use any audit rules, or even if you just stopped this service without host reboot!

To setup default services, use chkconfig or ntsysv in RedHat, or rc-update in Gentoo, update-rc.d on Debian

Shell scripts performance improvement[edit]

To improve performance of small shell scripts, which spends a lot of time starting the shell binary itself (like the shell scripts test from the unixbench package), you can set your LANG environment variable to "C".

To see current settings, type

  1. locale

If you want to change it only for the current shell session, do:

  1. export LANG=C

If you want to change the default value, modify the /etc/sysconfig/i18n file.

If your default LANG environment variable was set to something like en_US.UTF-8, you can reduce shell (bash) startup time up to ~15% with LANG=C.

Container tuning[edit]

CPU distribution inside container on SMP hosts[edit]

If the total number of containers in your host is more than CPUs number, and there are many threads running inside each container it is better to give just a single VCPU to each container. In this case thread memory locality will significantly reduce overhead on SMP memory coherence and overall performance can be increased up to ~50-100%!

To set the number of CPUs available inside a container, use:

  1. vzctl set $CTID --cpus N

Network checksumming[edit]

RHEL 5 based kernel supports IP checksum offload. If network ethernet cards in your host support IP checksum offload then you can switch this feature on also for the virtual network devices (venet, veth).

To check current offload setting for the hardware ethernet card (eth0, for instance) type

  1. ethtool -k eth0

Make sure that tx/rx features are switched on.

To see current offload settings for the venet0 device, type

  1. ethtool -k venet0

To set offload settings on for the venet0 device, type

  1. ethtool -K venet0 tx on sg on

Note, that 'tx on/off' enables/disables both tx and rx checksumming features for the all venet devices for all containers and HN.

The same applies to the veth device except that 'tx on/off' enables/disables tx and rx checksumming features for only given virtual ethernet device in HN and corresponding container.

Shell scripts performance improvement[edit]

Please note, that on container creation the default LANG value will be the same as in the HW node. So you can tune it in node (see #Shell scripts performance improvement above), or set it in container the same way.

The second important thing is the locale cache. On rpm based distributions, usually it is created by the glibc-common-XXX.rpm post install script and it can be up to 50 MBytes on some distributions. So on some container templates it can be missed to save disk space. But you can always create it inside container later by the following command (you must be the root user):

  1. build-locale-archive

And again, in some cases shell (bash) startup time can be reduced up to ~15%. </translate>