Performance hardening a 512Mb VM with Varnish

I’ve been having performance issues on a 512Mb VM where I run 3 wordpress sites for projectx and lushai. The problem was that the memory footprint default apache configuration would explode when traffic arrived. Lots of traffic would cause the Apache prefork module to spawn more processes until the machine started swapping and then cause the VM to spiral into a forced reboot.

Part one of my solution was to switch to Nginx webserver. I still wanted to use Apache, because I’m using the mod_pagespeed library for some extra performance juice, but I didn’t want to blow out memory usage. The solution involves using Nginx as a reverse proxy to apache. This allowed me to reduce the number of Apache servers down to 10. Nginx as a reverse proxy uses about 5Mb of memory It worked a treat . But it was a little slow 🙁 See the AB test below.

projectx@projectx:/px/sites/httparchive$ ab -n 1000 -c 100 http://www.projectx.co.nz/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.projectx.co.nz (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: nginx
Server Hostname: www.projectx.co.nz
Server Port: 80

Document Path: /
Document Length: 85698 bytes

Concurrency Level: 100
Time taken for tests: 112.181 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 85937000 bytes
HTML transferred: 85698000 bytes
Requests per second: 8.91 [#/sec] (mean)
Time per request: 11218.133 [ms] (mean)
Time per request: 112.181 [ms] (mean, across all concurrent requests)
Transfer rate: 748.10 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.2 0 13
Processing: 474 10689 2000.6 11051 12967
Waiting: 272 10458 1996.3 10821 12692
Total: 487 10690 1997.7 11051 12967

Percentage of the requests served within a certain time (ms)
50% 11051
66% 11220
75% 11381
80% 11525
90% 11927
95% 12409
98% 12687
99% 12799
100% 12967 (longest request)

I wasn’t happy about the performance, so I decided to throw Varnish as a proxy cache into the mix.

Using WordPress Varnish and varnish wordpress tips from the varnish site, I was able to quickly configure Varnish on the server.

Here’s the result in the performance, from the AB test.

projectx@projectx:~$ ab -n 1000 -c 100 http://www.projectx.co.nz/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.projectx.co.nz (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: nginx
Server Hostname: www.projectx.co.nz
Server Port: 80

Document Path: /
Document Length: 85689 bytes

Concurrency Level: 100
Time taken for tests: 0.366 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 86009000 bytes
HTML transferred: 85689000 bytes
Requests per second: 2733.35 [#/sec] (mean)
Time per request: 36.585 [ms] (mean)
Time per request: 0.366 [ms] (mean, across all concurrent requests)
Transfer rate: 229582.36 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 12 4.6 11 23
Processing: 16 25 4.9 24 36
Waiting: 2 10 5.3 10 23
Total: 29 36 4.6 37 42

Percentage of the requests served within a certain time (ms)
50% 37
66% 41
75% 41
80% 41
90% 42
95% 42
98% 42
99% 42
100% 42 (longest request)

Its a massive improvement from 8 reqs/sec to 2700 reqs/sec. Now I can remove Nginx from the mix, and now to tune mod_pagespeed to optimise my site 🙂

Leave a Reply


http://www.canakkaleruhu.org http://www.vergimevzuati.org http://www.finansaldenetci.com http://www.securityweb.org http://www.siyamiozkan.org http://www.fatmaozkan.com http://www.sgk.biz.tr http://www.denetci.gen.tr http://www.bagimsizdenetim.biz.tr http://www.mevzuat.biz.tr http://www.security.biz.tr http://www.sorgulatr.com http://www.kanunlar.biz http://www.prsorgu.net http://www.sirabul.com http://www.emekliol.org http://www.coklupagerank.com http://www.coklupagerank.net http://www.coklupagerank.org http://www.prsorgu.org http://www.scriptencode.com http://www.sirabul.net http://www.sirabul.org http://www.sitenizanaliz.com http://www.seoisko.com http://www.seomavi.com http://www.scriptencode.net http://www.scriptencode.org