Linux performance tuning

November 15, 2009

I grabbed this from a page, I haven’t confirmed any of it yet.


1) If you are tuning a heavy Apache compiled with a script interpreter (perl, php, python…) and lots of preloaded scripts (this is the case where lingerd comes the most useful), make sure you serve your images and other static content separately, from another server (running on the same machine or not).

This can be a lightweight Apache configured without any scripting, or even better, a copy of thttpd ( or boa ( Just put the image server on another IP address or port, and change your IMG tags to point to the right hostname (statically or dynamically).

2) If you’ve been able to offload image serving to a separate server, turn off KeepAlives on the dynamic page server. KeepAlives tie an Apache process to a specific client for a few seconds, which is long enough to increase the server’s load considerably, and short enough to be useless now that your images are coming from a separate server.

More importantly, KeepAlives and lingering_close are the main slowdown points for Apache processes; getting rid of one will speed up Apache a bit, whereas getting rid of both will have a much more dramatic effect.

3) Increase your kernel’s tcp/ip write buffers so that most, if not all generated pages can be written without blocking. If the page that Apache generates fits in this buffer, then Apache’s write() call returns instantaneously, then Apache hands the socket over to lingerd, logs the hit, and is immediately free for more work. If the page doesn’t fit, then write() blocks until the client has acknowledged part of the data, which can take several seconds.

To change this, use the SendBufferSize directive from httpd.conf. However, this directive cannot increase the buffer size past the kernel limit. Changing this kernel limit is OS-specific.

Under Linux you can set it by echo’ing a larger number (eg. 131072) into /proc/sys/net/core/wmem_max, before starting Apache. If you change wmem_default as well as wmem_max, then the SendBufferSize directive is not needed.

4) If you’re handling extremely high loads (500 connections per second and above on a single machine), make sure that the hard limit on open descriptors for the lingerd process is high enough (it should be at least twice the peak number of connections per second).

On Linux, the hard limit for a given process can be set (eg. to 2048) by running the bash command “ulimit -H -n 2048” as root, and the system-wide total of available descriptors can be set by echo’ing a number into /proc/sys/fs/file-max.

Lingerd regularily sends some statistics to syslog, including the number of open file descriptors in use.

FIXME: instructions for FreeBSD, OpenBSD, Solaris?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: