This is an old revision of the document!
How to enable CRIU
Summary
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 for the PHP processor. This will improve the performance of Litespeed for transactions which are commonly used and reduce the memory overhead on the server.
Must
- Running as the root user to use CRIU Litespeed or Apache. The CRIU facility requires Litespeed run as the root user to perform the snapshot and recovery. Running as a non-root user automatically disables CRIU.
- CloudLinux System
Installation
1. CRIU enabled from System
Login your Linux system. Check CRIU service is running or not.
If not, enable by following method
systemctl enable criu systemctl start criu systemctl status criu
Output Active: active (running)
2. CRIU parameter check
Generally PHP should be compiled with criu already.
Through phpinfo()
to check LSPHP build with parameter: -DWITH_CRIU
.
If you want to manually compile, please download LSAPI from here
3. php env config
Add 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 image dump generated, you should see an image folder under
/var/run/lsws/cl_criu/
Step 3
- Check PHP process number by
ps -ef | grep php
user 868577 … 10:54 0:00 lsphp
- Kill the lsphp process
kill -9 868577
Step 4
- To restore the PHP by refreshing the WordPress page to regenerate it
- Verify the process number is same as before
ps -ef | grep php
user 868577 … 10:55 0:00 lsphp
Process is back!! - You can also check standard error log
LSCRIU: Successful CloudLinux dump of PID: 868577
LSCRIU: Successful CloudLinux restore of PID: 868577, parent: 1.
Logs
- Error log default locate at Apache standard error log
- dump.log is in the images directory
- restore.log is in the images directory
- restore.log will gets generated even though there is no dump, so it's expected to see some related fail logs