multithreaded multimethod hotspots

93 views
Skip to first unread message

Kevin Downey

unread,
May 6, 2012, 1:34:09 PM5/6/12
to Clojure Dev
I've discovered that just calling a multimethod ends up locking (on
that multimethod, there is a synchronized method used) which means if
you have hotspot multimethod in a concurrent or parallel process, it
will effectively kill your parallelism.

This really hurts. Does anyone know if there is already an open jira
ticket for getting rid of the lock on non-mutating calls? I think it
might be simple to fix by changing calling a multimethod to only lock
if the call mutates.

--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

David Santiago

unread,
May 7, 2012, 4:03:14 AM5/7/12
to cloju...@googlegroups.com
I didn't know that about multimethods, it'd be great if that could be
improved. Are you sure MultiFn/getMethod can be modified that way? It
looks like it reads both cachedHierarchy and methodCache, and possibly
methodTable, all of which are always protected to be read and written
together in the rest of the file. On first look, it seems like they
could be read in an inconsistent state if that function is not
synchronized. Or is there a reason I'm not seeing that that would be
OK?

Would it be better to take methodTable, preferTable, methodCache, and
cachedHierarchy, put them all in a record, and stick that in an atom
in the MultiFn?

David
> --
> You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
> To post to this group, send email to cloju...@googlegroups.com.
> To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.
>

Kevin Downey

unread,
May 7, 2012, 12:30:34 PM5/7/12
to cloju...@googlegroups.com
On Mon, May 7, 2012 at 1:03 AM, David Santiago <david.s...@gmail.com> wrote:
> I didn't know that about multimethods, it'd be great if that could be
> improved. Are you sure MultiFn/getMethod can be modified that way? It
> looks like it reads both cachedHierarchy and methodCache, and possibly
> methodTable, all of which are always protected to be read and written
> together in the rest of the file. On first look, it seems like they
> could be read in an inconsistent state if that function is not
> synchronized. Or is there a reason I'm not seeing that that would be
> OK?
>
> Would it be better to take methodTable, preferTable, methodCache, and
> cachedHierarchy, put them all in a record, and stick that in an atom
> in the MultiFn?

sure, I am just trying to figure out if this is a known issue, or it
needs a jira ticket.
Screen Shot 2012-05-06 at 10.44.46 AM.png

Kevin Downey

unread,
May 8, 2012, 12:30:33 PM5/8/12
to cloju...@googlegroups.com

Stuart Halloway

unread,
Jun 8, 2012, 1:13:40 PM6/8/12
to cloju...@googlegroups.com
Added my comments to http://dev.clojure.org/jira/browse/CLJ-988. Would welcome more eyes, and some tests.

Stu


Stuart Halloway
Clojure/core
http://clojure.com

Reply all
Reply to author
Forward
0 new messages