Welcome Guest, Not a member yet? Register   Sign In
Handling heavy load
#1

Hi everyone.

I've got some questions regarding optimisation of a server to support more requests. I've recently launched an online game that's written in PHP and due to the current situation with everyone being stuck inside, it's been a lot more popular than we anticipated. I've been a hobbyist programmer for several years and this is the biggest project I've worked on so naturally, I had to learn fast about handling traffic. We're getting between 20-80 active users at any one time according to Google Analytics and are running Apache on a VPS with 4GB RAM and 3 vCPUs.

When we first launched, I was using Netdata to monitor everything and noticed that the Apache workers were being used up quickly and any subsequent requests were being timed out. We increased this from 24 (I think) to about 256 gradually until it was at a level that the server is comfortable. We still haven't gone over 100 but wanted to know that the option is there.

Is there anything else I can do to optimise the running? We're expecting a further influx of users each day as it's growing so want to be prepared. Is the answer simply increasing the server specs.

I apologise if some of what I say is irrelevant or naive - this is the first time I've made something like this and am generally still quite clueless.

Thanks a lot, any help is massively appreciated.

TLDR: launched PHP web app, server died, increased specs, server born again. Worried about 2nd death.
WebDevZone - A new, friendly web development community
Reply
#2

(This post was last modified: 05-02-2020, 08:24 AM by php_rocs.)

@campingrhino,

We need more specifics. What version of PHP are you using? Can you give us more information on the technology/frameworks/libraries/plugins that you are using?
Reply
#3

(This post was last modified: 05-02-2020, 08:24 AM by jreklund.)

What type of game are this?
- Do you need to load each PHP-page every time?
- Are the data dynamic (user unique) or static?
- Do you depend on a database?

What PHP mode are you running under?
- PHP-fpm (recommended) or mod_php?

Personally I'm a Nginx and PHP-fpm kinda guy.

In general you need to start caching results. Either the complete website or part of it.
If it's static pages (with a javascript game) you can cache that entire page with Nginx or Varnish.

If it's dynamic content, cache all but the dynamic data with Memcache or Redis (preferred).

Do you have a load graph on your server? Are you really using all those vCPU? Normally it's a memory issue. As you need to turn up the amount of PHP-fpm children/spawns.
Reply
#4

(This post was last modified: 05-02-2020, 08:50 AM by campingrhino.)

Thanks for the quick response and the tips!

All data is from a MySQL database that's on the same machine. Each page is dynamic and it pulls progress from the database and puzzles. We're also using mod_php on the server at the moment.

I've been monitoring the CPU usage and it's generally running at around 10% and RAM is pretty consistent at 20%. Other than that, we do get an occasional CPU spike every few hours where it goes up into the 80s for a few seconds but I wasn't sure if this is something I need to worry about or not.

Current set up is PHP 7.3 with Redis used for sessions at the moment only. Application is a very simple one using the Flight microframework as the backend with Twig templates (these are cached). There's also a separate admin panel for us built in CodeIgniter 3 but this gets very minimal traffic as only a couple of us use this.
WebDevZone - A new, friendly web development community
Reply
#5

Okay, are the puzzles dynamic generated as well or static content? Because you need to start caching content that's not unique to the user. To lighten the load of the database server.

You need to switch out mod_php into php-fpm asap. As of right know it's this:
apache2+php
apache2+php
apache2+php
apache2+php
apache2+php
...
256 times

And go into
apache2
apache2
apache2
apache2
apache2
... (don't know how many you need with Apache)
If it's the same as with Nginx, you need 3, the number of CPU.

php-fpm
php-fpm
php-fpm
php-fpm
php-fpm
... (depending on the amount of free RAM. And how memory hungry your game are.)

The PM pool should be static. Can't go into exact details on how many you will need, as it need to be tuned to the specific application and server specifications. Based on the current load you need to bump PHP higher than before. But move away from mod_php like yesterday! :-)

A little more read about it:
https://tideways.com/profiler/blog/an-in...fpm-tuning
Reply
#6

Also,

another suggestion would be to make sure that your sql queries are efficient. Are they making good use of indexes. Are they only asking for data that is needed.
Reply
#7

Thanks, will look into those right away. Thanks to both of you for your suggestions, you've saved my skin!
WebDevZone - A new, friendly web development community
Reply




Theme © iAndrew 2016 - Forum software by © MyBB