Mod_lsapi, number of processes and EP explained

Apache mod_lsapi is a great replacement for suPHP/FCGI engines.

This article uncovers more about how lsphp works on a server by means of processes.

 

The scheme is that each time a process ‘enters’ into LVE, we increment the EP counter. Each time a process exits LVE, we decrement the counter. We don’t count processes that are created inside LVE itself.

When we talk about lsapi, the following image can explain more:

For the real request we have several processes:
– Apache process that accepts a connection, it is actually one that increases EP, it does lve_enter.
lsphp parent process (one per VirtualHost), which starts lsphp backends.
lsphp backend process that actually processes requested PHP file.

Please review the results with a simple sleep.php script with sleep(30); inside presented below. The processes for single opening are:

We have one EP here and three NPROC .  Where Apache creates lsapi master process and it creates lsphp workers like on a screenshot above.

When opening URL two times simultaneously you can see the following:

We have two EPs and five NPROCs, which is normal as parent lsphp is one per VirtualHost.

If, for example, our PHP script creates another process (sending mail, etc.) the EP will remain the same as PHP script is already executed inside LVE. However, the number of processes for this LVE will increase.

That is why NPROC should be higher than EP.

There is no way to limit the number of parent PHP processes, it is only one per VirtualHost (not per account!).

To keep users within limits you have to combine lsapi_backend_children with LVE NPROC/EP limits.

 

Each lsphp worker process ends after the request is being processed. Turning “connection_pool_mode On”  in lsapi config makes lsphp workers not to end – they stay alive for lsapi_backend_max_idle time, or until lsapi_backend_max_reqs is reached (or Apache restarted).

All requests for every virtual host are spread across Apache worker almost equally. Connection pool grants faster processing mode, however, it will cause a higher number of processes per LVE (nproc) and a bit higher memory usage.

Leave a Reply

Your email address will not be published. Required fields are marked *