Class TPS
java.lang.Object
org.jpos.util.TPS
- All Implemented Interfaces:
AutoCloseable, Loggeable
TPS can be used to measure Transactions Per Second (or transactions during
other period of time).
It can operate in two different modes:
- Auto update.
- Manual update.
When operating in auto update mode, a shared scheduler is used and the number of transactions (calls to tick()) is automatically calculated for every period. In this mode, callers should invoke stop() (or close()) when the TPS object is no longer needed to cancel its scheduled task. The shared scheduler thread is daemon and reused across instances.
When operating in manual update mode, user has to call one of its floatValue() or intValue() method at regular intervals. The returned value will be the average TPS for the given period since the last call.
- Since:
- 1.6.7 r2912
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longIf set (via setSimulatedNanoTime), getNanoTime() returns this value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddump(PrintStream p, String indent) Dumps a human-readable representation of this object to the print stream.floatReturns the current transactions-per-second value.floatgetAvg()Returns the average TPS across sampled intervals.longReturns elapsed wall-clock time since the current sampling window started.protected longReturns the current monotonic time in nanoseconds.intgetPeak()Returns the highest recorded TPS peak.longReturns the wall-clock time when the peak TPS was recorded.longReturns the configured sampling period.intintValue()Returns the current transactions-per-second value rounded to an integer.voidreset()resets average and peak.voidsetSimulatedNanoTime(long simulatedNanoTime) Overrides the monotonic nano time source for deterministic tests.voidstop()Stops auto-update scheduling and leaves the meter in manual mode.voidtick()Increments the transaction counter for the current sampling window.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Loggeable
dumpModifier and TypeMethodDescriptiondefault voiddump(PrintStream p, String indent, LogRenderer.Type type) Dumps a representation of this object using the specified renderer type.
-
Field Details
-
simulatedNanoTime
If set (via setSimulatedNanoTime), getNanoTime() returns this value. This is intended for deterministic tests.
-
-
Constructor Details
-
TPS
public TPS()Default constructor. -
TPS
Creates a TPS meter with the default one-second period.- Parameters:
autoupdate- true to auto update
-
TPS
Creates a TPS meter with the given sampling period.- Parameters:
period- sampling period in millisecondsautoupdate- true to auto update
-
-
Method Details
-
tick
Increments the transaction counter for the current sampling window. -
floatValue
Returns the current transactions-per-second value.- Returns:
- current TPS as a floating-point value
-
intValue
Returns the current transactions-per-second value rounded to an integer.- Returns:
- current TPS rounded to an integer
-
getAvg
-
getPeak
-
getPeakWhen
Returns the wall-clock time when the peak TPS was recorded.- Returns:
- peak timestamp in epoch milliseconds, or
-1if unavailable
-
reset
resets average and peak. -
getPeriod
-
getElapsed
Returns elapsed wall-clock time since the current sampling window started.- Returns:
- elapsed time in milliseconds
-
toString
-
stop
Stops auto-update scheduling and leaves the meter in manual mode. -
close
- Specified by:
closein interfaceAutoCloseable
-
dump
-
setSimulatedNanoTime
Overrides the monotonic nano time source for deterministic tests.- Parameters:
simulatedNanoTime- simulated monotonic time value in nanoseconds
-
getNanoTime
Returns the current monotonic time in nanoseconds.- Returns:
- monotonic nano time, simulated when configured
-