Migrating from Amazon EC2 and Apache to DigitalOcean and nginx

Easter is upon us and i found myself bestowed with an unusual amount of free time, so i decided to take up the long overdue server upgrade.

For the last two years I’ve been running an Amazon EC2 instance (small) and thinking I’m getting good bang for the buck. But lately I’ve been wanting to upgrade to nginx because of all the buzz on the internet. Also, Ubuntu 14.04 came out.

I started off easy and moved two Worpress sites to the new DigitalOcean VPS and benchmarked the setup using ab. Both servers are rocking PHP 5.5 and have opcache enabled. The site is your average WordPress site with some posts, some static pages, a Twitter feed and a contact form. The site uses WP Super Cache with mod_rewrite caching for both Apache and nginx.

Command used for testing

ab -n 500 -c 100 -H "Accept-Encoding: gzip,deflate"  http://www.mysite.com:80/

Here are the old Apache 2.2 results on Ubuntu 12.04 LTS

Concurrency Level:      100
Time taken for tests:   1.205 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Total transferred:      3491000 bytes
HTML transferred:       3308500 bytes
Requests per second:    414.77 [#/sec] (mean)
Time per request:       241.095 [ms] (mean)
Time per request:       2.411 [ms] (mean, across all concurrent requests)
Transfer rate:          2828.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   3.7      0      32
Processing:     7  219  82.7    217     674
Waiting:        4  208  80.1    211     672
Total:         14  221  80.7    217     674

Percentage of the requests served within a certain time (ms)
  50%    217
  66%    230
  75%    242
  80%    256
  90%    286
  95%    288
  98%    507
  99%    552
 100%    674 (longest request)

And here is the same site on nginx on Ubuntu 14.04 LTS

Concurrency Level:      100
Time taken for tests:   0.101 seconds
Complete requests:      500
Failed requests:        0
Total transferred:      9694000 bytes
HTML transferred:       9572000 bytes
Requests per second:    4950.50 [#/sec] (mean)
Time per request:       20.200 [ms] (mean)
Time per request:       0.202 [ms] (mean, across all concurrent requests)
Transfer rate:          93730.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    7   2.8      7      12
Processing:     4   12   4.0     12      22
Waiting:        0    6   3.8      6      17
Total:         11   18   4.2     18      33

Percentage of the requests served within a certain time (ms)
  50%     18
  66%     20
  75%     20
  80%     21
  90%     26
  95%     27
  98%     28
  99%     28
 100%     33 (longest request)

This shows us that nginx on DigitalOcean performs over 11x better than Apache 2.2 on Amazon EC2. Did i mention that the Amazon EC2 instance has 1.7GB of RAM while the DigitalOcean only has 512MB? The cost is also about 1/4. See you in the next life Amazon!

I also tried running 5000 requests total with a concurrency of 1000, just for fun. Apache completely buckled, seized and dropped dead on the floor under the pressure. Nginx happily processed the requests faster than Apache could serve just 500 requests.

Footnote: I realize this is not a conclusive test and a reason for everybody to abandon both Amazon and Apache, ymmv but for me it’s definitely an upgrade. Setting up nginx for WordPress and WP Super Cache is a bit fiddly but the information is out there!

Free $10 credit on DigitalOcean

If you’d like to try DigitalOcean, please use my referreal link, it doesn’t cost you anything! As a thank you, here is a $10 promo code valid until¬†the 31st of May 2014:¬†SSDMAY10

Leave a Reply

Your email address will not be published. Required fields are marked *