RailsConf: Art of the Ruby Proxy for Scale, Performance, and Monitoring – Ilya Grigorik (AideRSS Inc.)

May 7, 2009 Pivotal Labs

Slides are online already

Random nuggets from the talk:

The overhead of most requests is calls out of a framework to a DB, FS etc, but because it is called from the framework, that is what gets the blame. This sustains the myth that “<insert your framework of choice> doesn’t scale”. Solution: put a proxy in front of the server and duplicate the server behind it.

Types of proxy:

  • Transparent
  • Intercepting
  • Caching

Transparent Cut-Through Proxy = 90% use case

  • Transparent Proxy – user cannot detect he is behind a proxy
  • Cut-Through – forwards on the fly (not store and forward)

The Problem

Flaws of Staging environments:

  • Any change in profile of queries invalidates your testing
  • Cost

The Solution

  • What if you could take your production traffic and fork it to two environments


  • EventMachine inplements a design pattern knows as the reactor pattern
  • Will connect to any file descriptor (e.g. a socket)
  • Written in C++ for high performance and concurrency without threads
  • EM does have a native thread pool used for EM.defer
  • http://bit.ly/aiderss-eventmachine excellent PDF to document EM


  • http://github.com/igrigorik/em-proxy
  • A simple DSL for writing proxy servers.
  • The return from on_data and on_response blocks is just passed on/back.
  • If you return nil from a block, no data gets forwarded.
  • 5% performance hit for large messages
  • 20% perforamnce hit if messages are very small, mitigate by putting behind HA proxy and add another server.
  • No way to send to only 1 back-end server yet (can’t implement a load-balancing proxy).

Misc name-dropping

  • httpperf is really good for replaying traffic against a site
  • igrigorik/autoperf – replay nginx logs against your site
  • Recommended we look at MySQL proxy – awesome dashboard.
  • Nginx does really good things with compression (gzip, ETAGS etc).
  • Mailtrap is a fake SMTP server gem for testing sending email from your Rails app.
  • Defensio is a smap filter for blogs. API you can send comments to and it will tell you if it is spam or not. Returns a ‘spam index’.
  • Beanstalk is an in-memory distributed message queue. Despite frequent requests, they have not implemented persistence, which is what motivated Ilya to work around them with this proxy server.

About the Author


More Content by Pivotal Labs
Railsconf: HTTP's Best-Kept Secret: Caching – Ryan Tomayko (Heroku)
Railsconf: HTTP's Best-Kept Secret: Caching – Ryan Tomayko (Heroku)

HTTP's Best-Kept Secret: Caching Ryan Tomayko (Heroku) About Ryan http://tomayko.com Sinatra maintainer. ...

Erector 0.6.3 – Now Ready to Conquer The World
Erector 0.6.3 – Now Ready to Conquer The World

[Updated: added instructions "If you are using a widget in rails, you now need to inherit from RailsWidget"...

SpringOne Platform 2019

Learn More