On PWM I recommend webmasters to start out with a shared webserver, as they are very cheap and easy to set up. However, eventually when you get more traffic than your shared server can efficiently serve, it’s time to consider a dedicated server. A dedicated server gives you full control over the server resources and software it runs, but you generally have to set this up and configure it yourself. Furthermore, the price increase can be quite substantial, going from $5 for a shared host to $100-$300 for a dedicated one per month.
Due to the traffic load the ping for my JustHost server was starting to get a bit high, with a global average ping at 1800ms. No website optimizations could change that latency. To bring it down I would need bigger hardware. However, paying $100 per month was too much. Instead I decided to go for a virtual dedicated host with Amazon’s EC2 service. Basically, with a virtual server you only pay for the virtual hardware you rent and how long you rent it. Their smallest server instance type was a Micro instance. It costs only $0.020 per hour, or $15 per month, and the first year is free, so there wasn’t much of a downside to trying it out. Furthermore, this price can be halved later by reserving the instance for one year at a time.
I moved my sites over to Amazon, but as I mentioned in a previous post PVT was too heavy for the server to handle and I had to move that site back to JustHost. Not only was the instance running slow with PVT there, but the database kept on crashing because of too little RAM. Upgrading to a larger instance type was not an option, as the price rose three-fold for the second largest instance type, from $15 to $47 per month. I instead had to optimize the software to reduce the hardware needs. To make sure my sites didn’t go down during my optimizations I made a copy of my server instance for testing purposes, which is an easy task with EC2.
Although MySQL’s storage engine kept on crashing, it was mostly because the Apache webserver stole all the RAM. A Micro instance has only 613 MB, and Apache is not really happy with anything less than a gig. So the first optimization I needed to make was for the webserver. Apache was thrown out and switched to a faster and more memory efficient web server called Nginx (pronounced “Engine X”). This is the third most popular webserver, used by 12% of all sites and 29% of the top 1000 websites. It works particularly well for serving cached content, which is all I serve.
A second optimization was to switch MySQL’s database storage engine from InnoDB to the older, less memory consumptive one called MyISAM. As my sites only serve cached content this will not impact the performance of the sites. Thirdly, I employed a second level of caching on the HTTP layer through a reverse proxy system called Varnish to speed up the serving of the pages. So the server now not only caches HTML files but also the actual HTTP response that it sends to the browser.
It took a lot of effort but the Amazon server could now handle PVT along with the other sites with ease. The global average latency for PVT is now only 700ms, and 450ms for the other sites. In the US east region I’m able to load the initial HTML document within 100ms and all page components within 600ms. Even from Finland I’m able to browse through pages in less than a second. These are changes which I could not implement on a shared host, so this level of performance enhancing is a definite advantage of having a virtual or dedicated host.