atom feed9 messages in edu.oswego.cs.concurrency-interestRe: [concurrency-interest] Using Atom...
FromSent OnAttachments
Ariel WeisbergFeb 13, 2013 12:41 pm 
Vitaly DavidovichFeb 13, 2013 12:51 pm 
Ariel WeisbergFeb 13, 2013 1:45 pm 
Vitaly DavidovichFeb 13, 2013 2:15 pm 
Aaron GrunthalFeb 13, 2013 7:37 pm 
Chris DennisFeb 14, 2013 8:15 am 
Ariel WeisbergFeb 14, 2013 8:56 am 
Vitaly DavidovichFeb 14, 2013 9:31 am 
Nathan ReynoldsFeb 14, 2013 9:41 am 
Subject:Re: [concurrency-interest] Using Atomic*FieldUpdater to remove indirection
From:Vitaly Davidovich (vita@gmail.com)
Date:Feb 13, 2013 2:15:12 pm
List:edu.oswego.cs.concurrency-interest

I'd be more concerned with heap overhead of using AtomicXXX if it's embedded in lots of objects (or embedded in classes with high allocation rates). For example, AtomicInteger will be 24 bytes for a payload of 4 bytes (nevermind requiring more GC time to mark and sweep these objects if they get tenured). The memory indirection cost may be minimal depending on whether you hit cache or not. Anyway, you can use Unsafe to replicate AtomicXXX to remove overhead.

The second use case sounds OK - you have single writer multiple readers. Your only possible concern there is whether other fields on the same cache line are read independent of message time. In other words, if message time changes more frequently than the other data on the line, you'll get unnecessary coherence hits for reading that other data.

Vitaly

Sent from my phone On Feb 13, 2013 4:45 PM, "Ariel Weisberg" <ari@weisberg.ws> wrote:

** Hi,

I have two use cases in mind.

I have some COW* data structures that use AtomicReference internally for example
COWNavigableSet<https://github.com/VoltDB/voltdb/blob/master/src/frontend/org/voltcore/utils/COWNavigableSet.java#L30>. Using AtomicReference means there is an extra indirection for every lookup.

The other use case is a field that tracks the last time a
message<https://github.com/VoltDB/voltdb/blob/cdc1eb42d6d8708cb5371af5cb1fd747372d8be0/src/frontend/org/voltcore/messaging/ForeignHost.java#L300>was
received from a host. There is a single thread that updates the field every time a message is delivered and multiple threads read the field every time they send a
message<https://github.com/VoltDB/voltdb/blob/cdc1eb42d6d8708cb5371af5cb1fd747372d8be0/src/frontend/org/voltcore/messaging/ForeignHost.java#L213>to
that host.

In the last message time tracking use case there will always be a coherence operation for the cache line containing the value tracking the last message time. I suppose it doesn't really matter if the other fields in that class are on the same line because the number of coherence operations remains the same. If there were a get equivalent of lazySet that would be nice.

Thanks, Ariel

On Wed, Feb 13, 2013, at 03:51 PM, Vitaly Davidovich wrote:

Can you elaborate a bit? Do you mean using AtomicInteger (as an example) instead of an int field inside a class? If so, I'd personally pad out the class with filler fields to avoid false sharing - there's no guarantee that the indirection via AtomicXXX will put memory far apart; padding gives you a bit more control here.

Sent from my phone On Feb 13, 2013 3:44 PM, "Ariel Weisberg" <ari@weisberg.ws> wrote:

Hi,

Does it make sense to use Atomic*FieldUpdater to remove the indirection overhead of an AtomicLong and AtomicReference? Similarly, does it make sense to use Atomic* to create indirection in order to avoid false sharing?