Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Brooklyn - Small web tool

Brooklyn - Small web tool

Brooklyn is a small (~300 LOC) rack-based application builder. Was made as proof of concept that fast and small code can still work.

Presented as RubyConf Argentina Lighting talk.

Luis Lavena

December 02, 2013

More Decks by Luis Lavena

Other Decks in Programming


  1. Brooklyn, NY Small Ruby web tool github.com/luislavena/brooklyn

  2. Luis Lavena Work: area17.com Twitter: @luislavena GitHub: luislavena

  3. Problem Create minimal service (just JSON) In Ruby Rack compatible

  4. Drama Need for speed (fewer allocs/req) Less Ruby magic No

    backward compatibility Small codebase No code is faster than no code
  5. Goal Understand what is going on

  6. Reference: Rack class HelloWorld def call(env) [ 200, {"Content-Type" =>

    "text/html"}, ["Hello World!"] ] end end run HelloWorld.new
  7. Minimal DSL (Sinatra) require "sinatra/base" class HelloWorld < Sinatra::Base get

    "/" do "Hello World!" end end run HelloWorld
  8. Brooklyn require "brooklyn" class HelloWorld < Brooklyn::App get "/" do

    "Hello World!" end end run HelloWorld.new
  9. Codebase Sinatra: 2035 lines (1738 sloc, 1 file) Brooklyn: 217

    lines (165 sloc, 7 files)
  10. Performance Rack: 7637 req/sec (1.0x) Sinatra: 2712 req/sec (0.35x) Brooklyn:

    5827 req/sec (0.76x) github.com/luislavena/bench-micro
  11. Again Rack-powered (use middlewares) No code is faster than no

    code Less ruby magic Code you can understand (in 10 minutes)
  12. Thanks! github.com/luislavena/brooklyn