Ubuntu 18+의 PHP 7.3 mmap munmap 호출이 너무 많습니다\시간

Ubuntu 18+의 PHP 7.3 mmap munmap 호출이 너무 많습니다\시간

오늘은 좋은 날이다. 로드가 높은 백엔드 PHP 서버를 새 서버로 마이그레이션한 후 문제가 발생했습니다. (투자). 이를 위해 우분투 16과 20을 비교하기 시작했습니다(18은 동일합니다).

유사한 m5.large aws 인스턴스 2개를 구입하고 간단히 확인했습니다.

간단한 스크립트strace -c php -r " exit(1);"

이것은 나에게 준다

ubuntu@ip-172-31-40-209:~$ sudo uname -srm
Linux 5.4.0-1009-aws x86_64
ubuntu@ip-172-31-40-209:~$ sudo php --version
PHP 7.3.17-1+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Apr 28 2020 14:49:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.17-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
ubuntu@ip-172-31-40-209:~$ sudo sysctl -a | grep vm.nr_hugepages
vm.nr_hugepages = 0
vm.nr_hugepages_mempolicy = 0
ubuntu@ip-172-31-40-209:~$ cat /sys/kernel/mm/transparent_hugepage/enabled
always [madvise] never
ubuntu@ip-172-31-40-209:~$ cat /sys/kernel/mm/transparent_hugepage/defrag
always defer defer+madvise [madvise] never


% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 31.94    0.002967          18       157           munmap
 27.64    0.002567           4       549         1 mmap
 12.12    0.001126           6       173           mprotect
  9.32    0.000866           4       182         5 openat
  4.86    0.000451           3       135         1 read
  4.35    0.000404           2       182           close
  3.63    0.000337           1       181           fstat
  1.48    0.000137           6        20           futex
  1.02    0.000095           3        26           brk
  0.74    0.000069          69         1           poll
  0.60    0.000056           0        85           rt_sigaction
  0.54    0.000050           4        11           fcntl
  0.36    0.000033           8         4           write
  0.25    0.000023          11         2           writev
  0.18    0.000017           2         8           getpid
  0.17    0.000016           4         4           uname
  0.12    0.000011          11         1           sysinfo
  0.12    0.000011           3         3           getrandom
  0.11    0.000010          10         1           connect
  0.10    0.000009           0        40         1 stat
  0.06    0.000006           6         1           unlink
  0.06    0.000006           6         1           fchmod
  0.05    0.000005           2         2           socket
  0.04    0.000004           2         2           gettid
  0.03    0.000003           1         2           rt_sigprocmask
  0.03    0.000003           1         3         2 access
  0.02    0.000002           2         1           getegid
  0.01    0.000001           1         1           getuid
  0.01    0.000001           1         1           getgid
  0.01    0.000001           1         1           geteuid
  0.01    0.000001           1         1           getppid
  0.00    0.000000           0         8         3 lstat
  0.00    0.000000           0        43         3 lseek
  0.00    0.000000           0        39        39 ioctl
  0.00    0.000000           0         8           pread64
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         1           getcwd
  0.00    0.000000           0         2           readlink
  0.00    0.000000           0         3           getrusage
  0.00    0.000000           0         2         1 arch_prctl
  0.00    0.000000           0         2           getdents64
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         1           set_robust_list
  0.00    0.000000           0         2           prlimit64
------ ----------- ----------- --------- --------- ----------------
100.00    0.009288                  1894        56 total

https://gist.github.com/futureisrise/46cc3d0bb55e612038fb7a95bc5efbfa추적 호출을 완료하세요.

동일한 스크립트가 우분투 16에서 실행됩니다.

ubuntu@ip-172-31-44-252:~$ sudo uname -srm
Linux 4.4.0-1105-aws x86_64
ubuntu@ip-172-31-44-252:~$ sudo php -v
PHP 7.3.17-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr 19 2020 07:44:05) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.17-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

ubuntu@ip-172-31-44-252:~$sudo sysctl -a | grep vm.nr_hugepages
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.ens5.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.nr_hugepages = 0
vm.nr_hugepages_mempolicy = 0
ubuntu@ip-172-31-44-252:~$ cat /sys/kernel/mm/transparent_hugepage/enabled
always [madvise] never
ubuntu@ip-172-31-44-252:~$ cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never


% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  0.00    0.000000           0        46           read
  0.00    0.000000           0        69         3 open
  0.00    0.000000           0        69           close
  0.00    0.000000           0        20           stat
  0.00    0.000000           0        73           fstat
  0.00    0.000000           0         8         3 lstat
  0.00    0.000000           0        24         3 lseek
  0.00    0.000000           0       130           mmap
  0.00    0.000000           0        81           mprotect
  0.00    0.000000           0        52           munmap
  0.00    0.000000           0        12           brk
  0.00    0.000000           0        80           rt_sigaction
  0.00    0.000000           0         2           rt_sigprocmask
  0.00    0.000000           0        20        20 ioctl
  0.00    0.000000           0        24        23 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         2           getdents
  0.00    0.000000           0         1           getcwd
  0.00    0.000000           0         2           readlink
  0.00    0.000000           0         2           getrlimit
  0.00    0.000000           0         1           sysinfo
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0        19           futex
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         1           clock_getres
  0.00    0.000000           0         1           set_robust_list
  0.00    0.000000           0         2           getrandom
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                   744        52 total

자세한 내용은 여기https://gist.github.com/futureisrise/de0a54d28e794c4d9bff714a1cbd21e1

보시다시피 우분투 16은 몇 배 더 빠릅니다. 또한 blackfire io, newrelic 등으로 테스트했습니다. DDOS 공격이 있을 경우 - 서버 CPU 부하가 매우 높습니다.

이 테스트를 명확하게 하기 위해 - 방금 설치했습니다.

add-apt-repository ppa:ondrej/php
apt update
apt install strace php7.3 php7.3-cli

관련 정보