Home

Awesome

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.

Howto / example commits:

Requirements:

Environment setup:

Starting up Rails:

Concurrency

ab -c 5 -n 10 http://127.0.0.1:3000/widgets/

    Concurrency Level:      5
    Time taken for tests:   2.740 seconds
    Complete requests:      10

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:

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.

Benchmarks

Pushing the stack on my MBP (db pool = 250; fiber pool = 250; env = production; thin 1.2.7) results in:

    Concurrency Level:      220
    Time taken for tests:   10.698 seconds
    Complete requests:      2000
    Failed requests:        0
    Write errors:           0
    Total transferred:      470235 bytes
    HTML transferred:       12006 bytes
    Requests per second:    186.95 [#/sec] (mean)
    Time per request:       1176.777 [ms] (mean)
    Time per request:       5.349 [ms] (mean, across all concurrent requests)
    Transfer rate:          42.93 [Kbytes/sec] received

For full AB trace see this gist

Resources:

Other: