Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

note about heroku

latest commit 9add02ddcd
John Bachir authored November 16, 2011
Octocat-spinner-32 app have the controller do stuff. November 16, 2011
Octocat-spinner-32 config thin and threads! November 16, 2011
Octocat-spinner-32 db first commit November 16, 2011
Octocat-spinner-32 doc first commit November 16, 2011
Octocat-spinner-32 lib first commit November 16, 2011
Octocat-spinner-32 log first commit November 16, 2011
Octocat-spinner-32 public first commit November 16, 2011
Octocat-spinner-32 script first commit November 16, 2011
Octocat-spinner-32 test first commit November 16, 2011
Octocat-spinner-32 vendor first commit November 16, 2011
Octocat-spinner-32 .gitignore first commit November 16, 2011
Octocat-spinner-32 Gemfile thin and threads! November 16, 2011
Octocat-spinner-32 Gemfile.lock thin and threads! November 16, 2011
Octocat-spinner-32 Procfile procfile November 16, 2011
Octocat-spinner-32 Rakefile first commit November 16, 2011
Octocat-spinner-32 config.ru first commit November 16, 2011
Octocat-spinner-32 readme.md note about heroku November 16, 2011
readme.md

A tiny example of a rails app serving requests asynchronously.

relevant things to look at

  • mycontroller_controller.rb
  • application.rb (config.threadsafe!)
  • Procfile

how to run the server

synchronously: bundle exec thin start

asynchronously: bundle exec thin start --threaded

how to observe synchronous vs. asynchronous behavior

compare behavior when refreshing http://0.0.0.0:3000/mycontroller/slow and http://0.0.0.0:3000/mycontroller/fast. When running without threads, fast will always have to wait for slow. When running with threads, you can refresh fast with wild abandon while waiting for a request to slow to finish.

how to benchmark

ab -n 1000 -c 10 http://0.0.0.0:3000/mycontroller/fast

Threaded mode is successfully asynchronous, but serves fewer requests per second.

does it work asynchronously on heroku?

yes

open questions

  1. Is anyone in the world doing this in production?
  2. How does thin decide how many threads to create?
  3. What is the space complexity of each thread?
  4. Why is threaded slower? (MRI 1.9.2 and 1.9.3)

discussion elsewhere

Something went wrong with that request. Please try again.