{"id":349,"date":"2018-05-03T02:52:57","date_gmt":"2018-05-02T16:52:57","guid":{"rendered":"https:\/\/ghiassy.net\/?p=349"},"modified":"2018-05-03T02:54:41","modified_gmt":"2018-05-02T16:54:41","slug":"apache-and-mariadb-load","status":"publish","type":"post","link":"https:\/\/ghiassy.net\/?p=349","title":{"rendered":"Apache and MariaDB High Load Crash"},"content":{"rendered":"<p><span style=\"color: #00ff00;\">Hello\u2026.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">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\u2019ve noticed that SQL server crashed.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">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\u2019s connection request.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">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.<\/span><\/p>\n<p><!--more--><\/p>\n<p><span style=\"color: #00ff00;\">This could also happened if your website is under DDoS Attack.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">There is a tool called \u201c<span style=\"color: #ff9900;\">Apache Benchmarking \u2013 ab<\/span>\u201d that you can use to benchmark the server to check the load, here is an example:<\/span><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:sh decode:true\" title=\"ab example\">saeed@test:~$ time ab -l -n 5000 -c 500 https:\/\/example.net\/\r\n<\/pre>\n<p><span style=\"color: #00ff00;\">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: \u201cerror establishing a database connection\u201d.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">Solutions:<\/span><\/p>\n<p><span style=\"color: #00ff00;\">1. Add more RAM and SWAP space \u2013 Sometimes not possible if you are on a VPS<\/span><\/p>\n<p><span style=\"color: #00ff00;\">2. Limit the number of the Child processes and Connections that Apache server can handle at the time \u2013 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 \u201cConnection time out\u201d. However this would ensure that server won\u2019t crash if the load is too high in this scenario.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">Here is what needs to be added to Apache Configuration:<\/span><\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\" title=\"00-mpm.conf on CentOS\">&lt;IfModule mpm_prefork_module&gt;\r\n    StartServers     3\r\n    MinSpareServers  3\r\n    MaxSpareServers  5\r\n    MaxRequestWorkers 25\r\n    MaxConnectionsPerChild   1024\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #00ff00;\">Hope this helps and thank you.<\/span><\/p>\n<p><span style=\"color: #00ff00;\">\u2013 Saeed \ud83d\ude42<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello\u2026. 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\u2019ve 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,7,6,14],"tags":[],"class_list":["post-349","post","type-post","status-publish","format-standard","hentry","category-apache","category-linux","category-servers","category-wordpress"],"_links":{"self":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349"}],"version-history":[{"count":10,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}