色々調べると、GuzzleHttpがHTTPSで通信する際に増えるらしい
まとめ
- AWS SDKのクライアント、GuzzleHttpも最終的にphpの
curl_~関数を呼んでいる
※constructorでcurlが無い場合、Exception吐くコードがあるし、AWSの要件にもcurlが入っている - php curl の nssは多分、ビルドされたcurlのNSSバージョンに依存し
てそう
※curl -V のNSS/3.27 の部分 - curlをmakeすると、その時のOSのnssバージョンが
組み込まれた
curl 7.19.7 (x86_64-unknown-linux-gnu) libcurl/7.19.7 NSS/3.36 - かつ、その際、nss-softokn-3.14.3-23.
3.el6_8.x86_64 で、curlコマンドのNSS_SDB_USE_CACHE=y es は有効だった - phpのcurlバージョンは、コマンドと同じくlibcur
lに依存してそうだが、curl_version(); 又は、phpinfo(); で確認できる
各種情報
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@ip-172-31-16-82 centos]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@ip-172-31-16-82 centos]# rpm -qa | grep nss-softokn nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64 nss-softokn-3.14.3-23.3.el6_8.x86_64 [root@ip-172-31-16-82 centos]# php -v PHP 5.5.38 (cli) (built: Mar 1 2018 11:12:35) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies [centos@ip-172-31-16-82 slab-nss]$ cat composer.json { "require": { "aws/aws-sdk-php": "^2.8" } } |
AWS-SDKでSNSへpublishするテストコードを準備
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php require_once('./vendor/autoload.php'); use Aws\Sns\SnsClient; $arn = "arn:aws:sns:ap-northeast-1:xxxxxx:aws-sdk-nss-dentry-test"; $message = 'dummy message'; $client = SnsClient::factory(array( 'profile' => 'default', 'region' => 'ap-northeast-1', )); for ($i = 0; $i < 100; $i ++) { $result = $client->publish(array( 'TopicArn' => $arn, 'Message' => $message )); } |
実行前後の情報
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[centos@ip-172-31-16-82 ~]$ sar -v 0 Linux 2.6.32-696.30.1.el6.x86_64 (ip-172-31-16-82.ap-northeast-1.compute.internal) 07/08/2018 _x86_64_ (1 CPU) 07:51:10 AM dentunusd file-nr inode-nr pty-nr 07:51:10 AM 41344 736 7227 5 [centos@ip-172-31-16-82 ~]$ sar -v 0 Linux 2.6.32-696.30.1.el6.x86_64 (ip-172-31-16-82.ap-northeast-1.compute.internal) 07/08/2018 _x86_64_ (1 CPU) 07:51:33 AM dentunusd file-nr inode-nr pty-nr 07:51:33 AM 61344 736 7227 5 [centos@ip-172-31-16-82 ~]$ slabtop -o | grep dentry 48140 48105 99% 0.19K 2407 20 9628K dentry [centos@ip-172-31-16-82 ~]$ slabtop -o | grep dentry 68100 68100 100% 0.19K 3405 20 13620K dentry [centos@ip-172-31-16-82 ~]$ free total used free shared buffers cached Mem: 499996 174200 325796 160 14212 53744 -/+ buffers/cache: 106244 393752 Swap: 1048572 1280 1047292 [centos@ip-172-31-16-82 ~]$ free total used free shared buffers cached Mem: 499996 178176 321820 160 14220 53744 -/+ buffers/cache: 110212 389784 Swap: 1048572 1280 1047292 |
dentunusedが増加し、dentryのslabが増加している。
buffers/cacheが減少している。
対策コードを追加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php putenv("NSS_SDB_USE_CACHE=yes"); // ★追加 require_once('./vendor/autoload.php'); use Aws\Sns\SnsClient; $arn = "arn:aws:sns:ap-northeast-1:xxxxxx:aws-sdk-nss-dentry-test"; $message = 'dummy message'; $client = SnsClient::factory(array( 'profile' => 'default', 'region' => 'ap-northeast-1', )); for ($i = 0; $i < 100; $i ++) { $result = $client->publish(array( 'TopicArn' => $arn, 'Message' => $message )); } |
実行前後の情報
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[centos@ip-172-31-16-82 ~]$ sar -v 0 Linux 2.6.32-696.30.1.el6.x86_64 (ip-172-31-16-82.ap-northeast-1.compute.internal) 07/08/2018 _x86_64_ (1 CPU) 07:55:05 AM dentunusd file-nr inode-nr pty-nr 07:55:05 AM 61349 736 7230 5 [centos@ip-172-31-16-82 ~]$ sar -v 0 Linux 2.6.32-696.30.1.el6.x86_64 (ip-172-31-16-82.ap-northeast-1.compute.internal) 07/08/2018 _x86_64_ (1 CPU) 07:55:15 AM dentunusd file-nr inode-nr pty-nr 07:55:15 AM 61349 736 7230 5 [centos@ip-172-31-16-82 ~]$ slabtop -o | grep dentry 68120 68110 99% 0.19K 3406 20 13624K dentry [centos@ip-172-31-16-82 ~]$ slabtop -o | grep dentry 68160 68136 99% 0.19K 3408 20 13632K dentry [centos@ip-172-31-16-82 ~]$ free total used free shared buffers cached Mem: 499996 178300 321696 160 14292 53844 -/+ buffers/cache: 110164 389832 Swap: 1048572 1280 1047292 [centos@ip-172-31-16-82 ~]$ free total used free shared buffers cached Mem: 499996 178300 321696 160 14300 53844 -/+ buffers/cache: 110156 389840 Swap: 1048572 1280 1047292 |
ほぼ増加しなくなったことがわかる。
nss-softokn-3.14.3-23.3.el6_8 の環境でも効果がありそうだ。
GuzzleHttp
コードを追っていくと、内部でphp curlを使っているようだ
1 2 3 4 5 |
if (!extension_loaded('curl')) { // @codeCoverageIgnoreStart throw new RuntimeException('The PHP cURL extension must be installed to use Guzzle.'); // @codeCoverageIgnoreEnd } |
curl と nss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[centos@ip-172-31-16-82 slab-nss]$ php -r "phpinfo();" | grep "^curl" -A24 PHP Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Command line code on line 1 curl cURL support => enabled cURL Information => 7.19.7 Age => 3 Features AsynchDNS => No CharConv => No Debug => No GSS-Negotiate => Yes IDN => Yes IPv6 => Yes krb4 => No Largefile => Yes libz => Yes NTLM => Yes SPNEGO => No SSL => Yes SSPI => No Protocols => tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps, scp, sftp Host => x86_64-redhat-linux-gnu SSL Version => NSS/3.27.1 ZLib Version => 1.2.3 libSSH Version => libssh2/1.4.2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[centos@ip-172-31-16-82 slab-nss]$ php -r "print_r(curl_version());" Array ( [version_number] => 463623 [age] => 3 [features] => 1597 [ssl_version_number] => 0 [version] => 7.19.7 [host] => x86_64-redhat-linux-gnu [ssl_version] => NSS/3.27.1 [libz_version] => 1.2.3 [protocols] => Array ( [0] => tftp [1] => ftp [2] => telnet [3] => dict [4] => ldap [5] => ldaps [6] => http [7] => file [8] => https [9] => ftps [10] => scp [11] => sftp ) ) |
NSS/3.27.1 が使われているようだ。
osにinstallされているnss-softknは使われていない?
curlをmakeして確かめてみる
同じバージョンをインストール
1 2 3 4 5 6 7 8 9 10 11 |
# cd /usr/local/src/ # curl -O https://curl.haxx.se/download/archeology/curl-7.19.7.tar.gz # tar xvzf curl-7.19.7.tar.gz # cd curl-7.19.7 # yum install gcc g++ # yum install nspr-devel # yum install nss-devel # ./configure --with-nss --disable-manual # make |
システムのnssが使われた事の確認と効果の確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@ip-172-31-16-82 curl-7.19.7]# rpm -qa | grep nss nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64 nss-util-3.36.0-1.el6.x86_64 nss-softokn-freebl-devel-3.14.3-23.3.el6_8.x86_64 nss-sysinit-3.36.0-8.el6.x86_64 nss-devel-3.36.0-8.el6.x86_64 openssh-server-5.3p1-123.el6_9.x86_64 nss-util-devel-3.36.0-1.el6.x86_64 nss-softokn-devel-3.14.3-23.3.el6_8.x86_64 nss-3.36.0-8.el6.x86_64 nss-tools-3.36.0-8.el6.x86_64 nss-softokn-3.14.3-23.3.el6_8.x86_64 openssl-1.0.1e-57.el6.x86_64 openssh-5.3p1-123.el6_9.x86_64 openssh-clients-5.3p1-123.el6_9.x86_64 [root@ip-172-31-16-82 curl-7.19.7]# ./src/curl -V curl 7.19.7 (x86_64-unknown-linux-gnu) libcurl/7.19.7 NSS/3.36 Protocols: tftp ftp telnet dict http file https ftps Features: IPv6 Largefile SSL [root@ip-172-31-16-82 curl-7.19.7]# strace -fc -e trace=access ./src/curl -s https://www.google.co.jp/ > /dev/null Process 28940 attached Process 28941 attached Process 28942 attached Process 28943 attached Process 28944 attached Process 28946 attached Process 28945 attached Process 28947 attached Process 28949 attached Process 28948 attached Process 28950 attached Process 28951 attached Process 28953 attached Process 28952 attached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 938 926 access ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 938 926 total [root@ip-172-31-16-82 curl-7.19.7]# NSS_SDB_USE_CACHE=yes strace -fc -e trace=access ./src/curl -s https://www.google.co.jp/ > /dev/null Process 29010 attached Process 29011 attached Process 29012 attached Process 29014 attached Process 29015 attached Process 29017 attached Process 29016 attached Process 29018 attached Process 29020 attached Process 29019 attached Process 29021 attached Process 29022 attached Process 29024 attached Process 29023 attached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 24 12 access ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 24 12 total |
nss-softokn-3.14.3-23.3 で nss-softokn-3.14.3-23.3 が使えているだろうと思われる。