Search code examples
phpmysqlamazon-web-servicesamazon-ec2system-administration

Amazon EC2 Linux PHP slowing down after each deployment


I have an EC2 server running a Laravel application, driven by RDS MySql database. Each time I deploy the application it works fine, but after about 1 week of use it becomes progressively slower, until the eventually the site won't load at all (for any visitor) and 502 errors result. One I re-deploy the application (thus rebooting the server) it works fine, then begins to slow down again.

What could be POSSIBLE causes of a steady drain on resources for such an application? Having tried Cloudwatch and server logs, I cannot find any resource which is close to its limit, but the behavior persists. (CPU, CPU credits, Burst, Memory etc...)

Thanks.


Solution

  • The 502 error is suggesting issue with communication between web server and the app handler - most probably being caused by your instance running out of memory due to it being a micro (guess). In this case I also assume you are using PHP-FPM.

    Try restarting just PHP-FPM and see if your site becomes responsive again. This will tell you your issue is most likely occurring at the application layer.

    Tail Web Server error logs - you should have some indication of what is causing the issue here and if you are unsure post.

    If your app doesn't respond to web server in the allotted time this will also cause an issue - check your PHP.ini for the following param:

    max_execution_time = 30
    

    If using Nginx you will also need to modify config to increase the timeout here also. Look for the following param:

    fastcgi_connect_timeout 300;
    

    You will probably want to create a swap file after you have done this. It's either this or increase your instance size. Your issue is really not likely RDS or a network issue (obviously) due to infrastructure you are running your app on.

    OPS note I checked the error logs using the following method : https://www.bigappledesigns.com/2013/06/how-to-access-apache-web-server-httpd-error-logs-for-amazon-ec2-linux-and-most-other-linux-varieties-also/ This revealed several "out of memory" messages.