Why autoscaling
If your site receives an unpredictable number of visitors or you want to lower your bill during low traffic periods (such as nighttime) then you want to design your site so that it can scale automatically. This will ensure that when you receive a higher number of visitors, the site will scale up to accommodate them for the best possible experience. It will also ensure that when the number of visitors decreases the resources are freed so that you always have the optimal number of servers dedicated to your customers.
Assumptions
- you have already connected Linode to Bunnyshell
- your application is set up to be scalable
Setting up your application to be scalable
In this example, we will start with a new application that is designed to be scalable.
First, navigate to Applications and then select Create Application followed by On a new webserver.
For autoscaling to work you need to ensure that:
- you are using a separate MySQL server
- all your files are stored on NFS
Please select the following options in the wizard:
Select application | WordPress (for this example) | |
Select Web Server Type |
Nginx/Apache | Either of these two will work |
Select cloud | Linode | |
Select location | Geographically closest to you | |
Select Plan | Based on needs per VM | |
Infrastructure components |
Web Server Type: Load Balanced MySQL Server: new (small) Redis: None NFS Server: new |
Only add Redis if you use it |
Chose Application Name |
Chose a suitable name |
Once the creation process is complete, you will have a new clean environment where you can deploy your WordPress application.
Autoscaling
From Web Servers select the newly create server and then navigate to the Scaling tab. On the left side, you will notice the Autoscaling option.
By default, autoscaling is turned off. Once you enable it you will be able to set at which level you want the process to kick in.
For example, when the CPU utilization is above 60% for more than 3 minutes, scale up by one instance:
When you are happy with the settings, please select Save Autoscaling Settings.
Testing autoscaling
The best way to test that Autoscaling is working is to install the stress from the ubuntu package manager and create high CPU load on the webserver:
sudo apt install stress
stress --cpu <number_of_cores>
This should generate sufficient load and after 3 minutes your application should automatically scale up to accommodate the load.