README.md

Async Rails 3.1 stack demo

Important warning:

You should be aware when using fibers with Rails that you can get a stack overflow error if your stack grows
bigger than 4Kb (which is enough for most things though), this got even worse with the 3.1 release in which
you can easily overflow the stack, here is an example here.

Simple async demo stack with Rails 3.1 + EventMachine and Fibers.

Hit localhost:3000/widgets to do a 1s async mysql query

Hit localhost:3000/widgets/http to make an HTTP call back to /widgets - recursive! :-)

Concurrency

We're running on a single reactor, so above is proof that we can execute HTTP+MySQL queries in non-blocking fashion on a single run loop / within single process:

AB opens 5 concurrent requests (10 total)

Each request to /widgets/http opens an async HTTP request to /widgets - aka, we ourselves spawn another 5 requests

Because the fiber pool is set to 10, it means we can process all 5 requests within ~1s (each mysql req takes 1s)

10 requests finish in ~2s

So, keep in mind that the size of 'database pool' is basically your concurrency throttle. In example above, we spawn
10 requests, which open another 10 internally, so in total we process 20 req's in ~2s on a single thing server. Just as expected.