-- Luc Préfontaine Off.:(514) 993-0320 Fax.:(514) 993-0325 Armageddon was yesterday, today we have a real problem... |
> I've recently done some experimentation with Clojure and Terracotta.
> I've detailed my experience at:
>
> http://paul.stadig.name/2009/02/clojure-terracotta-yeah-baby.html
Very exciting; I'm looking forward to trying this out! Thanks for posting.
-Phil
1. Remove AtomicReferences from Namespace class. If this is possible,
I think a major win for the share everything approach would be to
share clojure.lang.Namespace.namespaces. Once that is done almost all
of the objects will get shared by nature of being included in the
clojure.lang.Namespace.namespaces object graph. Almost all of the
static members of classes are assigned by looking up a var in a
namespace, or by creating Symbols, which are not a problem as far as I
have seen.
2. Static members that are not assigned by looking up a var in a
namespace. I'm not sure how many there are, but one example would be
PersistentHashMap.EMPTY. There is one trick to sharing this.
PersistentHashMap depends upon APersistentMap to generate and assign
it's hashCode value to the _hash member. The first time that hashCode
is called on the PersistentHashMap.EMPTY instance, Terracotta throws
an exception because PersistentHashMap.EMPTY is changed outside of a
lock. This can be fixed by adding
<autolock auto-synchronized="true">
<method-expression>*
clojure.lang.APersistentMap.hashCode(..)</method-expression>
<lock-level>write</lock-level>
</autolock>
to the Terracotta config. This will make Terracotta guard the
APersistentMap.hashCode method. This works, but adding the
synchronized keyword to the APersistentMap.hashCode method (as well as
ASeq, APersistentSet, and APersistentVector) would be a simple change
(assuming there aren't any consequences I'm missing).
I don't see why any of the Persistent data structures would need to be
modified. There may be other issues that will come about after these
changes, but I think it would be a good first step. After that fine
tuning the lock definitions could be done (although one could always
just define a broad lock config). I could look into creating a
Terracotta Integration Module so that people could just say,
"Terracotta, I'm using Clojure," and all of the instrumented classes,
roots, and locks would be configured automagically, then the work
wouldn't have to be duplicated every time.
Paul
AtomicReference is also used in Atom and Agent. Those cases may not be
as straight forward.
Paul
-- Luc Préfontaine Off.:(514) 993-0320 |
Writing a TIM is definitely the way to go, It's a place to hide the glue until both Terracotta and Clojure catches up with each other.