Document 7187745

Download Report

Transcript Document 7187745

Build a scalable architecture with
Amazon's EC2
Adam Howitt
www.adamhowitt.com
About Adam Howitt
• Over 7 years ColdFusion
– 5 ½ years blogging http://www.webdevref.com/blog
– 3 years at Duo Consulting in Chicago
• Independent Consultant since 9/24/07
– Google technologies, SEO, Load testing
– CF, AJAX, JS, MySQL, Apache, SQL Server 2000-2005
– http://www.adamhowitt.com
• WalkJogRun on BlueDragon
– 125,000 running routes worldwide
– Approximately 3,000 visitors per day
– http://www.walkjogrun.net
I Have Never
• hosed a dev box and had to reinstall
• hosed a prod box and spent all night fixing it
• tried a new patch of a server version and had to
roll it all back or reinstall
• moved an app to linux without being able to test it
• launched an app without load testing because we
didn't have the time to configure a test machine
and had it crash
How Would You Like To
• Try CF8 or BD7?
– New features
– Test existing apps
• Try Ruby on Rails, PHP, MySQL?
• Test your application on Linux machines?
– Cheaper OS, stability, hacker protection
• Load test an application?
• Solve your Slashdot / Wall Street Journal
problem?
Introducing Amazon EC2
• Spin up a basic server for about $2.50 per
day / $0.10 per hour
• Install what you want
• Use the server
• Optionally save a snapshot
• Shut it down
Basic Server Architecture
•
•
•
•
•
•
Linux based virtual machines
1.7Ghz x86 processor
1.75GB of RAM
160GB of local disk
250Mb/s of network bandwidth
$0.10 per hour per machine + bandwidth
Other Available Architectures
• Large Instance:
– 7.5 GB of memory,
– 4 EC2 Compute Units (2 virtual cores with 2 EC2 Compute Units
each),
– 850 GB of instance storage,
– 64-bit platform
– $0.40 per instance-hour consumed or partial hour consumed
• Extra Large Instance:
– 15 GB of memory,
– 8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units
each),
– 1690 GB of instance storage,
– 64-bit platform
– $0.80 per instance-hour consumed or partial hour consumed
Tools You Need
• Get an Amazon EC2 account
• http://www.amazonaws.com
• Get Putty for Windows
• http://www.chiark.greenend.org.uk/~sgtatham/p
utty/
• Get Amazon EC2UI for Firefox
– http://developer.amazonwebservices.com/conne
ct/entry.jspa?entryID=609
Boot a Machine
• Open EC2UI
• Generate a .pem key
• Boot an instance
– amhimages/ubuntu704-apache.manifest.xml
Login
• SSH Client (Putty)
• Convert Key to .ppk with PuttyGen
• Start Apache
/usr/local/apache2/bin/apachectl start
• Test Apache
• http://ec2-67-202-27-135.compute1.amazonaws.com/index.html
Install ColdFusion
•
•
•
•
•
cd downloads
chmod +x coldfusion-80-lin.bin
./coldfusion-80-lin.bin
/opt/coldfusion8/bin/coldfusion start
Test ColdFusion & RDS
• http://ec2-67-202-27-135.compute1.amazonaws.com/index.cfm
• WinSCP http://winscp.net/
• Logout and shutdown
Results for 4,000 visits/day site
• Cost
– Machine instances
– Traffic in and out
Day
Month
$2.40
$0.28
$72
$8.40
• Load testing HTML
Transactions:
Response time:
23582 hits
0.01 secs
• Load testing CFM
Transactions:
Response time:
19466 hits
0.12 secs
The Benefits
•
•
•
•
•
•
Cheap: $80.40 per machine
Scalable: As many servers as you need
Beefy: Upgrade to more virtual processors
Fault tolerant: Failover machines
No hardware required
Experiment!
The Drawbacks
• Non-persistent storage
• Persistent Machine Images
• Random IP Addresses
Tips for Living Without Persistence
• Install everything you need to persist
• Create boot scripts
–
–
–
–
Pull code from source control
S3 as a mounted drive
S3.cfc to save and retrieve assets
MySQL S3
• Bundle and Boot
• http://docs.amazonwebservices.com/AWSEC2/2007-0829/GettingStartedGuide/creating-an-image.html
Tips for Living with unstable IP
• Use the public DNS name
• Have offsite DNS / load balancing
• Use a CNAME e.g. www.walkjogrun.net
• Points to public DNS name
• Avoid using no CNAME e.g. http://walkjogrun.net
• Reduce domain TTL
• Run pound to control images
• http://www.apsis.ch/pound/
• Zeroflux.com articles
• Risk it! 3 weeks with no change
Dream Architecture
• 2 x Replicated MySQL Servers
– Large instances (4 cores, 7.5 gb RAM each)
– Hourly backups
• 2 x ColdFusion Servers
– Application code in Source control
– Small /Basic instances (1 core, 1.7 gb RAM each)
– Dynamic assets at S3
• Software Load Balancer
– Small /Basic instances (1 core, 1.7gb RAM each)
• Total Cost 11x$80 = $880 per month!
Summary
•
•
•
•
•
Cheap
Scalable
Beefy
Fault tolerant
Experiment!
Questions?
•
•
•
•
•
Adam Howitt
[email protected]
http://www.adamhowitt.com
http://www.webdevref.com/blog
http://www.walkjogrun.net