【问题标题】:fuser process php5 cron job using high amounts of cpufuser 使用大量 cpu 处理 php5 cron 作业
【发布时间】:2014-01-11 14:51:02
【问题描述】:

我们看到服务器的 CPU 每隔 30 分钟就会出现一次峰值。这可能是由 php5 作业清理会话文件引起的。这是从我们服务器上的 /etc/cron.d/php5 获取的:

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -ignore_readdir_race -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

在过去的版本中,这项工作似乎存在问题。 Ubuntu 11.10 版本存在问题,这占用了大量 CPU,但我们正在运行 Ubuntu 和 PHP 的更晚版本。 这份工作对 PHP 来说有多重要?我们可以阻止这个作业运行或降低它的优先级吗?

【问题讨论】:

  • 仅仅因为 CPU 出现峰值并不意味着有必要担心。这些文件必须在某个时候进行清理,此时最好尽快清理它们,使用尽可能多的资源来完成工作。你是说这项工作对服务器征税不合理
  • 它可能很好地利用了资源,但问题是这项工作需要 2 分钟左右才能完成,并且在高峰时间额外使用 cpu 可能会阻止我们在此期间响应请求。

标签: php amazon-ec2 cron cpu


【解决方案1】:

这是一个错误,它似乎与 pmisc 包有关,但当 php5-apc 正常运行时,它也是 php5 的一部分。
这里提到了一个 ubuntu 错误报告和建议的解决方法: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/876387

09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete

这里有一份 Debian 错误报告: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=633100

我已经在 debian wheezy 上测试了解决方法,它可以工作,尽管更新软件包会更好!

【讨论】:

    【解决方案2】:

    使用 find 和 fuser 反复递归地从文件系统中抓取垃圾通常是一个坏主意。

    不再将会话存储在文件中,您可以立即摆脱这个问题以及许多其他问题(如果还没有解决的话)。如果您实际上没有为会话使用文件存储,只需删除该行(或注释掉)。

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      • 2015-12-13
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多