org.multiverse.performancetool
Class CliffCounter

java.lang.Object
  extended by org.multiverse.performancetool.CliffCounter

public class CliffCounter
extends java.lang.Object

Author:
Peter Veentjer

Constructor Summary
CliffCounter()
           
 
Method Summary
 void add(long x)
          Add the given value to current counter value.
 void decrement()
          add(long) with -1
 long estimate_get()
          A cheaper get().
 long get()
          Current value of the counter.
 long increment()
          add(long) with +1
 int internal_size()
          Return the internal counter striping factor.
 int intValue()
          Same as get(), included for completeness.
 long longValue()
          Same as get(), included for completeness.
 void print()
          A more verbose print than toString(), showing internal structure.
 void set(long x)
          Atomically set the sum of the striped counters to specified value.
 java.lang.String toString()
          Return the counter's long value converted to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CliffCounter

public CliffCounter()
Method Detail

add

public void add(long x)
Add the given value to current counter value. Concurrent updates will not be lost, but addAndGet or getAndAdd are not implemented because the total counter value (i.e., get()) is not atomically updated. Updates are striped across an array of counters to avoid cache contention and has been tested with performance scaling linearly up to 768 CPUs.


decrement

public void decrement()
add(long) with -1


increment

public long increment()
add(long) with +1


set

public void set(long x)
Atomically set the sum of the striped counters to specified value. Rather more expensive than a simple store, in order to remain atomic.


get

public long get()
Current value of the counter. Since other threads are updating furiously the value is only approximate, but it includes all counts made by the current thread. Requires a pass over the internally striped counters.


intValue

public int intValue()
Same as get(), included for completeness.


longValue

public long longValue()
Same as get(), included for completeness.


estimate_get

public long estimate_get()
A cheaper get(). Updated only once/millisecond, but as fast as a simple load instruction when not updating.


toString

public java.lang.String toString()
Return the counter's long value converted to a string.

Overrides:
toString in class java.lang.Object

print

public void print()
A more verbose print than toString(), showing internal structure. Useful for debugging.


internal_size

public int internal_size()
Return the internal counter striping factor. Useful for diagnosing performance problems.



Copyright © 2008-2010 Multiverse. All Rights Reserved.