I have a strange problem. On an amazon m4.large with nginx and php-fpm , that sits behind a loadbalancer and with a memcached and s3 bucket when the visitors reach certain number, the CPU of the instance hits almost 97% for a short period of time. I have enabled the slow logging functionality of php-fpm and found multiple occurances of this:
script_filename = /var/www/xxx/web/app.php
[0x00007f231c23c6c0] curl_multi_select() /var/www/xxx/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php:101
[0x00007f231c23c560] tick() /var/www/xxx/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php:125
[0x00007f231c23c448] execute() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:246
[0x00007f231c23c338] invokeWaitFn() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:223
[0x00007f231c23c208] waitIfPending() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:267
[0x00007f231c23c0d8] invokeWaitList() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:225
[0x00007f231c23bfa8] waitIfPending() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:267
[0x00007f231c23be78] invokeWaitList() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:225
[0x00007f231c23bd48] waitIfPending() /var/www/xxx/vendor/guzzlehttp/promises/src/Promise.php:62
[0x00007f231c23bc08] wait() /var/www/xxx/vendor/aws/aws-sdk-php/src/AwsClientTrait.php:58
[0x00007f231c23bac0] execute() /var/www/xxx/vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php:319
[0x00007f231c23b998] getMetadata() /var/www/xxx/vendor/league/flysystem-aws-s3-v3/src/AwsS3Adapter.php:342
[0x00007f231c23b8a0] getSize() /var/www/xxx/vendor/league/flysystem/src/Filesystem.php:329
[0x00007f231c23b720] getSize() /var/www/xxx/vendor/league/glide-symfony/src/Responses/SymfonyResponseFactory.php:38
What i am trying to do is, to fetch an image from a S3 bucket. Both the instances from where i am executing this code and the bucket sit in the same aws zone. So the latency shall be pretty low. I have configured the aws-sdk-php with the following params:
timeout = 5
connect_timeout = 1
delay = 0
PHP and PHP-FPM are in version 5.6.36
this is an outtake from the php-fpm configuration:
pm = dynamic
pm.max_children = 505
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 135
pm.max_requests = 5000
The latency time of the loadbalancer peaks, when the visitors rise and the CPU load reaches ~97%. The RAM usage is pretty low though. Does someone had a similar problem with curl_multi_selection() taking so long?