0

I have a site running on aws But it stops working regularly. And once I restart PHP-fpm it starts working smoothly.

This is the error I am getting in error log when site throws 504 -

2308#2308: *3310 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 54.215.160.135, server: api.mysite.com, request: "POST /notfound HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock"

I tried solving this but unable to solve. I also tried re-installing PHP-FPM but not solved the problem.

here is my nginx conf file -

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

   fastcgi_intercept_errors off;
   fastcgi_buffer_size 16k;
   fastcgi_buffers 4 16k;
   fastcgi_connect_timeout 300;
   fastcgi_send_timeout 300;
   fastcgi_read_timeout 300;
    include fastcgi_params;
}

Also when I check status of FPM it shows -

  ● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-01-04 04:23:13 UTC; 1h 52min ago
       Docs: man:php-fpm7.2(8)
   Main PID: 2314 (php-fpm7.2)
     Status: "Processes active: 5, idle: 0, Requests: 1511, slow: 0, Traffic: 0req/sec"
      Tasks: 6 (limit: 1152)
     CGroup: /system.slice/php7.2-fpm.service
             ├─2314 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
             ├─3578 php-fpm: pool www
             ├─3579 php-fpm: pool www
             ├─3633 php-fpm: pool www
             ├─3784 php-fpm: pool www
             └─3786 php-fpm: pool www

In pool.d/www.conf

    user = nginx ##previously it was  www-data
    group = www-data
    listen.owner = nginx ##previously it was  www-data
    listen.group = nginx ##previously it was  www-data
    listen.mode = 0660
    listen = /run/php/php7.2-fpm.sock

How can I solve this issue?

Sunil Chhimpa
  • 404
  • 1
  • 4
  • 12
  • Well it looks like there are too many requests coming in and not enough worker processes to fulfill them. Next stop is to enable profiling for PHP-FPM somehow like https://stackoverflow.com/questions/15465333/php-fpm-processes-monitoring-profiling and see how long on average each request takes until the response – Daniel Protopopov Jan 04 '20 at 07:03
  • @DanielProtopopov Maybe. I have tested this for more than 1000 sequential requests and the site works fine. and this is a new site getting a little traffic. And if this is the case, whats the solution? – Sunil Chhimpa Jan 04 '20 at 07:21
  • The solution is to first test the capabilities through profiling, and then either increasing number of workers (if possible), tweaking server configuration or migrating to better instance. AWS t2-medium instance has 2 VCPUs for example, and the recommended limit is one worker per core, thus it would be necessary to migrate to higher-level instance or test how it performs outside of recommended parameters. Also, sequential is different from parallel, and this is where you may be failing, would recommend using a stress load tester to simulate multiple simultaneous requests. – Daniel Protopopov Jan 04 '20 at 08:21

0 Answers0