

Clojure Agents - jmtulloss
http://justin.harmonize.fm/index.php/2009/03/clojure-agents/

======
davidw
I was thinking that it would be a really cool hack to twiddle an open source
Java vm to give it a scheduler like Erlang's, in order to not rely on threads.
It would not be a simple hack, but you could potentially do some very cool
things with it. Erlang style "processes" are much cheaper than threads.

~~~
pmjordan
In the early days of Java, threads were actually lightweight threads that were
scheduled in user space. They changed them to true OS threads somewhere along
the way, which helps in multiprocessor situations, but I'd love to still have
the green threads around as a tool.

I don't know enough about the JVM to have any idea how tricky it would be to
hack it in; I suspect calling out into a C library that calls setcontext() is
going to make the JVM rather unhappy.

~~~
davidw
Calling out into C or other potentially blocking calls is one of the things
Erlang treats very carefully - the scheduler by itself isn't enough. To really
make Erlang turn over nicely, you have to isolate contact with external
libraries, usually in other Erlang nodes (real, OS level processes). Kind of
strange, but very robust.

~~~
pmjordan
It makes sense, really; C code can really mess with managed systems like that,
and by the sounds of it, Erlang deals with it gracefully. Unfortunately, the
JVM feels a little too monolithic for my liking with regard to processes; it's
more unixy than .NET, certainly, and I guess that's the price you pay for a VM
that sophisticated.

~~~
jmtulloss
I wonder if it would be more practical in .NET. They have this idea of
Application Domains that I've never needed to fully understand, so never have.
Perhaps you could hack that into a Erlang style process model?

~~~
davidw
The key point is really this: if you call out to some C function,
FoobarFunc(), you simply have no guarantees that it won't sit there in a
while(1) { fiddlefaddle() } loop. Since Erlang "processes" are all part of the
same OS process, that would kill the whole system dead. So you really need to
offload things into their own contained little world, which in this case means
a real, Unix process, or at the very least a thread.

------
st3fan
'''Flockr is slow. I would profile it, but profiling in Java is a pain''' -
weird ... that is not my experience. I've had nothing but excellent results
with profilers on Java code. On the microsecond level.

~~~
st3fan
Oh ... nevermind ... I was just reading his 'First stab at Clojure' post on
the same blog where he writes:

"First of all, I’ve never programmed in any lisp dialect. Second of all, I’ve
never programmed in Java."

Yeah. I guess profiling is a pain if you have never actually worked with Java
before. Duh.

~~~
jmtulloss
The problem is there doesn't seem to be an accepted, open source profiler I
can just drop in and start seeing some results. There probably is, but I
haven't come up with a good way of finding these tools for Java.

Being a Python guy, it's often quite frustrating to have to fight so much to
find tools, and then fight so much to get them to work in the environment.

~~~
st3fan
Eclipse and Netbeans come with pretty good profilers. You can also get one of
the commercial ones.

I really like your Clojure blog entries btw. I am very excited to start doing
similar stuff.

------
Tichy
What is Flockr?

~~~
jmtulloss
It's a silly little twitter portal I'm building for the express purpose of
learning clojure. Basically, it aggregates different twitter searches into
"channels".

There's an intro here: [http://justin.harmonize.fm/index.php/2009/03/first-
stab-at-l...](http://justin.harmonize.fm/index.php/2009/03/first-stab-at-
learning-clojure/)

This article is the sixth in the series, which you can see here:
<http://justin.harmonize.fm/index.php/tag/learning-clojure/>

