Question

How to stop server overload, Apache, MySQL and Php config

Posted November 9, 2021 76 views
MySQLApachePHPWordPress

I have set up a basic 1GB server running Ubuntu and Apache2.4.46, PHP7.4.16 MySQL 8.0.27. I am running one Wordpress installation on it.

I seem to be able to overload and crash the server by repeatedly refreshing pages (holding down command and reload). I made the time that this takes to happen a lot longer by making some changes to configs. Whilst this is an edge case situation, I would like to know if there is a way to make sure my server can not get overloaded from multiple requests.

Are there other settings for Apache, MySQL or PHP (or other) I could change to help with load.

Many thanks in advance.

**PHP set up:
PHP Memory Limit 256 MB
PHP Post Max Size 256M
PHP Time Limit 300
PHP Max Input Vars 5000
Max Upload Size 128 MB

**MySQL
keybuffersize = 128M
maxallowedpacket = 16M
threadstack = 192K
thread
cachesize = 8
myisam-recover-options = BACKUP
max
connections = 20
maxbinlogsize = 100M
interactivetimeout = 30
wait
timeout = 30
skip-name-resolve
I have run mysql tuner and the only recommendation is:
innodblogfile_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

**Apache
Timeout 30
KeepAlive On
MaxKeepAliveRequests 10
KeepAliveTimeout 1

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @RedmansWorld,

What you are describing is not high load or websites going down but your Apache Workers filling up, at least this is how it sounds(might be wrong!).

So first, what are Apache Workers and what are they used for:

Imagine you are in a cinema, and there are 300 chairs inside. Those are the Apache Workers and the movie is your Webiste. If someone wants to watch the movie(your website) they need to sit in the chair (Apache Workers). If all 300 chars are taken, the 301 person needs to wait for someone to leave in order for them to sit and watch the movie. That’s how ApacheWorkers work. Once all ApacheWorkers are taken, a new person that wants to open your website waits for a spot to be open and only after that they can see your website.

Usually, these limits are set by 256 by default but they can be increased.

You can open your Apache configuration file. In there you should see something similar to:

ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000

Increase both the ServerLimit and MaxClients options, restart Apache, and see if this would solve your issue.

It’s possible they do not exist (haven’t been added) and the default values are the ones above. Adding them to the prefork content of apache mods should be fine as well.

Don’t forget to restart Apache afterward.

Regards,
KFSys

  • Hi @KFSys, and thanks for the reply.

    Thanks for this; I had no such entry; it seems like the site is running better now – or at least I can’t provoke it to crash as easily as I could before.

    The ‘fix’ I had worked out before was to really reduce the number of MySQL connections – I had lowered from what was listed above to.

    maxconnections = 20
    max
    user_connections = 5

    This had worked in as much as preventing the site from crashing; but did mean that I was getting 'database connection’ errors.

    It seems that having implemented your suggestion I have been able to raise those numbers a bit preventing that problem.

    Could I ask a question about these settings.

    Would I be right to assume that each connection is only used whilst the site is being accessed, rather than whilst a browser window is open? Opening the site is 'watching the film’ in your analogy – but that the person will leave once the site has loaded (the film has finished).

    Does the 'KeepAlive On’ keep connections open a bit longer. That makes the site more efficient because people don’t have to leave the cinema and come back in if they want to watch something else?

    Thanks

    • Hi @RedmansWorld,

      So you are almost correct. Now there are IDLE Apache workers. After some time they become IDLE and after a period of time they get removed but once a website is opened, the connection stays there until you close it or it becomes IDLE and it gets killed.

      As for the KeepAlive settings, you are absolutely spot on!