How to temporarily scale a Wordpress site?

Hi there,
I'm trying to address a concern of my customer running the website mentioned above. They will be on a TV show and expect a sudden, temporary load increase during the show and a few days following.

I'm still trying to quantify that "load increase", but maybe you could help me identify an appropriate option to prepare the infrastructure.
Right now the site is hosted on a VPS together with 20 other sites, none of them creating a traffic that would be worth mentioning.
As the load increase will last for a week at maximum, I don't want to throw hardware at it. Using AWS and a load balancer seems to be the better option.
The users may fill in some contact forms or sign up for newsletters, but there won't be huge down- or uploads and the website itself will not change during the time.
Do you have any idea what the most effective approach might be? And where to find corresponding tutorials?
Would it be ok to have multiple instances that all have their own mysql instance?
Or do I need to run a shared MySQL instance that is used by all webserver instances?
If we are looking at e.g. 5000 concurrent users, does load balancing make sense at all or would a large, powerfull EC2 instance be sufficienct?
Maybe together with a CDN?

As you can see, I'm at a loss right now where to start and in which approach I should invest time to investigate and test a setup.
Especially as I didn't have to deal with any high-load sites so far.
Maybe you guys with all your experience could point me to the right direction :slight_smile:

  • Adam Czajczyk

    Hi Christian Toller

    I hope you're well today!

    Before I say anything else, let me just note that I'm not a sysadmin/server administration specialist so even though I used to deal with this back in the past, consider my words more as "remarks on the case" rather than a "guide on what to do".

    The perfect scenario for this would be to actually move the install entirely to some cloud based host - an Amazon cloud services are great for that but there are also other providers. This is by far the most "universal" solution because it is easily scalable and in most cases if you expect more traffic/heavier load all you need to do is just switch a couple of checkboxes or slide couple of sliders in server management panel. Well, it doesn't always look like that but it's usually equally simple :slight_smile:

    It gets a bit more complex if you can't move the site to such platform. A VPS can be a nice solution but its ability to be scaled "on demand" is usually very low, if any. You got a defined set of resources, limited by hardware, and that's all you can get from it. This requires different methods.

    I'll skip the part about server optimization as I'm not a specialist on this but what I could suggest here would be to make sure that the webserver powering the site is either NGINX or it's a NGINX + Apache configuration (where NGINX serves as a reverse proxy for Apache) rather than Apache alone.

    You should be able to find plenty of articles and tutorials on how to optimize both of these servers for high traffic. Some useful resources are here:

    nginx + apache setup

    https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-server

    https://www.howtoforge.com/tutorial/how-to-install-nginx-as-reverse-proxy-for-apache-on-ubuntu-16-04/

    optimize nginx

    https://gist.github.com/denji/8359866

    https://medium.freecodecamp.org/powerful-ways-to-supercharge-your-nginx-server-and-improve-its-performance-a8afdbfde64d

    optimize apache

    https://bobcares.com/blog/speed-up-apache/

    https://medium.com/@sbuckpesch/apache2-and-php-fpm-performance-optimization-step-by-step-guide-1bfecf161534

    https://httpd.apache.org/docs/2.4/misc/perf-tuning.html

    A tip: once you got nginx+apache setup you can additionally configure nginx to directly server/cache some static resources like e.g. images, pdfs (if there are any) and that kind of files;

    Then there's a matter of a database. The idea of having multiple databases - that could work but is more complex than it may seem. Regardless whether you'd get multiple "copies" of the site behind load balancer (which is actually a good idea but again - it requires making copies of the site on different! servers) or just database multiplied and "load-balanced" - you'd need to make sure about constant synchronization.

    Instead I would either try to fine-tune the database engine or consider just moving it to Amazon RDS.

    https://rudd-o.com/linux-and-free-software/tuning-a-mysql-server-in-5-minutes

    https://www.linode.com/docs/databases/mysql/how-to-optimize-mysql-performance-using-mysqltuner/

    http://www.monitis.com/blog/101-tips-to-mysql-tuning-and-optimization/

    On top of it, adding some robust server-side cache might be a good idea though you should be very careful about that, especially if you are already using some caching plugin (like W3 Total Cache).

    Then you got a "WP layer" - no server optimization makes sense if the site is not optimized so I'd strongly suggest reviewing the site and trying to optimize it as much as possible: get rid of any unnecessary plugins, see if some of the plugins might be replaced with their more lightweight/simpler versions and so on. Our Smush Pro and Hummingbird plugins should also be of great help with site optimization:

    https://premium.wpmudev.org/project/wp-smush-pro/

    https://premium.wpmudev.org/project/wp-hummingbird/

    On top of this all, definitely implement a CDN as it will additionally optimize and cache resources taking some load off of your server and it will improve stability, security and performance of the site (by routing the traffic through the fastest routes for the end-user instead of the same route for everyone).

    Now, will that be able to server 5k concurrent users? I honestly don't know. It might be or might not be. I've seen both: WP based sites that had no issues nearly "out of the box" and "super-optimized" sites that still weren't very responsive and stable (mostly due to server/server connectivity issues). But it would be a way if moving entire setup to the cloud is not an option. And if the hardware is reasonable and the OS, webserver(s) and site are well optimized, there's a good chance that it should "survive" :slight_smile:

    Still though, the best way would be to actually move everything to e.g. Amazon EC2:

    https://www.onepagezen.com/migrate-wordpress-aws/

    Best regards,
    Adam

  • Adam Czajczyk

    Hi guys!

    As always, simplest solutions are the best :slight_smile: As Jack says, that's definitely the best thing to start with as it might turn out that they can help you. I'm almost ashamed that I didn't suggest that in first place!

    But that depends a lot on your host. I said earlier that VPS "scalability" is close to none but actually that's not entirely true - it's more of "you cannot scale it easily" rather than anything else. It all depends on underlying infrastructure, it's quite possible that your host can actually allocate a lot more resources (at least temporary) to the virtual machine (container) that you're using so yeah, definitely give it a shot in a first place :slight_smile: Thanks for that simple, yet great advice Jack!

    Have a nice day,
    Adam

  • Christian Toller

    Hello Adam, hello Jack,

    thanks a lot for those answers, very detailed and thoughtful!

    First of all, I will do what Jack suggested and contact my VPS provider. You are right in saying that they would appreciate to be informed and that they may have some good suggestions.

    Depending on their answer, I will decide upon my next steps.
    I implemented quite a few of the optimization tasks suggested by Adam some time ago, I doubt that there's much to gain. So it will be more like moving to separate (more powerful) hardware, or to move to AWS. AWS is more complex to implement and easier to scale up, while the hardware might be more expensive, when I rent them for just a month.

    If you guys don't mind, I will keep this thread open and post my findings for everyone's amusement :smirk:

    Cheers,
    Christian

    PS: How do you add links to the profile of someone you are referring to? Adam did that, I just don't know how...

    • Adam Czajczyk

      Hi Christian Toller

      Sure, let's keep this thread open, I'm pretty sure some other Members may find it interesting and helpful as well :slight_smile:

      How do you add links to the profile of someone you are referring to? Adam did that, I just don't know how...

      While typing your post here, simply type at character @ and immediately after that (no space) start typing the name. A list will popup at the bottom of the post editor so you can select a person :slight_smile: Or you can just type entire username after that character (as you see it in our posts).

      Best regards,
      Adam

  • Christian Toller

    Hello everyone,

    as promised, I would like to post the outcome of the whole story. The mentioned TV show ("2 Minuten 2 Millionen", the Austrian version of the US show "Shark Tank") took place last week.

    In short, we didn't have any issues. I least I didn't notice any.

    Since I asked the question the customer decided to move away from WordPress to a course booking systems that also provides the whole website. Like WordPress it's a kind of CMS, it's shared hosting, but unlike their previous server we don't have control over the infrastructure or webserver settings at all.

    Before the event I did several load tests using the free service of loader.io, which indicated that page load time increase drastically when more than 100 simultaneous requests are made, at 500 requests page loads took nearly 30 seconds or timed out at all.
    My own (not optimized) wordpress installation in comparision was able to handle 1000 simultaneous requests with load time up to 10 seconds, but reaching 1200 requests it just stopped delivering pages.

    As we couldn't optimize the server, and because it was quite fast already (without load: first byte after 200ms, full page 2 seconds), we decided to go for a CDN, Cloudflare in that case.

    And that basically solved the issue. Without load you see first byte times of 30ms, full page load around 0.9 seconds.
    In a 1 minute test ramping up loads from 0 to 5000 simultaneous requests the first byte time increased constantly to 500ms, full page load around 2 seconds.
    Wow, That was fast. The CDN delivered 180 GB of data to the clients during that minute, only 180 MB got through to the real server.

    During the TV show, to be exact, during the 15 minutes my customer was on stage, we saw a constant increas of active visitors up to 1000. According to Google Analytics live view.
    Of course that doesn't mean 1000 parallel requests, those were spread of a minute or so.

    As a result, the CDN covered the load nicely. No outage, no delays.

    But a CDN has some drawbacks that I had to explain to the customer. If you should ever try it, keep the following in mind:
    - While the CDN is active, changes you make to the website will not be visible. For last minute changes you can activated the "development mode" that temporarily pauses caching. Don't forget to clear the CDN cache before the event.
    - Consider that it takes time to setup and test a CDN. Test your pages with mobile devices, too. You may find that it doesn't work for iOS, because some pictures are not loaded. CDN support or Google will be able to help, but you have to see the issue first. And the required DNS changes take time to propagate.
    - Use loader.io to run load testing
    - Ensure that the most affected pages don't load stuff from many sources, but are mainly static. Be aware that loading e.g. a script from an external, slow server will break the whole thing. The CDN can't cache those.
    - Talk to your hoster! Do NOT run performance test without their permission! Like in my case, they may actually have suggestions for CDN configuration (options to set, exclusions to make)

    All in all, it wasn't too complicated and the result was awesome.
    And right after the tv show, I switched the CDN off, because it's a pain if you work on your pages :slight_smile:

    Hope this helps,

    Christian Toller
    tethis IT
    Vienna, Austria

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.