|
NAMEcounters - Counter FunctionsDESCRIPTIONThis module provides a set of functions to do operations towards shared mutable counter variables. The implementation does not utilize any software level locking, which makes it very efficient for concurrent access. The counters are organized into arrays with the following semantics:
DATA TYPEScounters_ref() Identifies a counter array returned from new/2. EXPORTSnew(Size, Opts) -> counters_ref() Types: Size = integer() >= 1
Opts = [Opt] Opt = atomics | write_concurrency Create a new counter array of Size counters. All counters in the array are initially set to zero. Argument Opts is a list of the following possible options:
Read operations may see sequentially inconsistent results with regard to concurrent write operations. Even if write operation A is done sequentially before write operation B, a concurrent reader may see any combination of A and B, including only B. A read operation is only guaranteed to see all writes done sequentially before the read. No writes are ever lost, but will eventually all be seen. The typical use case for write_concurrency is when concurrent calls to add and sub toward the same counters are very frequent, while calls to get and put are much less frequent. The lack of absolute read consistency must also be acceptable. Counters are not tied to the current process and are automatically garbage collected when they are no longer referenced. get(Ref, Ix) -> integer() Types: Ref = counters_ref()
Ix = integer() Read counter value. add(Ref, Ix, Incr) -> ok Types: Ref = counters_ref()
Ix = Incr = integer() Add Incr to counter at index Ix. sub(Ref, Ix, Decr) -> ok Types: Ref = counters_ref()
Ix = Decr = integer() Subtract Decr from counter at index Ix. put(Ref, Ix, Value) -> ok Types: Ref = counters_ref()
Ix = Value = integer() Write Value to counter at index Ix. Note:
Despite its name, the write_concurrency optimization does not improve
put. A call to put is a relatively heavy operation compared to
the very lightweight and scalable add and sub. The cost for a
put with write_concurrency is like a get plus a
put without write_concurrency.
info(Ref) -> Info Types: Ref = counters_ref()
Info = #{size := Size, memory := Memory} Size = Memory = integer() >= 0 Return information about a counter array in a map. The map has the following keys (at least):
Visit the GSP FreeBSD Man Page Interface. |