Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Lightweight Web
Services with Sinatra
        Gerred Dillon
     Westin Consulting, LLC
Sinatra is...
Simple.
Simple.



require ‘rubygems’
require ‘sinatra’

get ‘/’ do
 “Hello, world!”
end
Extensible.
Extensible.

require ‘rubygems’
require ‘sinatra’
require ‘active_record’

class Post < ActiveRecord::Base
end

post ‘/cre...
Testable.
Testable.



•Rack::Test
Testable.



•Rack::Test
•Cucumber-Sinatra
Testable.



•Rack::Test
•Cucumber-Sinatra
•RSpec
And most importantly...
And most importantly...




Incredibly lightweight.
Memory Allocation Compared




                             Source: Matt Aimonetti (Merbist)
Memory Allocation Compared

On a request to a simple application...




                                          Source: ...
Memory Allocation Compared

On a request to a simple application...
•Rails 2.3.x allocates 170,000 objects




           ...
Memory Allocation Compared

On a request to a simple application...
•Rails 2.3.x allocates 170,000 objects
•Rails 3 alloca...
Memory Allocation Compared

On a request to a simple application...
•Rails 2.3.x allocates 170,000 objects
•Rails 3 alloca...
Memory Allocation Compared

On a request to a simple application...
•Rails 2.3.x allocates 170,000 objects
•Rails 3 alloca...
Memory Allocation Compared

On a request to a simple application...
•Rails 2.3.x allocates 170,000 objects
•Rails 3 alloca...
Rack
Rack

ActiveModel
Rack

 ActiveModel

ActiveResource
Rack

  ActiveModel

ActiveResource

ActionController
Rack

  ActiveModel

ActiveResource

ActionController

  ActionView
Rack          ActionMailer

  ActiveModel

ActiveResource

ActionController

  ActionView
Rack          ActionMailer

  ActiveModel      ActiveSupport

ActiveResource

ActionController

  ActionView
Rack          ActionMailer

  ActiveModel      ActiveSupport

ActiveResource        Logger

ActionController

  ActionView
Rack          ActionMailer

  ActiveModel      ActiveSupport

ActiveResource        Logger

ActionController    Rails Core...
Rack          ActionMailer

  ActiveModel      ActiveSupport

ActiveResource        Logger

ActionController    Rails Core...
Rack
Rack


Sinatra
Rack


Sinatra


          Application
Rack


Sinatra                 ???


          Application
In the wild...
In the wild...
Scanty
In the wild...
Scanty




                  Haze
In the wild...
Scanty




                    Haze
     Amnesia
In the wild...
Scanty
                            PasteBooth



                    Haze
     Amnesia
In the wild...
Scanty
                            PasteBooth

     UploadBooth

                    Haze
     Amnesia
In the wild...
Scanty
                            PasteBooth

     UploadBooth

                    Haze
     Amnesia
    ...
In the wild...
   Scanty
                                PasteBooth

         UploadBooth

                        Haze
Gi...
In the wild...
   Scanty
                                PasteBooth

         UploadBooth

                        Haze
Gi...
In the wild...
   Scanty
                                PasteBooth

         UploadBooth
                                ...
What about...
awsmimg


A basic image uploader in 59 lines of code.
    Built with BDD concerns in mind.
Deploying Sinatra
Deploying Sinatra

   Passenger
Deploying Sinatra

   Passenger
   Capinatra
Deploying Sinatra

   Passenger
   Capinatra
    Heroku
Deploying Sinatra

           Passenger
           Capinatra
            Heroku


You need a rackup (config.ru) file!
Actually using it...
Actually using it...

•Rails and Sinatra
Actually using it...

•Rails and Sinatra
•ActiveResource and RESTful APIs
Actually using it...

•Rails and Sinatra
•ActiveResource and RESTful APIs
•CouchDB Middleware
Actually using it...

•Rails and Sinatra
•ActiveResource and RESTful APIs
•CouchDB Middleware
•Small, atomic applications
Using Sinatra as a lightweight web service
Using Sinatra as a lightweight web service
Upcoming SlideShare
Loading in …5
×

of

Using Sinatra as a lightweight web service Slide 1 Using Sinatra as a lightweight web service Slide 2 Using Sinatra as a lightweight web service Slide 3 Using Sinatra as a lightweight web service Slide 4 Using Sinatra as a lightweight web service Slide 5 Using Sinatra as a lightweight web service Slide 6 Using Sinatra as a lightweight web service Slide 7 Using Sinatra as a lightweight web service Slide 8 Using Sinatra as a lightweight web service Slide 9 Using Sinatra as a lightweight web service Slide 10 Using Sinatra as a lightweight web service Slide 11 Using Sinatra as a lightweight web service Slide 12 Using Sinatra as a lightweight web service Slide 13 Using Sinatra as a lightweight web service Slide 14 Using Sinatra as a lightweight web service Slide 15 Using Sinatra as a lightweight web service Slide 16 Using Sinatra as a lightweight web service Slide 17 Using Sinatra as a lightweight web service Slide 18 Using Sinatra as a lightweight web service Slide 19 Using Sinatra as a lightweight web service Slide 20 Using Sinatra as a lightweight web service Slide 21 Using Sinatra as a lightweight web service Slide 22 Using Sinatra as a lightweight web service Slide 23 Using Sinatra as a lightweight web service Slide 24 Using Sinatra as a lightweight web service Slide 25 Using Sinatra as a lightweight web service Slide 26 Using Sinatra as a lightweight web service Slide 27 Using Sinatra as a lightweight web service Slide 28 Using Sinatra as a lightweight web service Slide 29 Using Sinatra as a lightweight web service Slide 30 Using Sinatra as a lightweight web service Slide 31 Using Sinatra as a lightweight web service Slide 32 Using Sinatra as a lightweight web service Slide 33 Using Sinatra as a lightweight web service Slide 34 Using Sinatra as a lightweight web service Slide 35 Using Sinatra as a lightweight web service Slide 36 Using Sinatra as a lightweight web service Slide 37 Using Sinatra as a lightweight web service Slide 38 Using Sinatra as a lightweight web service Slide 39 Using Sinatra as a lightweight web service Slide 40 Using Sinatra as a lightweight web service Slide 41 Using Sinatra as a lightweight web service Slide 42 Using Sinatra as a lightweight web service Slide 43 Using Sinatra as a lightweight web service Slide 44 Using Sinatra as a lightweight web service Slide 45 Using Sinatra as a lightweight web service Slide 46 Using Sinatra as a lightweight web service Slide 47 Using Sinatra as a lightweight web service Slide 48 Using Sinatra as a lightweight web service Slide 49 Using Sinatra as a lightweight web service Slide 50 Using Sinatra as a lightweight web service Slide 51 Using Sinatra as a lightweight web service Slide 52 Using Sinatra as a lightweight web service Slide 53 Using Sinatra as a lightweight web service Slide 54 Using Sinatra as a lightweight web service Slide 55 Using Sinatra as a lightweight web service Slide 56 Using Sinatra as a lightweight web service Slide 57
Upcoming SlideShare
Rack
Next

1 Like

Share

Using Sinatra as a lightweight web service

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Using Sinatra as a lightweight web service

  1. 1. Lightweight Web Services with Sinatra Gerred Dillon Westin Consulting, LLC
  2. 2. Sinatra is...
  3. 3. Simple.
  4. 4. Simple. require ‘rubygems’ require ‘sinatra’ get ‘/’ do “Hello, world!” end
  5. 5. Extensible.
  6. 6. Extensible. require ‘rubygems’ require ‘sinatra’ require ‘active_record’ class Post < ActiveRecord::Base end post ‘/create’ do Post.create(:body => “Hello, world!”) end
  7. 7. Testable.
  8. 8. Testable. •Rack::Test
  9. 9. Testable. •Rack::Test •Cucumber-Sinatra
  10. 10. Testable. •Rack::Test •Cucumber-Sinatra •RSpec
  11. 11. And most importantly...
  12. 12. And most importantly... Incredibly lightweight.
  13. 13. Memory Allocation Compared Source: Matt Aimonetti (Merbist)
  14. 14. Memory Allocation Compared On a request to a simple application... Source: Matt Aimonetti (Merbist)
  15. 15. Memory Allocation Compared On a request to a simple application... •Rails 2.3.x allocates 170,000 objects Source: Matt Aimonetti (Merbist)
  16. 16. Memory Allocation Compared On a request to a simple application... •Rails 2.3.x allocates 170,000 objects •Rails 3 allocates 8,500 objects Source: Matt Aimonetti (Merbist)
  17. 17. Memory Allocation Compared On a request to a simple application... •Rails 2.3.x allocates 170,000 objects •Rails 3 allocates 8,500 objects •Sinatra allocates 151 objects Source: Matt Aimonetti (Merbist)
  18. 18. Memory Allocation Compared On a request to a simple application... •Rails 2.3.x allocates 170,000 objects •Rails 3 allocates 8,500 objects •Sinatra allocates 151 objects •Rack allocates 7 objects Source: Matt Aimonetti (Merbist)
  19. 19. Memory Allocation Compared On a request to a simple application... •Rails 2.3.x allocates 170,000 objects •Rails 3 allocates 8,500 objects •Sinatra allocates 151 objects •Rack allocates 7 objects Application performance directly corresponds to Ruby’s garbage collector! The garbage collector will run every ~6 requests on Rails 3. Source: Matt Aimonetti (Merbist)
  20. 20. Rack
  21. 21. Rack ActiveModel
  22. 22. Rack ActiveModel ActiveResource
  23. 23. Rack ActiveModel ActiveResource ActionController
  24. 24. Rack ActiveModel ActiveResource ActionController ActionView
  25. 25. Rack ActionMailer ActiveModel ActiveResource ActionController ActionView
  26. 26. Rack ActionMailer ActiveModel ActiveSupport ActiveResource ActionController ActionView
  27. 27. Rack ActionMailer ActiveModel ActiveSupport ActiveResource Logger ActionController ActionView
  28. 28. Rack ActionMailer ActiveModel ActiveSupport ActiveResource Logger ActionController Rails Core ActionView
  29. 29. Rack ActionMailer ActiveModel ActiveSupport ActiveResource Logger ActionController Rails Core ActionView Application
  30. 30. Rack
  31. 31. Rack Sinatra
  32. 32. Rack Sinatra Application
  33. 33. Rack Sinatra ??? Application
  34. 34. In the wild...
  35. 35. In the wild... Scanty
  36. 36. In the wild... Scanty Haze
  37. 37. In the wild... Scanty Haze Amnesia
  38. 38. In the wild... Scanty PasteBooth Haze Amnesia
  39. 39. In the wild... Scanty PasteBooth UploadBooth Haze Amnesia
  40. 40. In the wild... Scanty PasteBooth UploadBooth Haze Amnesia Chargd
  41. 41. In the wild... Scanty PasteBooth UploadBooth Haze GitHub Amnesia Chargd
  42. 42. In the wild... Scanty PasteBooth UploadBooth Haze GitHub Amnesia Chargd Webnailer
  43. 43. In the wild... Scanty PasteBooth UploadBooth Integrity Haze GitHub Amnesia Chargd Webnailer
  44. 44. What about...
  45. 45. awsmimg A basic image uploader in 59 lines of code. Built with BDD concerns in mind.
  46. 46. Deploying Sinatra
  47. 47. Deploying Sinatra Passenger
  48. 48. Deploying Sinatra Passenger Capinatra
  49. 49. Deploying Sinatra Passenger Capinatra Heroku
  50. 50. Deploying Sinatra Passenger Capinatra Heroku You need a rackup (config.ru) file!
  51. 51. Actually using it...
  52. 52. Actually using it... •Rails and Sinatra
  53. 53. Actually using it... •Rails and Sinatra •ActiveResource and RESTful APIs
  54. 54. Actually using it... •Rails and Sinatra •ActiveResource and RESTful APIs •CouchDB Middleware
  55. 55. Actually using it... •Rails and Sinatra •ActiveResource and RESTful APIs •CouchDB Middleware •Small, atomic applications
  • tanbamboo

    Mar. 11, 2011

Views

Total views

3,709

On Slideshare

0

From embeds

0

Number of embeds

1

Actions

Downloads

0

Shares

0

Comments

0

Likes

1

×