InfoQ

News

Kilim - actors and message passing in Java

Posted by Niclas Nilsson on Jun 26, 2008

Community
Architecture,
Java
Topics
Performance & Scalability
Tags
Concurrency

As discussed in The multicore crises: Scala vs. Erlang, massage passing and the actor model of concurrency is one promising way for the massive parallelization needed to utilize current and especially future CPUs. Erlang has it built in from the start and Scala incorporated the Scala Actor library into it’s framework. But there is also a pure Java solution - Kilim

Kilim is a message-passing framework for Java that claims provides ultra-lightweight threads and facilities for fast, safe, zero-copy messaging between these threads.

It consists of a bytecode postprocessor (a “weaver”), a run time library with buffered mailboxes (multi-producer, single consumer queues) and a user-level scheduler and a type system that puts certain constraints on pointer aliasing within messages to ensure interference-freedom between threads.

And it seems to perform well. According to Sriram Srinivasan in his Google Tech Talk, task-switching in Kilim is 1000x faster than Java threads and its message-passing is 3x faster than Erlang.

Kilim works with code annotations on methods and arguments. A method is annotated as @pausable if it directly it indirectly calls other pausable methods, which somewhere in the call chain will result in calls to Kilim methods, such as Actor.sleep() or Mailbox.get(). The annotated code is transformed by the bytecode weaver to code in a continuation passing style. Continuations are native in some languages but has been retrofitted into Java code before in well known web frameworks and web servers, such as RIFE and Jetty.

Arguments on the other hand are annotated as @free, @cuttable or @safe. These argument qualifiers are described in an ECOOP 2008 presentation by Sriram Srinivasan and Alan Mycroft:

These qualifiers can be understood in terms of two orthogonal capabilities of an object in a tree: first, whether it is pointed to by another object or not (called a root in the latter case) and second, whether or not it is structurally modifiable (whether its pointer-valued fields are assignable). The latter is a transitive property; an object is structurally modifiable if its parent is.

Given this, an object is free if it is the root of a tree and is structurally modifiable. A cuttable object may or may not be the root, but is structurally modifiable. An object with a safe capability cannot be structurally modified (transitively so), and does not care whether or not it is the root.

The actor model is popping up in more and more contexts, and no matter which language or platform you will program in in the future, the concept is likely to be in important one.

Cool! by Neil Ellis Posted Jun 26, 2008 12:31 PM
Can he switch his project page back to black text on white background ? by Dorel Vaida Posted Jun 27, 2008 1:59 AM
Re: Can he switch his project page back to black text on white background ? by Neil Ellis Posted Jun 27, 2008 5:45 AM
Project Name? by Jeremy Gerrits Posted Jun 27, 2008 9:29 AM
A few clarifications. by sriram srinivasan Posted Jun 27, 2008 12:38 PM
  1. Back to top

    Cool!

    Jun 26, 2008 12:31 PM by Neil Ellis

    Thanks Niclas


    Nice to see a Java only implementation I will definitely be checking this as a possible execution model type in Einstein. What's interesting is the way that he has chosen to annotate the degree of mutability. I think that thinking in gray-scale rather than monochrome is the way forward for general purpose (rather than specialist) scalability techniques. I'm not convinced yet by the absolutism of some languages/frameworks with rigid restrictions, like those in functional programming; I think we have a lot to learn from the results of using these idioms but need to be able to say the degree of, for example, idempotency, mutability, concurrency etc. that we desire or can assure etc. And exploration in this area is very interesting to see.

    Definitely on my one to watch list!


    All the best

    Neil

  2. Cause I'm used to associate that with work you know ? White text on black background is for MUD-ing mind you ?

  3. Man Black is the new White!




    You may have noticed from my project page (the above link to Einstein) I am a little biased in this area :).


    All the best

    Neil

  4. Back to top

    Project Name?

    Jun 27, 2008 9:29 AM by Jeremy Gerrits

    Is this project related to the other Java project that's been around since 2002 that has the same exact name?

    kilim.objectweb.org/

  5. Back to top

    A few clarifications.

    Jun 27, 2008 12:38 PM by sriram srinivasan

    On the term Actor



    One of the big features of Actors, as used by the originators of the term (Carl Hewitt, Gul Agha), is isolation from one another. There is no point doing concurrent programming if you cannot isolate easily.




    In Scala's actor model, isolation is not enforced; it is obtained by convention; the programmer must use immutable messages or be "very careful" while exchanging mutable messages.




    On Continuations



    A continuation is a snapshot of both the data and control planes. In that sense, Jetty doesn't provide continuations (it only restores the control plane, but no support on the data plane; it leaves it to the programmer to figure out which variables to restore, and where to store them before yielding.



    Kilim can be downloaded at kilim.malhar.net. There's an "IFAQ" (Infrequently asked questions) in the download that provides more comparisons.

    --sriram

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.