Freelance Projects

Upeksha Wisidagama

WordPress Performance Benchmarking With APC via FastCGI PHP5-CGI

Setup: Apache 2.2 Prefork MPM. FastCGI with suEXEC. PHP5-CGI. APC per user.

For detailed explanations on setting up a system summerized above, please read Apache2 FastCGI and suEXEC Implementing APC Per User With PHP5-CGI. Most of the unexplained steps are explained in that post.

Create a new user and install WordPress

1) Login to the server via SSH

‘Login via SSH’
1
upeksha@uw:~$ ssh uwlab

2) Add a new user called ‘uwapc’

‘Add new user’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
upeksha@uwlab:~$ sudo adduser uwapc
Adding user `uwapc' ...
Adding new group `uwapc' (1002) ...
Adding new user `uwapc' (1002) with group `uwapc' ...
Creating home directory `/home/uwapc' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for uwapc
Enter the new value, or press ENTER for the default
  Full Name []: UW APC Testing
  Room Number []: 123
  Work Phone []: +94 011 7776665
  Home Phone []: +94 011 1122334
  Other []: +94 077 1234567
Is the information correct? [Y/n] Y

3) Setup a Virtual Host

‘Setup the Virtual Host’
1
2
3
4
5
upeksha@uwlab:/home$ cd /etc/apache2/sites-available/
upeksha@uwlab:/etc/apache2/sites-available$ ls
default  default-ssl  wisidagama.dev
upeksha@uwlab:/etc/apache2/sites-available$ sudo cp wisidagama.dev uwapc.dev
upeksha@uwlab:/etc/apache2/sites-available$ sudo vi uwapc.dev

:%s/wisidagama/uwapc/g

‘New Virtual Host (uwapc.dev)’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<VirtualHost *:80>
        ServerName www.uwapc.dev
        ServerAdmin webmaster@uwapc.dev

        DocumentRoot /home/uwapc/public_html/
        <Directory /home/uwapc/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        <IfModule mod_fastcgi.c>
        SuexecUserGroup uwapc uwapc
        Alias /cgi-bin/ /var/www/bin/uwapc/
    </IfModule>

        ErrorLog /home/uwapc/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /home/uwapc/access.log combined
</VirtualHost>

4) Setup a suEXEC compatible FastCGI Wrapper

‘FastCGI wrappers’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
upeksha@uwlab:/etc/apache2/sites-available$ cd /var/www/bin/
upeksha@uwlab:/var/www/bin$ ls
wisidagama

upeksha@uwlab:/var/www/bin$ sudo cp -r wisidagama uwapc
upeksha@uwlab:/var/www/bin$ ls
uwapc  wisidagama

upeksha@uwlab:/var/www/bin$ sudo chown -R uwapc:uwapc uwapc
upeksha@uwlab:/var/www/bin$ ls -al
total 16
drwxr-xr-x 4 root       root       4096 Jul  8 15:20 .
drwxr-xr-x 3 root       root       4096 Jul  8 07:23 ..
drwxr-xr-x 2 uwapc      uwapc      4096 Jul  8 15:21 uwapc
drwxr-xr-x 2 wisidagama wisidagama 4096 Jul  8 07:39 wisidagama
upeksha@uwlab:/var/www/bin$

Change the APC size to 100MB in the wrapper script. Please refer to the post linked at the top of this post on how to change the APC size per user.

3) Setup MySQL database

‘WordPress Database Setup’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
uwapc@uwlab:~$ mysql -u root -p
Enter password:

mysql> create database uwapc;
Query OK, 1 row affected (0.00 sec)

mysql> grant usage on *.* to uwapc@localhost identified by 's9sd%sd@1DS!A(6,sld69s%sHEaRWad9#@)X~sd7ZzdffzzzZZZdd9df%^';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on uwapc.* to uwapc@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
upeksha@uwlab:/var/www/bin$ mysql -u uwapc -p

4) Become ‘uwapc’ and setup WordPress

‘Download WordPress’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
upeksha@uwlab:/var/www/bin$ su uwapc
Password:
uwapc@uwlab:/var/www/bin$ cd
uwapc@uwlab:~$ wget http://wordpress.org/latest.tar.gz
--2013-07-08 15:28:15--  http://wordpress.org/latest.tar.gz
Resolving wordpress.org (wordpress.org)... 66.155.40.250, 66.155.40.249
Connecting to wordpress.org (wordpress.org)|66.155.40.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4988077 (4.8M) [application/x-gzip]
Saving to: `latest.tar.gz'

100%[======================================>] 4,988,077   25.9K/s   in 3m 22s

2013-07-08 15:31:40 (24.1 KB/s) - `latest.tar.gz' saved [4988077/4988077]
uwapc@uwlab:~$ tar -xzvf latest.tar.gz
uwapc@uwlab:~$ mv wordpress public_html
uwapc@uwlab:~$ ls
latest.tar.gz  public_html

5) Install WordPress via web interface.

Enable the new site and restart.

‘Enable new site’
1
2
3
4
5
6
7
upeksha@uwlab:/var/www/bin$ sudo a2ensite uwapc.dev
[sudo] password for upeksha:
Enabling site uwapc.dev.
To activate the new configuration, you need to run:
  service apache2 reload
upeksha@uwlab:/var/www/bin$ sudo service apache2 restart
 * Restarting web server apache2                                                 ... waiting

We are not running a DNS server. Map the new site address to the host ip via /etc/hosts file.

WordPress APC Benchmarking Server

Install APC Info Interface

‘APC Info Interface Installation’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
uwapc@uwlab:~$ wget http://pecl.php.net/get/APC
--2013-07-08 16:12:48--  http://pecl.php.net/get/APC
Resolving pecl.php.net (pecl.php.net)... 76.75.200.106
Connecting to pecl.php.net (pecl.php.net)|76.75.200.106|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 171591 (168K) [application/octet-stream]
Saving to: `APC'

100%[======================================>] 171,591      121K/s   in 1.4s

2013-07-08 16:12:55 (121 KB/s) - `APC' saved [171591/171591]

uwapc@uwlab:~$ tar -zxf APC
uwapc@uwlab:~$ mv APC-3.1.13 public_html/apc

Visit APC Info Interface to see the APC status.

WordPress APC Information

Benchmarking WordPress Response Time with APC

Disable APC. Set apc.enabled=0 in ‘/etc/php5/cgi/conf.d/apc.ini’.

Restart the server. sudo service apache2 restart.

Run Apache Benchmarking tool to collect performance data.

ab -n 1000 -c 30 -g without-apc.dat http://www.uwapc.dev/

Enable APC. Restart the server. Again, run ab tool.

ab -n 1000 -c 30 -g with-apc.dat http://www.uwapc.dev/

Plot data using Gnuplot. ( Details on plotting can also be found here: Apache2 FastCGI and suEXEC Implementing APC Per User With PHP5-CGI )

Gnuplot config file

‘APC Info Interface Installation (APC-benchmarking.p)’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# output as png image
set terminal png

# save file to "apc-benchmarking.png"
set output "apc-benchmarking.png"

# graph title
set title "WordPress Benchmarking with APC"

# nicer aspect ratio for image size
set size 1,0.7

# y-axis grid
set grid y

# x-axis label
set xlabel "request"

# y-axis label
set ylabel "response time (ms)"

#plot data from data files
plot "without-apc.dat" using 9 smooth sbezier with lines title "Without APC", \
"with-apc.dat" using 9 smooth sbezier with lines title "With APC"

gnuplot APC-benchmarking.p

WordPress Performance Gain with APC

WordPress Performance Gain While Many PHP5-CGI Children share the same APC under One User with High Concurrency

Next, increase the PHP-CGI children from 2 to 6 (PHP_FCGI_CHILDREN=6 in FastCGI wrapper script). Increase the concurrency to 60 -c 60. Benchmark again.

WordPress Performance Gain with APC with many children

The above plots clearly show the Performance Gain in Response Time when using APC to cache the PHP Opcodes.