This is an old revision of the document!
How to Enable LSPHP CRIU on CloudLinux
Checkpoint/Restore In Userspace, or CRIU, is an open source project which dumps all of the information of a running process to disk and restores it at the point of the dump. The LiteSpeed Enterprise Edition Web Server now supports CRIU both natively, and for the CloudLinux/Apache-specific implementation of the PHP processor. This will improve the performance of LiteSpeed for transactions which are commonly used, and reduce the memory overhead on the server.
Requirements
- CloudLinux System
- LiteSpeed must be running as the root user to use CRIU Litespeed or Apache. Root is required in order to perform the snapshot and recovery. Running as a non-root user automatically disables CRIU.
Installation
1. Verify CRIU is enabled on your system
Log into your Linux system. Check CRIU whether the service is running or not.
If not, enable by following method:
systemctl enable criu systemctl start criu systemctl status criu
Output should be Active: active (running)
.
2. Check CRIU parameters
Generally PHP should be compiled with CRIU already.
Use phpinfo()
with parameter -DWITH_CRIU
to check the LSPHP build.
If you want to manually compile, please download LSAPI from here
3. Configure the PHP environment
Add the following necessary parameter to the PHPx.x External App > Environment
LSAPI_CRIU=1
Important Syntax
Variable | Values | Default | Description |
---|---|---|---|
LSAPI_CRIU | 1/On/Off | Off | If set to On, CRIU will be performed. 1=On |
LSAPI_INITIAL_START | A number from 1 upwards. | 15 | The number of consecutive calls which must be made within a single PHP instance before a dump of the instance will be made. If there’s no PHP instance running and there’s a dump on disk it will be restored on the first use. |
LSAPI_CRIU_IMGS_DIR_PATH | Any valid, existing directory | /var/run/lsws/cl_criu/ | CRIU images will start from this directory; a subdirectory named “images” will be created below and then a directory for each user's type of request. There needs to be lots of free space in this file system. |
LSAPI_CRIU_DEBUG | On/Off | Off | If set to On , messages concerning CRIU processing will be written to the stderr.log file (usually in /usr/local/apache2/logs/stderr.log) |
How to Verify
Step 1
- Prepare any PHP site, e.g. WordPress
Step 2
- Generate the dump by hitting the WordPress site
- Hit more than INITIAL_START number, e.g. 20 times
- If an image dump is generated, you should see an image folder under
/var/run/lsws/cl_criu/
Step 3
- Check the PHP process number by
ps -ef | grep php >>> user 868577 ... 10:54 0:00 lsphpL
- Kill the lsphp process via
kill -9 868577
Step 4
- Restore the PHP by refreshing the WordPress page to regenerate it
- Verify the process number is the same as before:
ps -ef | grep php >>> user 868577 ... 10:55 0:00 lsphp
The process is back!!
- You can also check standard error log for something like
LSCRIU: Successful CloudLinux dump of PID: 868577 LSCRIU: Successful CloudLinux restore of PID: 868577, parent: 1.
Logs
- Error log default located at Apache standard error log
dump.log
is in the images directoryrestore.log
is in the images directory
NOTE: restore.log
is generated even when there is no dump, so it's expected to see some related fail logs