Apache and MariaDB High Load Crash

Hello….

Today I was trying to check my website appearance on different browsers to see how my website looks like. But when the load on server was high, I’ve noticed that SQL server crashed.

Of course there is a memory limit on my server and Apache server is configured to accept unlimited connections and child processes for each client’s connection request.

If you have WordPress running (which dynamically loads the pages), this would dramatically increase the load on server and will eventually crashes the SQL server.

This could also happened if your website is under DDoS Attack.

There is a tool called “Apache Benchmarking – ab” that you can use to benchmark the server to check the load, here is an example:

saeed@test:~$ time ab -l -n 5000 -c 500 https://example.net/

If the Apache server is not configured to handle the connection requests, the load will go too high and SQL server will crash, hence WordPress loses its connection to database with the error message: “error establishing a database connection”.

Solutions:

1. Add more RAM and SWAP space – Sometimes not possible if you are on a VPS

2. Limit the number of the Child processes and Connections that Apache server can handle at the time – if the load goes high in this case each connection would be served in a queue once the limit has reached, this might have performance effects and the connection might be disconnected because of “Connection time out”. However this would ensure that server won’t crash if the load is too high in this scenario.

Here is what needs to be added to Apache Configuration:

<IfModule mpm_prefork_module>
    StartServers     3
    MinSpareServers  3
    MaxSpareServers  5
    MaxRequestWorkers 25
    MaxConnectionsPerChild   1024
</IfModule>

 

Hope this helps and thank you.

– Saeed 🙂



BTC: 1G1myr8rYv7SgyYtyWXLu3WLSPNaHCGGcd

Comments are closed.