SlideShare une entreprise Scribd logo
1  sur  26
Rails in the Cloud
Ian Warshak

Developer @ RightScale

http://twitter.com/iwarshak

http://github.com/iwarshak/lsrc-cloud
The Clouds
Cloud Infrastructure       Cloud Services


                         Amazon S3
Amazon Ec2
                         Amazon SQS
Rackspace Cloudservers
                         Amazon SimpleDB
Flexiscale
                         Google AppEngine
GoGrid
                         Heroku
Pictr
Photo website. You upload photos, they are
resized, watermarked, and put on the homepage

Photos can be uploaded by the public

Photos are converted asynchronously by
separate processing servers

Very simple app, but hopefully shows some
ideas of how cloud computing apps work
Why Pictr?
Lots of Disk Storage

Lots of Bandwidth

Offline processing

I want to manage and host as little as possible

It will be an instant hit. Needs to scale from day 1
Don’t get your hopes up
about Pictr!
Why the Cloud?
I don’t want to build or configure hardware.

I don’t want to do much capacity planning.

I want to pay as I go for servers and service.

Offload as much as possible.

Lots of Bandwidth

Offline processing

I want to manage and host as little as possible

It will be an instant hit. Needs to scale from day 1
How is it built?

Rails application running on Amazon EC2 servers

Asynchronous image processing (resizing, effects)

Database is Amazon SimpleDB

Storage is Amazon S3

CDN is Amazon Cloudfront

Messaging queue is Amazon SQS

ImageMagick is used for image manipulation
gem install right_aws
Why Amazon?
Simple. Right now, they are the market leader...
But the competition is good.

Tight integration between services

RESTful APIs for their services

Lots of documentation and libraries
Amazon Ec2
Servers “on demand”.

Pay by the hour: $0.10 - $0.80/hour

Non-persistent.

Forces you to automate your configuration.

RightScale helps a lot with this.

Elastic IP can give you a static IP

Elastic Block Store gives you persistent data
store
Amazon S3
Oldest of the publicly available web services

Scalable, reliable data storage mechanism

Bucket/object concept

Pay for the data you are storing, as well as
bandwidth in and out

$0.15/GB stored. $0.10/GB transferred. $0.01/
request.

Very fine grained permissions
CloudFront
  Similar to LimeLight, Akamai

  Low latency, high data rate transfers

  8 edge locations in the US

  Origin server is an S3 bucket

  24 hour object expiration

  Very simple API

acf = RightAws::AcfInterface.new
acf.create_distribution('pictr.s3.amazonaws.com', 'Woo-Hoo!', true)
Amazon Simple Queue Service

 Reliable, scalable queue

 PUSH and PULL messages

 Messages can be up to 8K of text

 Messages are “locked” as they are processed,
 preventing them from being read multiple times.
Amazon SimpleDB
 Simple (but powerful) database

 Non-relational. No tables, only “domains”. No joins.

 No schema. Define it as you go.

 All data is stored as strings.

 Attributes can have up to 256 values.

 Automatically indexes all your data.

 Not exactly a speed daemon.
Amazon SimpleDB
ActiveSDB

RightAws::ActiveSdb.establish_connection
class Item < RightAws::ActiveSdb::Base; end

Item.create_domain
item = Item.create :Category => "Electronics", :Size => 47, :Manufacturer => "Sony"

# Add a new "column"
item["Illumination"] = "LCD"
item.save

# New category. Now, category is an "array"
item["Category"] << "Televisions"
item.save

items = Item.select(:all, :conditions => ["Size = ?", 47])
# => [#<Item:0x1a8a5ec @new_record=false, @attributes={"Size"=>["47"], "Category"=>["Electronics",
"Televisions"], "id"=>"788b5192-8a85-11de-a035-00264a1272e2", "Manufacturer"=>["Sony"],
"Illumination"=>["LCD"]}>]
SimpleDB caveats

All data is stored as a string.

Response cannot be > 1MB

Maximum query execution time: 5 sec

Eventually consistent (a tradeoff for availability)

Speed (network)
What does all this mean?
 I worry less about scaling

 I worry more about configuration management
 and automation

 Database performance is very consistent

 S3, Cloudfront handles static file serving

 Minimal upfront investment

 Only pay for what I need
SQS


              SimpleDB
Web Servers              Converter Servers




               S3
  Users
Step 1: Upload

    S3




                          EC2 INSTANCE
            REDIRECT ON
            SUCCESS

  POST
  PIC.JPG

                          INITIATES PROCESSING
Step 2: Queue the jobs

# Jobs are created
jobs = [ConvertJob.new(key, "paint", "400", "-paint 5"),
ConvertJob.new(key, "monochrome", "400", "-monochrome")]

# Push the jobs into the queue
sqs = RightAws::SqsGen2.new
convert_queue = sqs.queue("convert")

jobs.each do |job|
  convert_queue.send_message job.to_json
end
Step 3: Create SimpleDB record



# class Picture < RightAws::ActiveSdb::Base
# ...
# end

picture = Picture.create(:key => key)
picture["total_conversions"] = ["paint", "monochrome"]
picture.save
SimpleDB record

# Before conversion
{"key"=>["uploads/f1"],
"total_conversions"=>["paint", "monochrome"]}

# After conversion
{"key"=>["uploads/f1"],
"total_conversions"=>["paint", "monochrome"],
"paint"=>["processed/f1_paint.jpg"],
"monochrome"=>["processed/f1_monochrome.jpg"]
}
Step 4: Processor Daemon

 loop do
   sqs = RightAws::SqsGen2.new
   convert_queue = sqs.queue("convert")

  message = convert_queue.pop
  if message
    job = JSON.parse message.to_s
    puts "Found a new message #{job.key}"
    job.run!
  end
  sleep(5)
 end
Demo
Thanks!

right_aws gem

http://github.com/iwarshak/lsrc-cloud

twitter.com/iwarshak

Contenu connexe

Tendances

Aws cloud best_practices
Aws cloud best_practicesAws cloud best_practices
Aws cloud best_practices
Suruli Kannan
 

Tendances (20)

Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3
 
Aws cloud best_practices
Aws cloud best_practicesAws cloud best_practices
Aws cloud best_practices
 
AWS User Group December 2016
AWS User Group December 2016AWS User Group December 2016
AWS User Group December 2016
 
Amazon ec2
Amazon ec2Amazon ec2
Amazon ec2
 
When Should You Use AWS Lambda?
When Should You Use AWS Lambda?When Should You Use AWS Lambda?
When Should You Use AWS Lambda?
 
Serverless Architecture
Serverless ArchitectureServerless Architecture
Serverless Architecture
 
What is AWS lambda?
What is AWS lambda?What is AWS lambda?
What is AWS lambda?
 
T3 - Deploy, manage, and scale your apps
T3 - Deploy, manage, and scale your appsT3 - Deploy, manage, and scale your apps
T3 - Deploy, manage, and scale your apps
 
AWS Big Data combo
AWS Big Data comboAWS Big Data combo
AWS Big Data combo
 
Accelerate Your Java Development on AWS (TLS301) | AWS re:Invent 2013
Accelerate Your Java Development on AWS (TLS301) | AWS re:Invent 2013Accelerate Your Java Development on AWS (TLS301) | AWS re:Invent 2013
Accelerate Your Java Development on AWS (TLS301) | AWS re:Invent 2013
 
Deploying Data Science with Docker and AWS
Deploying Data Science with Docker and AWSDeploying Data Science with Docker and AWS
Deploying Data Science with Docker and AWS
 
Services comparison among Microsoft Azure AWS and Google Cloud Platform
Services comparison among Microsoft Azure AWS and Google Cloud PlatformServices comparison among Microsoft Azure AWS and Google Cloud Platform
Services comparison among Microsoft Azure AWS and Google Cloud Platform
 
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
 
Container Orchestration with Amazon ECS
Container Orchestration with Amazon ECSContainer Orchestration with Amazon ECS
Container Orchestration with Amazon ECS
 
Major Container Platform Comparison
Major Container Platform ComparisonMajor Container Platform Comparison
Major Container Platform Comparison
 
Building a data warehouse with Amazon Redshift … and a quick look at Amazon ...
Building a data warehouse  with Amazon Redshift … and a quick look at Amazon ...Building a data warehouse  with Amazon Redshift … and a quick look at Amazon ...
Building a data warehouse with Amazon Redshift … and a quick look at Amazon ...
 
Amazon Lightsail
Amazon LightsailAmazon Lightsail
Amazon Lightsail
 
How to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda RuntimeHow to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda Runtime
 
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
 
AWS Lambda Tutorial | Introduction to AWS Lambda | AWS Tutorial | AWS Trainin...
AWS Lambda Tutorial | Introduction to AWS Lambda | AWS Tutorial | AWS Trainin...AWS Lambda Tutorial | Introduction to AWS Lambda | AWS Tutorial | AWS Trainin...
AWS Lambda Tutorial | Introduction to AWS Lambda | AWS Tutorial | AWS Trainin...
 

En vedette (7)

Jantima Resume
Jantima ResumeJantima Resume
Jantima Resume
 
Powerpoint
PowerpointPowerpoint
Powerpoint
 
WordPress Policy Primer
WordPress Policy PrimerWordPress Policy Primer
WordPress Policy Primer
 
Ihya' ramadhan
Ihya' ramadhanIhya' ramadhan
Ihya' ramadhan
 
Grant Presentation
Grant PresentationGrant Presentation
Grant Presentation
 
Linkedin executive-playbook
Linkedin executive-playbookLinkedin executive-playbook
Linkedin executive-playbook
 
Link Analysis and Link Building in a Penguin and Disavow World
Link Analysis and Link Building in a Penguin and Disavow WorldLink Analysis and Link Building in a Penguin and Disavow World
Link Analysis and Link Building in a Penguin and Disavow World
 

Similaire à Rails in the Cloud

AWS Cloud Kata | Manila - Getting to Scale on AWS
AWS Cloud Kata | Manila - Getting to Scale on AWSAWS Cloud Kata | Manila - Getting to Scale on AWS
AWS Cloud Kata | Manila - Getting to Scale on AWS
Amazon Web Services
 
AWS Cloud Kata | Taipei - Getting to Scale
AWS Cloud Kata | Taipei - Getting to ScaleAWS Cloud Kata | Taipei - Getting to Scale
AWS Cloud Kata | Taipei - Getting to Scale
Amazon Web Services
 
AWS Startup Webinar | Developing on AWS
AWS Startup Webinar | Developing on AWSAWS Startup Webinar | Developing on AWS
AWS Startup Webinar | Developing on AWS
Amazon Web Services
 
Cloud computing workshop at IIT bombay
Cloud computing workshop at IIT bombayCloud computing workshop at IIT bombay
Cloud computing workshop at IIT bombay
Nilesh Satpute
 

Similaire à Rails in the Cloud (20)

The Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with RubyThe Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with Ruby
 
Cloud computing-Practical Example
Cloud computing-Practical ExampleCloud computing-Practical Example
Cloud computing-Practical Example
 
Media Processing Workflows using AWS Step Functions and Machine Learning on A...
Media Processing Workflows using AWS Step Functions and Machine Learning on A...Media Processing Workflows using AWS Step Functions and Machine Learning on A...
Media Processing Workflows using AWS Step Functions and Machine Learning on A...
 
How to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless EditionHow to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless Edition
 
AWS 201 - A Walk through the AWS Cloud: App Hosting on AWS - Games, Apps and ...
AWS 201 - A Walk through the AWS Cloud: App Hosting on AWS - Games, Apps and ...AWS 201 - A Walk through the AWS Cloud: App Hosting on AWS - Games, Apps and ...
AWS 201 - A Walk through the AWS Cloud: App Hosting on AWS - Games, Apps and ...
 
How to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless EditionHow to Build a Big Data Application: Serverless Edition
How to Build a Big Data Application: Serverless Edition
 
Why Scale Matters and How the Cloud is Really Different (at scale)
Why Scale Matters and How the Cloud is Really Different (at scale)Why Scale Matters and How the Cloud is Really Different (at scale)
Why Scale Matters and How the Cloud is Really Different (at scale)
 
Building and scaling a B2D service, the bootstrap way
Building and scaling a B2D service, the bootstrap wayBuilding and scaling a B2D service, the bootstrap way
Building and scaling a B2D service, the bootstrap way
 
Serverless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesServerless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best Practices
 
McrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and AmazonMcrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and Amazon
 
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
AWS re:Invent 2016: IoT Visualizations and Analytics (IOT306)
 
NodeJS @ ACS
NodeJS @ ACSNodeJS @ ACS
NodeJS @ ACS
 
AWS Cloud Kata | Manila - Getting to Scale on AWS
AWS Cloud Kata | Manila - Getting to Scale on AWSAWS Cloud Kata | Manila - Getting to Scale on AWS
AWS Cloud Kata | Manila - Getting to Scale on AWS
 
Fowa Miami 09 Cloud Computing Workshop
Fowa Miami 09 Cloud Computing WorkshopFowa Miami 09 Cloud Computing Workshop
Fowa Miami 09 Cloud Computing Workshop
 
AWS Cloud Kata | Taipei - Getting to Scale
AWS Cloud Kata | Taipei - Getting to ScaleAWS Cloud Kata | Taipei - Getting to Scale
AWS Cloud Kata | Taipei - Getting to Scale
 
AWS Startup Webinar | Developing on AWS
AWS Startup Webinar | Developing on AWSAWS Startup Webinar | Developing on AWS
AWS Startup Webinar | Developing on AWS
 
AWS Webcast - What is Cloud Computing?
AWS Webcast - What is Cloud Computing?AWS Webcast - What is Cloud Computing?
AWS Webcast - What is Cloud Computing?
 
Cloud computing workshop at IIT bombay
Cloud computing workshop at IIT bombayCloud computing workshop at IIT bombay
Cloud computing workshop at IIT bombay
 
Deep Dive on Microservices and Docker
Deep Dive on Microservices and DockerDeep Dive on Microservices and Docker
Deep Dive on Microservices and Docker
 
SRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and DockerSRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and Docker
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Rails in the Cloud

  • 1. Rails in the Cloud Ian Warshak Developer @ RightScale http://twitter.com/iwarshak http://github.com/iwarshak/lsrc-cloud
  • 2. The Clouds Cloud Infrastructure Cloud Services Amazon S3 Amazon Ec2 Amazon SQS Rackspace Cloudservers Amazon SimpleDB Flexiscale Google AppEngine GoGrid Heroku
  • 3. Pictr Photo website. You upload photos, they are resized, watermarked, and put on the homepage Photos can be uploaded by the public Photos are converted asynchronously by separate processing servers Very simple app, but hopefully shows some ideas of how cloud computing apps work
  • 4. Why Pictr? Lots of Disk Storage Lots of Bandwidth Offline processing I want to manage and host as little as possible It will be an instant hit. Needs to scale from day 1
  • 5. Don’t get your hopes up about Pictr!
  • 6. Why the Cloud? I don’t want to build or configure hardware. I don’t want to do much capacity planning. I want to pay as I go for servers and service. Offload as much as possible. Lots of Bandwidth Offline processing I want to manage and host as little as possible It will be an instant hit. Needs to scale from day 1
  • 7. How is it built? Rails application running on Amazon EC2 servers Asynchronous image processing (resizing, effects) Database is Amazon SimpleDB Storage is Amazon S3 CDN is Amazon Cloudfront Messaging queue is Amazon SQS ImageMagick is used for image manipulation
  • 9. Why Amazon? Simple. Right now, they are the market leader... But the competition is good. Tight integration between services RESTful APIs for their services Lots of documentation and libraries
  • 10. Amazon Ec2 Servers “on demand”. Pay by the hour: $0.10 - $0.80/hour Non-persistent. Forces you to automate your configuration. RightScale helps a lot with this. Elastic IP can give you a static IP Elastic Block Store gives you persistent data store
  • 11. Amazon S3 Oldest of the publicly available web services Scalable, reliable data storage mechanism Bucket/object concept Pay for the data you are storing, as well as bandwidth in and out $0.15/GB stored. $0.10/GB transferred. $0.01/ request. Very fine grained permissions
  • 12. CloudFront Similar to LimeLight, Akamai Low latency, high data rate transfers 8 edge locations in the US Origin server is an S3 bucket 24 hour object expiration Very simple API acf = RightAws::AcfInterface.new acf.create_distribution('pictr.s3.amazonaws.com', 'Woo-Hoo!', true)
  • 13. Amazon Simple Queue Service Reliable, scalable queue PUSH and PULL messages Messages can be up to 8K of text Messages are “locked” as they are processed, preventing them from being read multiple times.
  • 14. Amazon SimpleDB Simple (but powerful) database Non-relational. No tables, only “domains”. No joins. No schema. Define it as you go. All data is stored as strings. Attributes can have up to 256 values. Automatically indexes all your data. Not exactly a speed daemon.
  • 16. ActiveSDB RightAws::ActiveSdb.establish_connection class Item < RightAws::ActiveSdb::Base; end Item.create_domain item = Item.create :Category => "Electronics", :Size => 47, :Manufacturer => "Sony" # Add a new "column" item["Illumination"] = "LCD" item.save # New category. Now, category is an "array" item["Category"] << "Televisions" item.save items = Item.select(:all, :conditions => ["Size = ?", 47]) # => [#<Item:0x1a8a5ec @new_record=false, @attributes={"Size"=>["47"], "Category"=>["Electronics", "Televisions"], "id"=>"788b5192-8a85-11de-a035-00264a1272e2", "Manufacturer"=>["Sony"], "Illumination"=>["LCD"]}>]
  • 17. SimpleDB caveats All data is stored as a string. Response cannot be > 1MB Maximum query execution time: 5 sec Eventually consistent (a tradeoff for availability) Speed (network)
  • 18. What does all this mean? I worry less about scaling I worry more about configuration management and automation Database performance is very consistent S3, Cloudfront handles static file serving Minimal upfront investment Only pay for what I need
  • 19. SQS SimpleDB Web Servers Converter Servers S3 Users
  • 20. Step 1: Upload S3 EC2 INSTANCE REDIRECT ON SUCCESS POST PIC.JPG INITIATES PROCESSING
  • 21. Step 2: Queue the jobs # Jobs are created jobs = [ConvertJob.new(key, "paint", "400", "-paint 5"), ConvertJob.new(key, "monochrome", "400", "-monochrome")] # Push the jobs into the queue sqs = RightAws::SqsGen2.new convert_queue = sqs.queue("convert") jobs.each do |job| convert_queue.send_message job.to_json end
  • 22. Step 3: Create SimpleDB record # class Picture < RightAws::ActiveSdb::Base # ... # end picture = Picture.create(:key => key) picture["total_conversions"] = ["paint", "monochrome"] picture.save
  • 23. SimpleDB record # Before conversion {"key"=>["uploads/f1"], "total_conversions"=>["paint", "monochrome"]} # After conversion {"key"=>["uploads/f1"], "total_conversions"=>["paint", "monochrome"], "paint"=>["processed/f1_paint.jpg"], "monochrome"=>["processed/f1_monochrome.jpg"] }
  • 24. Step 4: Processor Daemon loop do sqs = RightAws::SqsGen2.new convert_queue = sqs.queue("convert") message = convert_queue.pop if message job = JSON.parse message.to_s puts "Found a new message #{job.key}" job.run! end sleep(5) end
  • 25. Demo

Notes de l'éditeur

  1. rightscale is a cloud management platform goal is to give you an overview of some of the cloud technologies, and how you can use ruby to leverage them for your own app will show you a sample app
  2. no users, no permissions. nothing.
  3. photo processing is a good sample app.
  4. completely contrived could scale pretty well if needed. around 300 lines of code
  5. tongue in cheek
  6. boot in a few minutes animoto story
  7. starling, based on memcached beanstalkd
  8. people are starting to look at alternatives to traditional ACID databases. too much overhead, and not scalable enough. database is first big bottleneck very consistent. 100, 10,000, 1,000,000 records all had similar response time. ~100ms return from a query is ids, you need to reload to get attributes
  9. first version of API had a very custom. algabraic query language. now supporting more SQL like expressions. union, intersection. now deprecated.
  10. get a token to retrieve next set of results if results are too big
  11. show the job.rb class
  12. Very similar to activerecord
  13. job is a ConvertJob. show it.