Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Scaling WordPress on a
small budget
Brecht Ryckaert
Hi, I’m Brecht
• Also known as “Bob”

• WordPress Fanatic

• Performance

• Security

• Combell
Premise
• A WordPress site running on a shared server
• Limited resources:
• A WordPress site running on a shared server
• Limited resources:
Premise
A max of 25 visitors
at the same time
Server
25 visitors
Premise
• Simulated environment on Digital Ocean
• 25 Max Clients
• 128 Memory Limit
• Environment is running webserver and database locally
“Next month we’ll be organizing an event. 

Can you make sure the website can handle the
extra traffic?”
“Sure, how much visitors do you estimate?”
“Not that much, I guess a couple of ten
thousand per hour…”
Scaling WordPress On A Small Budget
Step 1 - Benchmarking the basic setup
Apache Benchmark
• Used to simulate load

• Part of Mac OSX. 

• Can be added via apt-get:



apt-get install apache2-utils
Apache Benchmark
• We’ll send 1000 sequential
requests to our new WordPress
site



ab -n 1000 http://159.65.195.6
Scaling WordPress On A Small Budget
Scaling WordPress On A Small Budget
Apache Benchmark
• We’ll now send 1000 requests
to our new WordPress site in
batches of 200 concurrent
connections.



ab -n1000 -c200 http://
159.65.195.6
Scaling WordPress On A Small Budget
Apache Benchmark
• Our shared server can process
16.98 requests per second



BUT…



The time required to process a
single request increases from
130 ms to a whopping 11776
ms.

• Now we’ll send 1000 requests
to our new WordPress site in
one single batch



ab -n1000 -c1000 http://
159.65.195.6
Scaling WordPress On A Small Budget
Apache Benchmark
• Sending 1000 concurrent
requests kills our server and
takes our site down.
Scaling Up vs Scaling Out
Scaling Up (Scaling Vertically)
Scaling Out (Scaling Horizontally)
Step 2 - Database Scaling
Setting up our cluster
3 x MySQL server
Setting up our cluster
https://www.digitalocean.com/community/tutorials/how-to-
optimize-wordpress-performance-with-mysql-replication-on-
ubuntu-14-04
Cost per droplet:
Database Scaling
• 3 node database cluster

• Total cost so far: 15 $ / month
Connecting The Cluster To WordPress
https://wordpress.org/plugins/hyperdb/
Connecting The Cluster To WordPress
Edit db-config.php to contain the various database connection
strings.
Place db-config.php into the same folder as wp-config.php
Connecting The Cluster To WordPress
/** The name of the database for WordPress */
define('DB_NAME', 'YourDBName');
/** MySQL database username */
define('DB_USER', 'YourDBUser');
/** MySQL database password */
define('DB_PASSWORD', ‘AReallyStrongPasswordShouldBeFoundHereForSecurityReasons');
/** MySQL hostname */
define('DB_HOST', ‘mysqlserver01.brechtryckaert.com’);
define(‘DB_SLAVE_1', ‘mysqlserver02.brechtryckaert.com’);
define(‘DB_SLAVE_2', ‘mysqlserver03.brechtryckaert.com’);
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
Connecting The Cluster To WordPress
Place db.php in the “wp-content” folder
Remove writing permissions to db.php
sudo chmod a-w /path/to/site/wp-content/db.php
Step 3 - Adding Varnish
Adding Varnish
https://www.digitalocean.com/community/tutorials/how-to-
configure-varnish-cache-4-0-with-ssl-termination-on-
ubuntu-14-04
Cost for this droplet:
Adding Varnish
Setting up Varnish:
Add the GPG Key to APT:
curl https://repo.varnish-cache.org/ubuntu/GPG-key.txt | sudo apt-
key add -
Add the repository to the sources list:
sudo sh -c 'echo "deb https://repo.varnish-cache.org/ubuntu/
trusty varnish-4.0" >> /etc/apt/sources.list.d/varnish-cache.list'
Update APT-GET and install Varnish:
sudo apt-get update
sudo apt-get install varnish
Adding Varnish
Adding Varnish
https://gist.github.com/bjornjohansen/
5448f7dd637a5bff1e8f935e693092f2
Change the default.vcl to the content of this vcl:
Adding Varnish
vcl 4.0;
import std;
import directors;
backend server1 { # Define one backend
.host = “shared.brechtryckaert.com”;
.port = "80";
Step 4 - Benchmarking again
VarnishWebserver
MySQL 1 MySQL 2 MySQL 3
VarnishWebserver
MySQL 1 MySQL 2 MySQL 3
Total Cost Of Droplets: $25
Benchmarking Again
Document Path: /
Document Length: 53992 bytes
Concurrency Level: 1000
Time taken for tests: 8.520 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 54162000 bytes
HTML transferred: 53992000 bytes
Requests per second: 144.59 [#/sec] (mean)
Extending upon the basic setup
- HAProxy for Loadbalacing
- Adding several Varnish nodes
- Adding REDIS (not Memcached) nodes for object caching
Questions?
Slides will be tweeted at @brechtryckaert and published on brechtryckaert.com

More Related Content

Scaling WordPress On A Small Budget