Thread Regulator with notifications and statistics
Project description
ThreadRegulator
Python class that allows to control thread execution in time (requests per second) for both constant rate mode, or burst mode. With a notify option that is called after a specific number of executions or a time delta
from thread_regulator import ThreadRegulator, safe_sleep
def demo_constant_rate():
from random import choice
def my_notifier(arg1, stats_dict):
print(arg1, stats_dict)
def my_thread_call(*args, **kwargs):
safe_sleep(choice((0.1, 0.2, 0.3)))
return True
tr = ThreadRegulator.create_regular(users=4, rps=10.0, duration_sec=1.0, executions=15)
print(tr)
print("="*100)
tr.set_notifier(my_notifier, ("notify_example_arg_1", ), every_sec=1, every_exec=8).\
start(my_thread_call, "arg1", "arg2", arg3="my_name", arg4="my_demo")
print("="*100)
print(tr.get_statistics())
print(tr.get_execution_dataframe().start_ts.diff().describe())
return tr
def demo_burst_mode():
from random import choice
def my_notifier(arg1, stats_dict):
print(arg1, stats_dict)
def my_thread_call(*args, **kwargs):
safe_sleep(choice((0.1, 0.2, 0.3)))
return True
tr = ThreadRegulator.create_burst(users=4, rps=10.0, duration_sec=2.0, req=10, dt_sec=0.5, executions=20)
print(tr)
print("="*100)
tr.set_notifier(my_notifier, ("notify_example_arg_1", ), every_sec=1, every_exec=8). \
start(my_thread_call, "arg1", "arg2", arg3="my_name", arg4="my_demo")
print("="*100)
print(tr.get_statistics())
print(tr.get_execution_dataframe().start_ts.diff().describe())
return tr
if __name__ == "__main__":
print("RegularMode")
demo_constant_rate()
print("\n\nBurstMode")
demo_burst_mode()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for thread_regulator-pjn2work-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cfc012aa8006caa249349985ed20e56634d56032d9aeb60e6f96f7dc81d207d |
|
MD5 | 2dd5f76abe0c14cc8c8c6e25f2967b27 |
|
BLAKE2b-256 | 941187129abe05f080597d63d85b85023fc984542e82a2548827906ae948c047 |
Close
Hashes for thread_regulator_pjn2work-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3da42c2eb6726dde5145ed80e6978216208ab717cd3b09f6f96965c9c07181b3 |
|
MD5 | a535ec19044beb401f2e3a0fd7256874 |
|
BLAKE2b-256 | 1e87fe4fea668ca4fd4df93e074c192ea7341b4f36171393232f025fac64aa21 |