Welcome to the redmx documentation!¶
redmx¶
Basic Rate Error & Duration (RED) metrics.
Have an object to be able to gather performance metrics.
Examples
>>> import time
>>> from redmx import RateErrorDuration
>>> metrics = RateErrorDuration()
>>> time.sleep(1)
>>> metrics.increment_count(1)
>>> metrics.increment_count(1)
>>> metrics.rate()
>>> print(metrics)
Will produce the following output:
rate = 1.9904 tps, errors = 0 in 2 (0.0%), duration = 502.4475 milliseconds per transaction.
- class redmx.RateErrorDuration¶
RateErrorDuration class.
- __str__()¶
Give a usable string representation of the object.
Returns a string similar to this:
rate = 1.9904 tps, errors = 0 in 2 (0.0%), duration = 502.4475 milliseconds per transaction.
- count(count=None)¶
Get or set the count value for the object.
- Parameters
count (int,optional) – The value to set the count to.
- Returns
The count value for the object.
- Return type
int
- duration()¶
Get or set the average duration of a transaction.
- Returns
The average time of a transaction in milliseconds. If there have been no transactions, then return 0.
- Return type
float
- errors(errors=None)¶
Get or set the error count for the object.
- Parameters
errors (int,optional) – The value to set the error count for the object.
- Returns
Get the value of the error count for the object.
- Return type
int
- increment_count(count=1)¶
Increment the count.
- Parameters
count (int,optional) – The value for the count to be incremented by. The default value is 1.
- Returns
The new count of transactions.
- Return type
int
- increment_errors(errors=1)¶
Increment the number of errors in the object.
- Parameters
errors (int,optional) – The value for the count of errors to be incremented by. The default value is 1.
- Returns
The new value of the error count.
- Return type
int
- rate()¶
Calculate the number of transactions per second.
- Returns
The number of transactions per second. If there have been no transactions then this will return 0.
- Return type
float
- throttle_rate(allowed_rate_per_second, calculate_only=False)¶
Throttle (sleep) depending on an allowed transaction rate in comparison to an actual transaction rate.
- Parameters
allowed_rate_per_second (float) – The maximum rate allowed in transactions per second.
calculate_only (bool,optional) – Calculate and return the value, don’t actually sleep if True. Default is False.
- Returns
The time in seconds that we slept for.
- Return type
float