我的php-fpm进程在Ubuntu 14.04 LTS上(Nginx服务器,MariaDB数据库)面临性能问题。
strace -f $(pidof php-fpm7.1 | sed 's/\([0-9]*\)/\-p \1/g')
给了我。
<... epoll_wait resumed> {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, {}, 1, 103) = 0
[pid 32533] epoll_wait(8, <unfinished ...>
[pid 32535] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd933fdd000
[pid 32535] munmap(0x7fd933fdd000, 2097152) = 0
[pid 32535] mmap(NULL, 4190208, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd933dde000
[pid 32535] munmap(0x7fd933dde000, 139264) = 0
[pid 32535] munmap(0x7fd934000000, 1953792) = 0
[pid 32535] madvise(0x7fd933e00000, 2097152, MADV_HUGEPAGE) = 0
[pid 32533] <... epoll_wait resumed> {}, 1, 897) = 0
[pid 32533] epoll_wait(8, {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, <unfinished ...>
[pid 32535] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd933c00000
[pid 32535] madvise(0x7fd933c00000, 2097152, MADV_HUGEPAGE) = 0
[pid 32533] <... epoll_wait resumed> {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, <unfinished ...>
[pid 32535] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd933a00000
[pid 32535] madvise(0x7fd933a00000, 2097152, MADV_HUGEPAGE) = 0
[pid 32533] <... epoll_wait resumed> {}, 1, 1000) = 0
[pid 32533] epoll_wait(8, <unfinished ...>
[pid 32535] open("/usr/share/zoneinfo/UTC", O_RDONLY) = 7
[pid 32535] fstat(7, {st_mode=S_IFREG|0644, st_size=118, ...}) = 0
[pid 32535] read(7, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) = 20
[pid 32535] lseek(7, 0, SEEK_SET) = 0
[pid 32535] mmap(NULL, 118, PROT_READ, MAP_SHARED, 7, 0) = 0x7fd946835000
[pid 32535] close(7) = 0
[pid 32535] munmap(0x7fd946835000, 118) = 0
[pid 32535] pwrite(5, "_sf2_attributes|a:2:{s:14:\"_secu"..., 979, 0) = 979
[pid 32535] close(5) = 0
[pid 32535] mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd933200000
[pid 32535] madvise(0x7fd933200000, 2097152, MADV_HUGEPAGE) = 0
我尝试使用php-fpm7.0和PHPMod7.1,但是出现了相同的问题。
CPU使用率在处理少量数据的请求时达到了100%。
配置是默认的。
在一个复制的实例上,php5.6-fpm运行良好。
编辑:可能相关的PHP脚本一直在执行mmap/munmap
编辑:我尝试启用hugepages https://wiki.debian.org/Hugepages
cat /proc/meminfo | grep Huge
给了我以下结果:
AnonHugePages: 108544 kB
HugePages_Total: 512
HugePages_Free: 497
HugePages_Rsvd: 50
HugePages_Surp: 0
Hugepagesize: 2048 kB
但问题仍然存在。
编辑:我尝试启用/禁用OPCache,并设置opcache.huge_code_pages=0
,但没有结果。在http://php.net/上没有关于hugepages的文档。
mmap()
/munmap()
,还是通过malloc()
/free()
?如果是通过malloc()
/free()
,你可以尝试将M_MMAP_THRESHOLD
环境变量设置为类似于4MB或8MB的等效值,这样进程就会使用“正常”的堆内存来处理你看到的2MB分配。有关详细信息,请参见mallopt()
手册页面。 - Andrew Henle