Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cloud Computing for Hackers
Search
Giovanni Collazo
October 23, 2012
Programming
3
630
Cloud Computing for Hackers
Presented on workshop at Universidad de Puerto Rico, Rio Piedras.
Giovanni Collazo
October 23, 2012
Tweet
Share
More Decks by Giovanni Collazo
See All by Giovanni Collazo
Mis refranes favoritos
gcollazo
7
840
BarcampVSJ
gcollazo
4
63
The Future
gcollazo
0
150
Blimp - How it's Made
gcollazo
5
300
Naming and branding for hackers
gcollazo
0
230
Receta para conseguir "guisos" mientras se estudia a tiempo completo
gcollazo
4
460
Other Decks in Programming
See All in Programming
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
DMMオンラインサロンアプリのSwift化
hayatan
0
190
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
150
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
Alba: Why, How and What's So Interesting
okuramasafumi
0
210
AHC041解説
terryu16
0
400
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
140
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.3k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
1.9k
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
450
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
240
Featured
See All Featured
Designing Experiences People Love
moore
139
23k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Thoughts on Productivity
jonyablonski
68
4.4k
Side Projects
sachag
452
42k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
GitHub's CSS Performance
jonrohan
1030
460k
KATA
mclloyd
29
14k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Done Done
chrislema
182
16k
What's in a price? How to price your products and services
michaelherold
244
12k
A better future with KSS
kneath
238
17k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
Cloud Computing for Hackers
Thanks for showing up
We are going to move fast
I will stop for questions
Giovanni Collazo @gcollazo
None
None
Hacker
“jakel”
“To programmers, ‘hacker’ connotes mastery in the most literal sense:
someone who can make a computer do what he wants—whether the computer wants to or not” - Paul Graham
“It can be either a compliment or an insult. It's
called a hack when you do something in an ugly way. But when you do something so clever that you somehow beat the system, that's also called a hack.” - Paul Graham
None
None
None
None
None
If you are here you are a Hacker
So, what’s cloud computing?
a computer in the sky
a computer over network
a computer somewhere on the internet
elastic
providing service as a utility
the illusion of infinite supply
Why so much attention?
Paradigm shift
None
Everything talks to the network
All computers are over the network
Does it matter if the other side of the cable
is in the same building?
For most apps it doesn’t matter
So, I don’t have to buy and maintain servers?
None
Why Hackers should care?
We can deploy a server in seconds
We can deploy hundreds in minutes
Pay for what you use
New kinds of apps are possible
New toy to play with
How many servers they have?
It’s been reported that AWS has somewhere around 500,000
That’s not enough
They are enough because the are virtualized
What’s this virtualization thing?
Hardware virtualization or platform virtualization refers to the creation of
a virtual machine that acts like a real computer with an operating system - Wikipedia
One physical machine can run multiple virtual machines
They share the resources of the physical machine
XEN
XEN x86, x86_64, IA64, ARM
XEN Windows, Linux, Solaris, BSD
They look like “real” machines over the network
They are cheap to run
None
This is specially cool for scaling web apps
Modern web apps are designed to scale horizontally
That means that to support more traffic you just add
more “cheap” machines
...instead of using really big, powerful and “expensive” machines
What does the architecture of a web app looks like?
App Server HTTP Request HTTP Response DB
App Server HTTP Request HTTP Response DB Cache
App Server HTTP Request HTTP Response Cache DB Reads &
Writes
App Server HTTP Request HTTP Response Cache DB Reads &
Writes App Server Load Balancer
Load Balancer App Server App Server App Server App Server
DB Read Slave DB Read Slave Cache Reads DB Master Writes Replication HTTP Request HTTP Response
Load Balancer App Server App Server App Server App Server
Cache DB01 HTTP Request HTTP Response DB02 DB03 Shard01 Shard10 Shard11 Shard20 Shard21 Shard30 Reads & Writes Reads & Writes
what if AWS goes down?
AWS America East Rackspace OpenCloud DNS
18 million visitors per month 3 million + users 410TB
of data
12 Employees
30 million users 150 million photos
3 engineers
Sold for $1 billion to Facebook
OK. Got it! How do I use the cloud?
There are many approaches to “the cloud” but we are
going to talk about 2
The ones I think you’ll care about
None
you rent an instance
you manage your OS
upgrade packages
take care of security
... and availability
it’s the closest to renting a physical server on a
data center
maximum control
management over web console or api
None
They provide a container for your app
Easy deployment
git push heroku master
They take care of OS level issues
Super easy scaling
They enforce good app design
Less control over the environment
They run on top of AWS
What should I use?
Well, it depends
Understand the AWS model
Start with Heroku
Move to AWS when it’s absolutely necessary
None
Hands-on
None
Login to the AWS console
Create a Linux instance
Install Apache and PHP
Create a simple PHP script
Warning
Let’s do it
https://blimp.signin.aws.amazon.com/console
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
chmod 600 keyfile.pem
ssh -i keyname.pem ubuntu@hostname
sudo aptitude install apache2
sudo aptitude install php5 libapache2-mod-php5
cd /var/www/
sudo mv index.html index.php
sudo vim index.php
<?php echo 'AppServer: ' . gethostname(); ?>
Now what?
Live demo
Creating an image from a running instance
Launch an instance from an image
Creating an ELB
Me gusta
ProTips™
Free Tier
Micro instances are throttled down after a few minutes of
heavy use
Using the biggest available instance size gets you a “full”
machine
Chaos Monkey
Homework: Try to learn some Python
That’s it for today... Questions
Day 2
Cloud Computing for Hackers
None
Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno
HTTP Request HTTP Response
Load Balancer Web Dyno Web Dyno Worker Dyno Cron Dyno
HTTP Request HTTP Response Ruby, Python, Scala, Java, Javascript, PHP
They do SysOps
You make web apps
Let’s try it
Setup a Python dev environment
Create a virtualenv for our first project
Create the simplest web app ever made
Deploy to Heroku
Make changes to the app
Deploy again
Start * tested on Mac OSX
mkdir ~/.virtualenvs
sudo easy_install pip
sudo pip install virtualenvwrapper
vim ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh .bash_profile
source ~/.bash_profile
cd ~/Desktop mkdir myapp cd myapp
mkvirtualenv myapp
pip install flask pip freeze > requirements.txt
app.py import os from flask import Flask app = Flask(__name__)
app.debug = True @app.route("/") def hello(): return 'Hello: {}'.format(os.uname()[1]) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port)
python app.py open http://localhost:5000
vim Procfile
web: python app.py Procfile
git init git add . git commit -m ‘Initial Commit’
Install the Heroku Toolbelt https://toolbelt.heroku.com
Sign up to Heroku https://api.heroku.com/signup
heroku login
heroku create
git push heroku master
heroku open
import os from flask import Flask app = Flask(__name__) app.debug
= True @app.route("/") def hello(): return 'Bye: {}'.format(os.uname()[1]) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port) app.py
git commit -am ‘Small copy change’
git push heroku master
heroku open
Something more exiting, please * tested on Mac OSX
Let’s use Redis
brew install redis * Mac OSX only
pip install redis
pip freeze > requirements.txt
import os import redis redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379/0') redis =
redis.from_url(redis_url) store.py
mkdir templates vim templates/index.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>The List</title> </head> <body>
<ul> {% for item in the_list %} <li>{{ item }}</li> {% endfor%} </ul> </body> </html> index.html
import os import time from flask import Flask from flask
import render_template from store import redis app = Flask(__name__) app.debug = True @app.route("/") def hello(): redis.rpush('thelist', 'Hello: {} - {}'.format(os.uname()[1], time.time())) the_list = redis.lrange('thelist', 0, -1) return render_template('index.html', the_list=the_list) if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port) app.py
git add . git commit -am ‘Added redis’
heroku addons:add redistogo:nano
git push heroku master heroku open
How can I manage the app?
heroku ps
heroku logs
heroku config
ProTips™
heroku logs --tail
heroku run bash
heroku maintenance:on heroku maintenance:off
Prevent app from sleeping http://pingdom.com
Use foreman locally to run multiple app processes
web: python app.py redis: redis-server Procfile.local
foreman start -f Profile.local
Q&A
Giovanni Collazo @gcollazo