[concurrency-interest] High performance clock/counter

Tim Eck teck at terracottatech.com
Tue Apr 27 09:33:04 EDT 2010


Hi Peter -- Do you need a global counter, or are you really seeking some
sort of ever increasing unique ID generator? Depending on the exact
properties required, you can make certain tradeoffs. In particular if you
just need ID generation and can live with gap and order comparison only
within a given thread you can use the shared global counter to allocate a
range to a thread local (this is much like TLAB in the VM). 

> -----Original Message-----
> Date: Sat, 24 Apr 2010 00:10:56 +0200
> From: Peter Veentjer <alarmnummer at gmail.com>
> Subject: [concurrency-interest] High performance clock/counter
> To: concurrency-interest at cs.oswego.edu
> Message-ID:
> 	<q2h1466c1d61004231510z31978fcchdfa0e247b665f3e at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> High All,
> 
> I'm looking for a high performance counter to be used inside an STM.
> 
> Atm I use an AtomicLong, but if the number threads increase, the
> performance drops, example:
> 
> Thread count: 1
> Update transactions/second: 74,149,986.633
> Update transactions/second: 74,149,986.633 per core
> 
> Thread count: 2
> Update transactions/second: 22,864,414.996
> Update transactions/second: 11,432,207.498 per core
> 
> Thread count: 4
> Update transactions/second: 21,958,871.971
> Update transactions/second: 5,489,717.993 per core
> 
> Thread count: 8
> Update transactions/second: 25,207,393.631
> Update transactions/second: 3,150,924.204 per core
> 
> I have a machine with 8 cores.
> 
> I already use a 'relaxed' increment, it is allowed that concurrent
> increments on the clock,
> return the same value. So I'm using the following:
> 
> long writeVersion;
> if (strict) {
>     writeVersion = clock.incrementAndGet();
> } else {
>     long value = clock.get();
>     writeVersion = value+1;
>     clock.compareAndSet(value, writeVersion);
> }
> 
> The performance numbers above are creating using the strict = false.
> 
> I was also playing with the Counter of the high scale lib from Cliff
> Click,
> and the increment is amazingly fast (it gets faster the more cores I
> throw at it). But
> the big problem is that the increment doesn't return a value, and I
> need this
> to determine the writeversion of the transaction. If I do a
> counter.get after the
> increment, the performance drops far under the AtomicLong with the
> relaxed increment.
> 
> So does someone know about a library/approach to solve this situation?
> 
> 



More information about the Concurrency-interest mailing list