Public bug reported: The php5 file-based session cleaner script /var/lib/php5/sessionclean is extremely expensive, taking over 10 seconds to run on my laptop, even when no PHP file-based session storage is enabled and the system is idle. My servers, on the other hand, are completely overwhelmed by this script, which runs every 30 minutes by default.
The script performs an lsof +d /var/lib/php5, which can itself take several minutes on my servers when they serving peak traffic of about 500 req/sec. This lsof command is extremely expensive (imagine iterating 5000 threads/procs, each of which has dozens or hundreds of open files). As a result of the load of this command, the server's connections back up leading to an out of memory condition (OOM) at which point the kernel tells oom_killer to start killing processes. The really kicker here is that my session management is not done with files (most high-performance PHP sites would not be), so all this work is done in vain. As a subject-matter expert in PHP and GNU/Linux, I recommend we update /usr/lib/php5/sessionclean and add /usr/lib/php5/sessionstorage New versions: https://gist.github.com/kamermans/27218b1a6dd61756b647 The new sessionstorage script simply prints out which session.save_handlers are enabled in the installed PHP versions (not including the cli). The improved sessionclean script uses the sessionstorage to run only if the "files" session.save_handler is enabled, thus removing the lsof burden on most high-performance servers. Note that I am doing some creative scripting since Bash-style arrays are not available in Dash. For reference, I am running on AWS c3.xlarge instances with NGINX, PHP5-FPM and Redis (no MySQL, no sessions at all). sessionclean kills my instances when the total CPU usage is around 20% (where 100% is a load of 4.0 on my 4-vCPU server), so I have a lot more room for requests if this is fixed. ProblemType: Bug DistroRelease: Ubuntu 14.04 Package: php5-common 5.5.9+dfsg-1ubuntu4.3 ProcVersionSignature: Ubuntu 3.13.0-29.53-generic 3.13.11.2 Uname: Linux 3.13.0-29-generic x86_64 ApportVersion: 2.14.1-0ubuntu3.3 Architecture: amd64 Date: Tue Aug 12 23:46:17 2014 Ec2AMI: ami-62a2730a Ec2AMIManifest: (unknown) Ec2AvailabilityZone: us-east-1c Ec2InstanceType: c3.xlarge Ec2Kernel: aki-919dcaf8 Ec2Ramdisk: unavailable ProcEnviron: TERM=xterm PATH=(custom, no user) XDG_RUNTIME_DIR=<set> LANG=en_US.UTF-8 SHELL=/bin/bash SourcePackage: php5 UpgradeStatus: Upgraded to trusty on 2014-07-30 (13 days ago) modified.conffile..etc.cron.d.php5: [modified] mtime.conffile..etc.cron.d.php5: 2014-08-12T20:02:50.878339 ** Affects: php5 (Ubuntu) Importance: Undecided Status: New ** Tags: amd64 apport-bug ec2-images trusty -- You received this bug notification because you are a member of Ubuntu Server Team, which is subscribed to php5 in Ubuntu. https://bugs.launchpad.net/bugs/1356113 Title: PHP5 session clean cron job causes OOM To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1356113/+subscriptions -- Ubuntu-server-bugs mailing list Ubuntu-server-bugs@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-server-bugs