After Andrea O. K. Wright’s wildly popular (popular as in she had to schedule
a second session after the first one literally overflowed with people)
RailsConf talk
it seems like now is a good time to give an update on my plans for the
Omnibus Concurrency Library, especially after I’ve neglected it for so
long.
At this point, the next version of the library is likely to be a complete
rewrite, licensed under an MIT-style license similar to Rubinius’. It will
aim to support at least the following Ruby implementations, with others
following as time and interest permit:
- Ruby 1.8
- Ruby 1.9
- Rubinus
- JRuby
Portability
Presently, only JRuby presents opportunities for improved parallel
performance with Omnibus’ thread-centric implementation; under Ruby 1.8,
1.9, and Rubinius, performance will necessarily be equal to or less than
single-threaded performance. Why support them at all? There are two
main reasons:
The first reason to support green-threaded Ruby implementations is for the
sake of portability, allowing the same program that runs under JRuby on a
multi-core behemoth from Sun to scale all the way down to a single-CPU
machine running Ruby 1.8 with its green threads.
Secondly, concurrent programming abstractions are often convenient ways to
structure programs even on single-processor systems. (If they weren’t,
nobody would ever bother with Ruby 1.8’s green threads.)
Additionally, the concurrency picture for some of these Ruby implementations
is not necessarily bleak in the long-term: Rubinius already permits
taking advantage of multiple threads per process in separate VMs. A
future version of Rubinius may offer more fine-grained multicore support,
and a future version of Omnibus may find ways to exploit things like the
existing per-VM multicore support, or even include support for fork-based
parallelism for some purposes.
Organization
Rather than Omnibus remaining a monolithic library, I’m also going to be
breaking things up in order to enable individual components to be released
as separate gems (and hopefully in a more timely fashion):
- concurrent – “omnibus” gem which pulls in the others as dependencies
- concurrent-actors – Actors for Ruby
- concurrent-futures – Futures for Ruby
- concurrent-joins – Join calculus for Ruby
- concurrent-parallel – Parallel algorithms and parallel extensions to core/stdlib classes (corresponding roughly to TBB parallel algorithms)
- concurrent-primitives – Grab-bag of simple primitives like channels
- concurrent-selectable – Semaphore and a few other primitives which can be waited on using existing event-based IO libraries, or just IO.select (DONE)
- concurrent-sequential – Force strict sequential execution of asynchronous tasks, even in the face of multiple threads or reentrancy. Don’t laugh, it’s useful.
- concurrent-tasks – Task-oriented parallelism (similar to TBB tasks)
Major Changes and Incompatibilities
One of the major changes coming is that the library will handle
asynchronous tasks (e.g. from futures, or joins) by dispatching them to
a TBB-like task scheduler instead of simply spawning a new thread for each
task. In most cases this means that the creation of continuation tasks is
the preferred alternative to blocking, although there will still be
provisions to support blocking tasks. The largest effect of this change
will be the elimination of transparent futures from the core library,
since they have the effect of causing arbitrary tasks to block, and
have consistently been the most difficult feature of the library to
implement portably anyway.
There will also be some less drastic, but incompatible, changes to the rest
of the existing APIs. In particular, parallel algorithms will take grain
sizes rather than a count of threads to spawn, and the actor API will
be modified to match the current Rubinius API more closely.
Timeline
Especially since Omnibus is a spare time project for me at the moment,
I can’t commit to a timetable for the new release, but at the moment
I’m aiming to have the new release out in 2-3 months. Watch this space.
(Incidentally, feel free to contact me if you’re interested in funding
some aspect of Omnibus development. I am committed to finishing Omnibus
regardless, but obviously paid projects have to take precedence.)