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
750
BarcampVSJ
gcollazo
4
62
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
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
最新TCAキャッチアップ
0si43
0
190
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Featured
See All Featured
RailsConf 2023
tenderlove
29
900
Code Review Best Practice
trishagee
64
17k
A Philosophy of Restraint
colly
203
16k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Speed Design
sergeychernyshev
25
620
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
It's Worth the Effort
3n
183
27k
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