celluloid/celluloid — pull request #371 by cheald (2014-01-27 23:01:23+00:00)
Title: Pooled fibers

(Recreated based off of master now)

This adds support for a variant on TaskFiber which pools fibers for a given thread. This is primarily a triage patch for JRuby 1.7.5+ which isn't currently pooling the threads that back its fibers, resulting in a ridonkulous amount of CPU burn as it spins up a new thread per Fiber. See jruby/jruby#1443 for full details there.

This is the same fiber pattern used by rack-fiber_pool, among others. In my tests, it's completely eliminated the JRuby CPU thrashing, and actually improved performance of Celluloid under MRI, too.

Using [this very unrigorous benchmark](https://gist.github.com/cheald/94097ddb2a855cdb2583), I saw the following results:

| | TaskFiber | TaskPooledFiber |
|--------------|---------------------|-----------------|
| 2.0.0-p247 | 4.08 sec | 2.79 sec |
| jruby-1.7.10 | 29.5 sec (not a typo) | 5.04 sec |