Migrating  WebSite to Amazon EC2

“While the hosting on Godaddy become unacceptably slow with php or asp.net, I’ve to choose another cost-effective way to make my website continues …  ”

 

Recently,  I found new version of iOS (I think is from iOS10) will consider the connection with TLS version less then 1.2 is not safe.  Although it can be bypass by add exception entry in app's plist file, I think for the long term it's good to upgrade the server to support TLS 1.2. Then everything happened from here.

 

Phase 1 Find The Problem

The service I was using is "cPanel  Deluxe Web Hosting" which Godaddy stop selling or updating.  So I purchased 1 year "Ultimate Plesk Window Hosting" when it's on sale (about 5.99USD/month, 1-year term, looks great). My plan is quite simple, migrate and merge my two deluxe hosting to one newer Ultimate Hosting.  I have several domains, one for company & products information, one for simple ios application backend, one for development information.  

First yes, it do support TSL 1.2.

But I found the fact that new Plesk windows host is too slow to run the Joomla /WordPress, the reality is like

  1. The loading time for every Page(Joomla)  will be around 4~5s, something even longer, 
  2. Network throughput  is good for the static content, but the extremely low process power made the service nearly useless.

 

Phase 2 Ask For Help 

Write a post in Godaddy's  community,  Got replied, but they're not much helpful.  They're talking bout caching or CDN. I know php will be better at Linux hosting, but my application backend is asp.net so I need windows. So I decide to dive deeper to investigate.. 

 

Phase 3 Measure the problem

To testing how slow it  is "test.php" to run a 10M loop  with simple +1 operation,  it take 2+s sometime 4s to finish,  the time is just at server side, it didn't count the network delay . 

 

Php 10M Loop

Joomla  Latency (First Byte)  first Load/2nd Load

Godaddy Ultimate Windows Hosting Plan

Avg 4s

~10s/~5s

Godaddy Deluxe Classic Windows Hosting

Avg 1.3s

<2s/<1s

Amazon EC2 t2.micro(Oregon) win 2016

Avg 0.2s

1s/~0.5s

 

About running PHP on windows, I know well php has better performance in Linux environment, but I believes it should be like 20% faster top. In my case, it has dozen times different.  So  I can be pretty sure that Goddady assigned extremely low process power for "ultimate" Plesk hosting plan. Why? They're forcing customers to purchase more expensive service, their VPC service...

 

Phase 4 Search for alternative

  1. Godaddy Business Hosting  19.99/month for 1st year and 29.00/month,  1GB, 1 CPU,  a little bit expensive, but it only has Linux plan
  2. Godaddy VPS,  ~30+/month which is too expensive or over kill for my requirement
  3. A2Hosing,  turbo win hosting, 12.75 1st 24.99 later,  better, but still has ~2s latency and can't be accessed from China

There's tons of companies providing hosting and vps service, every one claims they're the best performance with lowest price. So I think testing these one by one will be an endless task and also costly, why not build own hosting server from ground.  Both way will take my lot of time, but I can learn a lot form  building own hosting  and more important I can control everything by myself.

 

Phase 5 Setup Amazon EC2 instance

  1. Create a Linux t2.nano (512MB, EBS 8G gp2) , install a MySQL, http, php and phpMyAdmin,
  2. Windows t2.micro with EBS 30GB+ 5GB gp2
    1. Windows 2016 base  IIS10.0,  php 7.x
    2. Amazon ClI + Note++
    3. The 2nd 8G EBS Volume is used as web page hosting space, so it'll be easy to migrate to other instance in the future and also easy to backup and restore.
    4. Install Joomla and use the mysql at linux t2.nano
  3. Setup CloudFront,  I know the CloudFlare is totally free, but  I just don't like the way they hide my server behind their network.  I have to change my domain name's DNS server to make it work. Just don't feel well with it. So I choose the old way.  But CloudFront is not free, the cost might become a burden in future, then I probably consider to use it. 
  4. Testing and perfect!!  First Byte Latency: first load <1s, 2nd load <500ms.

 

Phase 6 MSSQL Database for  previous asp.net project

It's  a very tricky issue,  Amazon do provide RDS instance to support  MS SQL, but it's too expensive, the price db.t2.micro is even higher then a t2.micro instance,  so I found a solution,  why not use the MSSQL service in Godaddy.

Yes, the performance of Godaddy's hosting database is not bad at all.  So I copy all my asp.net  code from Godaddy  nothing need to be changed since the database connection is same.

Testing! the result is acceptable as temporary  solution.

 

Phase 7 Setup SSL

Since all my domains is register in the Godaddy,  I decided still using the SSL service from them so I'll be breeze easy to manage SSL in one place

Testing! Perfect, all encryption connections now support TLS 1.2

 

Phase 8 Measure the Cost

I choose the US Oregon Region since it's the cheapest and networks speed is acceptable, compared with North California, Mine is a little bit slower but it's find to me. 

Amazon

  • Amazon t2.micro windows, on-demand, 0.017usd/ partial . I purchased  a one-year term reserved instance with 54.00 USD upfront,  so the effective cost will be 0.012/hr  or 8.88usd/month
  • t2.nano Linux,  on-demand, 0.0059/hr or 4.30usd/month
Here, I have to say it's so cheap with Linux,  same hardware configure, the cost for linux is always at least 30% lowser
  • Yes, Amazon charge storage separately including system disk. EBS  gp2 volumes 30G(windows sys)+8G(Linux  sys)+5G(web data)  0.1/GB/Month, totally 4.10usd/month
  • Backup, Amazon can save EBS  volume snapshot to S3 at 0.05/GB/Month, but it said it will only store the used sector and also compress the content, so the actual usage will far smaller than original, anyway, the maximum usage will be same size of all volumes which is 2.10usd/month
  • CloudFront, about 0.140/GB transfer, it will be quite small with my site's current traffic. 
  • So Total cost for Amazon Services will be about ~20.00 usd/moth,
    • If high traffic, the cost for cloudFront will added up

Godaddy

  • Ultimate Plesk, 7.99usd/month on sales and 16.9usd/month,  since I've already paid a year, so just used it as a static web site and provide  temporary MSSQL service to my t2.micro instance
  • SAN SSL 149.99USD/year, which can contain 5 domain name.  I just learn, www.[domain].com and [domain].com are count as 2. Actual the primary domain is included both types autumnally, but the other 4 are counted separately. Anyway, it's good enough for me.
  • For other service, I'm plan to cancel them at their end of bill duration, I'll also cancel the Plesk windows Hosting if they don't improve the service.
  • Domains, I have  6 domains, so it cost avg 12.8usd/month
  •  So total cost for Godaddy will be ~25usd/month (just for  SSL and domains)

Summary

Current 

Cost with Amazon + Partial Godaddy  will be around 20+25, 45usd/month, 

If  go with VPS

VSP service will cost around 30+usd/month(first 26 then 36) and still need add ~25/month for SSL and domains) , the total cost will be at least 55usd/month.

 

Phase 8 Pros and Cons

Pros

  • You get what you paid

 ec2 instances is using CPU credit and baseline to manage the usage of processers. For example t2.micro, has 10% baseline,  every hour will add 3 vCPU credit if avg load below baseline.  Maximum CPU credit balance will be 144.  The number 144 means you can use 100% vCPU performance  144 minutes continuously.    And the current CPU model is e5-2673 v3 @2.4Ghz.   It sound not that powerful, but php test mentioned before, it provided 10x more  power than what Godaddy provided in its ultimate level hosting .   And it will be  6~10% cpu peak  for every single page load.  It mean it should be able handle 5 ~6 concurrence request per second within baseline and much more burst requests. Not like Godaddy, you can't know these detail.   

  • Upgrade Anytime

 in case t2.micro can't handle growing traffic, just change the instance type to a higher one. 5mintues top. Nothing else.  Of course, the cost will be changed accordingly.

The disk space is just like the ec2 instance, can be change (actually increase) size at anytime

  • Free Public IPs (up to 4).
  • Freedom

Literally, you can do anything with EC2 instance. Since I get fully control  of the server. I even can run my own little program if I like.  And migrating the instance to other region is possible and easy.

 

Cons

  • Freedom is not free, a lot thing need to be considered, like system configuration, update, backup and security.
  • For security,  the in-bond rule must be configured carefully. My 1st lesson is 3389 RDP,  I had allowed any source IP address to connection.  In 12hrs, I saw 35K+  remote login attempting failure events in the log.  Lucky, I changed this in-bond rule to allow only my ip address before anyone breach.
  • Database will be costly.  RDS instance is more expensive  than the same level of normal ec2 instance and MSSQL is even higher.  Of course the database can be installed in same instance which running  web server. But in my case, the t2.micro only has 1G memory,  it's not a good idea to add a MSSQL on it, the giant windows system already take most of memory.

 

Summary

Although,  the current cost on amazon is low, but it won't cheap at all if using  whole set of services. But I think I like this way to build own website.  It's not like Godaddy or a2hosting, etc. They provided a simple centralized UI and there's not much user can do.  Amazon EC2 provide a way like assistant user to build everything from bottom, they provided so many services or parts. User can pick up some of these like toy parts to connect, configure them to build something .

And one thing I found is Linux is a lot way is much more cost-effective than windows.  Like the t2.nano, only 512MB memory. Linux doesn't complain at all. Install MySQL, http, still is working fine.  It requires only 8GB volume for system, not like windows requires 30GB to fill its fat ass. When both instances are idle, Linux only take ~0.5% cpu, windows will takes avg 1.24% for nothing.  More important,  Linux instance is much cheaper then the same level windows instance.

So it makes me to consider to re-write my projects to Linux environment ….