A large server traffic, because the program needs, the expiration of the session set is 3 hours, resulting in/tmp accumulation of nearly 200,000 of the session file. This leads to a sharp increase in the CPU consumed by the kernel. Because session reading and writing involves a lot of small files of random read and write, and is concentrated in a directory, iowait also increased dramatically.
First consider putting the session into memory
The easiest way to do this is to mount/tmp as a TMPFS file system, which is in-memory
The second step is to store the session in a directory that is not in use
PHP itself supports multilevel hashing of sessions
In PHP.ini, the
; Session.save_path =/tmp |
To
Session.save_path = "2;/tmp/session" |
Indicates that the session is stored in the/tmp/session folder and is in 2 and hashed columns.
Save exit and restart PHP after step three
Step three, create the session storage folder
PHP does not automatically create these folders, but it provides a few scripts for creating folders in the source file. The following script is also useful
i= "0 1 2 3 4 5 6 7 8 9 a B c D E F" For the ACM in $I; Todo for x in $I; Todo Mkdir-p/tmp/session/$ACM/$x; Done Done Chown-r nobody:nobody/tmp/session Chmod-r 1777/tmp/session
|
Because/TMP is the memory used, after the server restarts, all the files inside will be lost, so you need to add the above script to the/etc/rc.local and put it before starting PHP
The fourth step, the recovery of the session
Session after Session.gc_maxlifetime will expire, but will not be immediately deleted, long time will cause the/TMP space occupy very large. The specific deletion algorithm is too lazy to study. The following command deletes an expired session, and the expiration time I define here is 3 hours.
Find/tmp/session-amin +180-exec rm-rf {} \; |
Put it in Cron and run it 10 minutes.