How does jetlang deal with single thread logic in a multi actor environment

219 views
Skip to first unread message

Carl-Gustaf Harroch

unread,
Sep 8, 2011, 6:01:58 AM9/8/11
to jetla...@googlegroups.com
Reading up on Actor pattern on Scala or Killim, there is code weaving in order to ensure several actors get there share of CPU/memory within a single Thread. As such you could have 10 actors, all sending message to each other with replies against a single thread. As far as I understand, this would be impossible without weaving in order to pause and save the stack for later use. How does JetLang compare to this?

Mike Rettig

unread,
Sep 8, 2011, 8:39:22 PM9/8/11
to jetla...@googlegroups.com
Jetlang uses callbacks. To save state, simply pass the values into a
callback (i.e. anonymous class).

There is no magic in jetlang. It is just java. Code weaving tricks
make the problem harder than it needs to be.

Mike

> --
> You received this message because you are subscribed to the Google Groups
> "jetlang-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/jetlang-dev/-/tDHJX_BvNHMJ.
> To post to this group, send email to jetla...@googlegroups.com.
> To unsubscribe from this group, send email to
> jetlang-dev...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jetlang-dev?hl=en.
>

Holger Hoffstätte

unread,
Sep 8, 2011, 6:58:07 AM9/8/11
to jetla...@googlegroups.com

Yes, the term you're looking for is continuation aka coroutine. Java does
not have any (yet), so Scala/Kilim have to add their own stack
saving/switching mechanism. Kilim's is IMHO vastly superior since it adds
actual data safety guarantees. There is a working prototype for "proper"
built-in Java continuations about which you can read here (pdf at the
bottom): http://ssw.jku.at/Research/Papers/Stadler11Master/

> How does JetLang compare to this?

Jetlang does not implement any continuation mechanism, so a
hanging/looping fiber does just that. You will need to run each on a
different thread.

-h

Mike Rettig

unread,
Sep 8, 2011, 10:37:55 PM9/8/11
to jetla...@googlegroups.com
2011/9/8 Holger Hoffstätte <holger.ho...@googlemail.com>:

Jetlang does not require a Thread per Fiber. You can create millions
of fibers if you'd like and use a backing thread pool for running
them. Jetlang guarantees the sequential execution of events for a
given fiber. Since it is java, it still requires discipline from the
developer. In practice, writing completely thread safe code with
Jetlang isn't difficult. Any framework that runs on the JVM
(including Kilim) cannot guarantee data safety since the JVM allows
threads. A developer can always spin up their own thread and access
shared data through a shared instance or a static reference. All
concurrency frameworks on the JVM merely make concurrency easier to
implement and understand, but cannot guarantee data safety.

Carl-Gustaf Harroch

unread,
Sep 9, 2011, 6:59:50 AM9/9/11
to jetla...@googlegroups.com
I am a bit confused with the 2 answers. I understand continuation with Killim/Scala and the upcoming java 7. I am still trying to figure out if you can do request/reply on a single thread.
For instance, can you run Jetlang on a single threaded system (GAE for instance). Even thought you have a Thread pool with millions of Fiber, can the execution be shifted accross Fiber when callback methods are reached?

./C

peter royal

unread,
Sep 9, 2011, 7:46:00 AM9/9/11
to jetla...@googlegroups.com
in jetlang, with request-reply, the requestor does not block awaiting a response, rather a callback is invoked. as long as you never block in a callback things will scale as you expect. 
-pete

-- 
(peter.royal|osi)@pobox.com - http://fotap.org/~osi
--
You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jetlang-dev/-/E9vpi9vrfAgJ.

Holger Hoffstätte

unread,
Sep 9, 2011, 5:25:19 AM9/9/11
to jetla...@googlegroups.com
On 09.09.2011 04:37, Mike Rettig wrote:
> Jetlang does not require a Thread per Fiber. You can create millions

That's true, wonderful, and also very specifically *not* what I wrote,
in the context of which I wrote it.

-h

Mike Rettig

unread,
Sep 12, 2011, 11:37:10 PM9/12/11
to jetla...@googlegroups.com
2011/9/9 Holger Hoffstätte <holger.ho...@googlemail.com>:

"Jetlang does not implement any continuation mechanism, so a


hanging/looping fiber does just that. You will need to run each on a
different thread."

That is the statement I was referring to. To me, the statement implied
a dedicated thread is required for each and every fiber. A jetlang
fiber backed by a thread pool does not loop or hang. When inactive, it
does not consume resources by looping or polling. When an event
arrives that needs to be executed on that fiber, then the fiber is run
by the pool. The fiber is just an ordinary object on the heap.

In practice, pooled threads are rarely needed. Modern OS's are quite
efficient at thread scheduling so tens or hundreds of threads usually
aren't a problem. There are many cases when an app may need to
allocates a large number of fibers or have lots of short lived fibers,
so Jetlang provides the pooled implementation.

Obviously, in the absence of continuations, this is all made possible
by callbacks.

Mike

Reply all
Reply to author
Forward
0 new messages