【问题标题】:php process LD_LIBRARY_PATH big cpu usagephp进程LD_LIBRARY_PATH大cpu使用率
【发布时间】:2013-02-27 15:44:45
【问题描述】:

我正在寻找 PHP 进程使用这么多 CPU 的原因,服务器是 Apache mpm worker + suphp 下面是'strace php'的一些输出,如你所见,进程在'不正确'路径中寻找dso,这些只是编译的PHP扩展,有没有办法将搜索路径指定为'/lib64:/ usr/lib64' ? 因为我发现它最终在 lib64 或 /usr/lib64 中加载了 dso,经过多次否定路径尝试,这是系统 CPU 消耗,你知道,很多系统调用都是徒劳的。提前致谢。

open("/opt/xslt/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xml2/lib/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/php_with_imap_client//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xslt//lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libselinux.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libselinux.so.1", O_RDONLY) = 3

open("/opt/xslt/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xml2/lib/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/php_with_imap_client//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xslt//lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libsepol.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libsepol.so.1", O_RDONLY)  = 3
open("/opt/xslt/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/mysql/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xml2/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/pcre/lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/curlssl//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/php_with_imap_client//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/libmcrypt//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/mhash//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/tidy//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/xslt//lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libnss_files.so.2", O_RDONLY) = 3

我的意见正确吗?还是以下原因导致 CPU 使用率高?

lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0    
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0
stat("/home/socialth/public_html/index.php", {st_mode=S_IFREG|0644, st_size=1971, ...}) = 0
access("/home/socialth/public_html/components/com_content/router.php", F_OK) = 0
lstat("/home", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth", {st_mode=S_IFDIR|0711, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/home/socialth/public_html/components/com_content/router.php", {st_mode=S_IFREG|0644, st_size=8157, ...}) = 0

【问题讨论】:

  • 你想在这里做什么?我所看到的只是一堵系统调用。
  • 我怀疑 php 进程在这些调用中花费了很多 CPU 成本

标签: php system-calls strace


【解决方案1】:

您对此无能为力,尤其是因为所有这些软件包都已将它们自己安装在它们自己的小目录树中。虽然 /opt 是一个很好的概念,可以将整个包相互隔离,但这确实意味着任何为系统其余部分提供共享库的包都必须放入库搜索路径中,你最终会得到长时间无意义的打开/ stat 在搜索任何共享库时调用。您可以做的唯一优化可能是重新排列路径,以便不经常使用的库位于搜索路径的末尾,这样点击就会“更快”出现,并且不会浪费时间检查很少使用的区域。

同样适用于您的 PHP 自动加载器。通向任何特定文件的长统计链也是必要的,因为系统会在每个阶段检查访问权限。

顺便说一句,这就是不鼓励使用 .htaccess 文件的确切原因。启用 .htaccess 后,Apache 必须检查通向请求文件的每个目录是否存在 .htaccess 文件。如果文件存在,则必须加载/解析/等...所有这些都会浪费大量的 CPU 周期和磁盘带宽。

.htaccess 在开发/测试时很好,但是一旦你有一个可以工作的设置, .htaccess 指令应该被转移到主服务器 .conf 文件,所以它们只在服务器启动时加载/解析一次.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 2020-09-16
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多