My php-fpm process is facing performance issues on Ubuntu 14.04 LTS (Nginx server, MariaDB database).
strace -f $(pidof php-fpm7.1 | sed 's/\([0-9]*\)/\-p \1/g')
Gave me
<... 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
I tried with php-fpm7.0, PHPMod7.1 but same issues.
CPU is up to 100% on requests with a small amount of data.
Configurations are the default ones.
On a duplicated instance php5.6-fpm works well.
Edit: Possibly related PHP script keeps doing mmap/munmap
Edit: I tried to enable hugepages https://wiki.debian.org/Hugepages
A cat /proc/meminfo | grep Huge
gave me
AnonHugePages: 108544 kB
HugePages_Total: 512
HugePages_Free: 497
HugePages_Rsvd: 50
HugePages_Surp: 0
Hugepagesize: 2048 kB
but still the same issue.
Edit: I tried to enable/disable OPCache, also set opcache.huge_code_pages=0
, no results. There is no documentation about hugepages on http://php.net/
mmap()
/munmap()
directly, or is it throughmalloc()
/free()
? If it's throughmalloc()
/free()
, you can try setting theM_MMAP_THRESHOLD
environment variable to the equivalent of something like 4MB or 8MB so the process uses "normal" heap memory for the 2MB allocations you're seeing. See themallopt()
man page for details. – Asbestosismmap
/munmap()
directly. – Calvariavoid *
to anunsigned long
to try aligning the resulting pointer. Avoid *
doesn't necessarily fit into along
. The linked code will fail on 64-bit Windows, for example, hardly an uncommon platform.. See en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models – Asbestosis