Freebsd – Apache httpd processes in lockf state

apache-2.2freebsd

We run Apache on a FreeBSD system, it has multple web apps on it (WordPress, Magento, custom PHP). As the traffic increases, we see more and more httpd processes in status "lockf" (using 'top'). The server load increases until we have to restart Apache.

As I understand this state Apache waits for a file lock. But how can we find out which file(s) are to be locked / cause the bottleneck? Without that information, it seems very hard to tackle the problem.

Best Answer

It's an old question, but I'll give it a try ;)

This situation sounds like 'you have a slow drive' - but it's just a feeling without knowing more.

To answer the direct question (finding the used files), do the following: Check if you have lsof installed which lsof, if not installed install it by pkg(_install) (dunno which FreeBSD Version you have).

Then search for your http processes by top or ps and use lsof to see which files are used with lsof -p PROCNUMBER This gives you a table of ALL files/dirs/pipes etc. used by this process.

This can now be examined. Have a look at man lsof, it's very long and has much power.

Without knowing the result of what you find, try to reduce or even disable logging and see if this helps. Using the wrong logging setup and much traffic could kill even big machines. And a last note: If you have a good machine running such setup you described, the BIGGEST problem is drive I/O in many cases. Dual Xeon Superbig-CPU has no meaning if you still have an IDE drive ;)

One final resource which might be interesting: http://httpd.apache.org/docs/2.2/caching.html