Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Recommendations for Lightweight Threading?

Reply
Thread Tools

Re: Recommendations for Lightweight Threading?

 
 
Kevin McMurtrie
Guest
Posts: n/a
 
      06-16-2012
In article <(E-Mail Removed)>,
"Aaron W. Hsu" <(E-Mail Removed)> wrote:

> I am considering moving one of my projects from C to Java, but I am
> hoping to find a high-performance threading implementation, or something
> along the lines of libqthread, which offers Fill-Empty bit blocking and
> good cooperative lightweight threading as a library.
>
> Is there a current "best" solution when doing many threaded programs in
> Java? By many threads I mean many more than the cores or machines on the
> network. Something that scales up efficiently to distributed computing
> would be nice as well.


It's possible to roll your own concurrency classes using compare-and-set
or safe races. Custom code with reduced functionality can beat the
general JVM classes by a lot.

Minimizing thread interaction in high-performance code helps even more.
Writing to shared memory results in a hardware stall to sync CPU caches.
The bigger the system, the worse those cache syncs are.
--
I will not see posts from Google because I must filter them as spam
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      06-16-2012
On 16.06.2012 07:27, Kevin McMurtrie wrote:

> It's possible to roll your own concurrency classes using compare-and-set
> or safe races. Custom code with reduced functionality can beat the
> general JVM classes by a lot.


That sounds interesting: please share concrete examples where you were
able to beat std lib "by a lot".

> Minimizing thread interaction in high-performance code helps even more.
> Writing to shared memory results in a hardware stall to sync CPU caches.
> The bigger the system, the worse those cache syncs are.


Well, that's one of the basic principles Doug Lea calls "thread
confinement". Not sharing is always more efficient than sharing when it
comes to multiple threads.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Kevin McMurtrie
Guest
Posts: n/a
 
      06-19-2012
In article <(E-Mail Removed)>,
Robert Klemme <(E-Mail Removed)> wrote:

> On 16.06.2012 07:27, Kevin McMurtrie wrote:
>
> > It's possible to roll your own concurrency classes using compare-and-set
> > or safe races. Custom code with reduced functionality can beat the
> > general JVM classes by a lot.

>
> That sounds interesting: please share concrete examples where you were
> able to beat std lib "by a lot".


Many of the utility classes in the concurrency package use locking
because it's required for implementing general List, Map, and the
blocking APIs. If you needed only a small subset of features, you could
eliminate the locks. Eliminating the locks would reduce overhead and,
in many cases, improve the JIT compiler optimizations.

The classic example is data that has an incredibly high read to write
ratio. That makes it possible to use copy-on-write rather than locking.

You can also eliminate locks for blocking methods when there is one
thread that may block. The blocking thread calls LockSupport.park() and
the unblocking thread calls LockSupport.unpark(). This comes in handy
for one worker thread performing many very small tasks. The Java
classes don't have this drastic limitation of a single thread so they
need locking. (This can work for multiple threads but the complexity
and overhead may get out of control.)

>
> > Minimizing thread interaction in high-performance code helps even more.
> > Writing to shared memory results in a hardware stall to sync CPU caches.
> > The bigger the system, the worse those cache syncs are.

>
> Well, that's one of the basic principles Doug Lea calls "thread
> confinement". Not sharing is always more efficient than sharing when it
> comes to multiple threads.
>
> Kind regards
>
> robert

--
I will not see posts from Google because I must filter them as spam
 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      06-19-2012
On Tuesday, June 19, 2012 4:37:00 AM UTC+2, Kevin McMurtrie wrote:
> In article <(E-Mail Removed)>,
> Robert Klemme <(E-Mail Removed)> wrote:
>
> > On 16.06.2012 07:27, Kevin McMurtrie wrote:
> >
> > > It's possible to roll your own concurrency classes using compare-and-set
> > > or safe races. Custom code with reduced functionality can beat the
> > > general JVM classes by a lot.

> >
> > That sounds interesting: please share concrete examples where you were
> > able to beat std lib "by a lot".

>
> Many of the utility classes in the concurrency package use locking
> because it's required for implementing general List, Map, and the
> blocking APIs. If you needed only a small subset of features, you could
> eliminate the locks. Eliminating the locks would reduce overhead and,
> in many cases, improve the JIT compiler optimizations.
>
> The classic example is data that has an incredibly high read to write
> ratio. That makes it possible to use copy-on-write rather than locking.


In which cases did these classes not work or not work well for you?
java.util.concurrent.CopyOnWriteArrayList
java.util.concurrent.CopyOnWriteArraySet
etc.
http://docs.oracle.com/javase/6/docs...e-summary.html

java.util.concurrent.atomic.AtomicReferenceArray
etc.
http://docs.oracle.com/javase/6/docs...e-summary.html

> You can also eliminate locks for blocking methods when there is one
> thread that may block. The blocking thread calls LockSupport.park() and
> the unblocking thread calls LockSupport.unpark(). This comes in handy
> for one worker thread performing many very small tasks. The Java
> classes don't have this drastic limitation of a single thread so they
> need locking. (This can work for multiple threads but the complexity
> and overhead may get out of control.)


I see. Thank you!

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Recommendations for Lightweight Threading? Eric Sosman Java 56 06-29-2012 11:04 PM
Re: Recommendations for Lightweight Threading? markspace Java 4 06-16-2012 07:13 PM
Re: Recommendations for Lightweight Threading? Lew Java 0 06-15-2012 10:57 PM
When I spawn a lightweight process in ASP.NET Does it time out?? MS News ASP .Net 2 07-31-2003 11:53 PM
lightweight XSLT-based page flow: anyone thought of this? SUPER KOOL 223 Java 0 07-29-2003 08:01 PM



Advertisments