Re: Recommendations for Lightweight Threading?

Discussion in 'Java' started by Kevin McMurtrie, Jun 16, 2012.

  1. In article <>,
    "Aaron W. Hsu" <> 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
    Kevin McMurtrie, Jun 16, 2012
    #1
    1. Advertising

  2. 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/
    Robert Klemme, Jun 16, 2012
    #2
    1. Advertising

  3. In article <>,
    Robert Klemme <> 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
    Kevin McMurtrie, Jun 19, 2012
    #3
  4. On Tuesday, June 19, 2012 4:37:00 AM UTC+2, Kevin McMurtrie wrote:
    > In article <>,
    > Robert Klemme <> 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/api/java/util/concurrent/package-summary.html

    java.util.concurrent.atomic.AtomicReferenceArray
    etc.
    http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/package-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
    Robert Klemme, Jun 19, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    1,028
    Mark Space
    Dec 29, 2007
  2. Steven Woody
    Replies:
    0
    Views:
    403
    Steven Woody
    Jan 9, 2009
  3. markspace
    Replies:
    4
    Views:
    429
    Daniel Pitts
    Jun 16, 2012
  4. Lew
    Replies:
    0
    Views:
    335
  5. Eric Sosman
    Replies:
    56
    Views:
    1,110
    Martin Gregorie
    Jun 30, 2012
Loading...

Share This Page