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.
Environment
- LVE
- mod_lsapi
Solution
Each time a process 'enters' into LVE, the EP counter is incremented. Each time a process exits LVE, the counter decreases. Processes that are created inside LVE itself are not taken into account. 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:
# lveps -p ID EP PNO COM TNO TID CPU MEM DT DO bogdan1 1 3 --- 3 --- 0 15 39340 1865 --- --- lsphp:/home/bogdan1/publ --- 271509 0 4 N/A N/A --- --- lsphp --- 271508 0 4 N/A N/A --- --- /usr/sbin/httpd -k start --- 271024 0 4 N/A N/A
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:
# lveps -p ID EP PNO COM TNO TID CPU MEM DT DO bogdan1 2 5 --- 5 --- 0 20 39340 1865 --- --- lsphp:/home/bogdan1/publ --- 271518 0 4 N/A N/A --- --- lsphp:/home/bogdan1/publ --- 271509 0 4 N/A N/A --- --- lsphp --- 271508 0 4 N/A N/A --- --- /usr/sbin/httpd -k start --- 271043 0 4 N/A N/A --- --- /usr/sbin/httpd -k start --- 271024 0 4 N/A N/A
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 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.
Comments
0 comments
Please sign in to leave a comment.