No project description provided
Project description
Monitored IO Loop
A production ready monitored IO loop for Python.
No more wondering why your event loop (or random pieces of your code) are suddenly popping up as slow in your monitoring.
Getting started
Installation
pip install monitored_ioloop # For the default event loop
pip install monitored_ioloop[uvloop] # For the the additional support of the uvloop event loop
Demo
:pencil2: Play with the demo in sandbox
Usage
Asyncio event loop
from monitored_ioloop.monitored_asyncio import MonitoredAsyncIOEventLoopPolicy
from monitored_ioloop.monitoring import IoLoopMonitorState
import asyncio
import time
def monitor_callback(ioloop_state: IoLoopMonitorState) -> None:
print(ioloop_state)
async def test_coroutine() -> None:
time.sleep(2)
def main():
asyncio.set_event_loop_policy(MonitoredAsyncIOEventLoopPolicy(monitor_callback))
asyncio.run(test_coroutine())
Uvloop event loop
In order to use the uvloop event loop, please make sure to install monitored_ioloop[uvloop]
.
The usage is the same as the asyncio event loop, but with monitored_ioloop.monitored_uvloop.MonitoredUvloopEventLoopPolicy
instead of the monitored_ioloop.monitored_asyncio.MonitoredAsyncIOEventLoopPolicy
.
The monitor callback
The monitor callback will be called for every execution that the event loop initiates.
With every call you will receive an IoLoopMonitorState object that contains the following information:
wall_loop_duration
: The time it took to execute the current step of the event loop in wall time.cpu_loop_duration
: The time it took to execute the current step of the event loop in CPU time.handles_count
: The amount of handles (think about them as tasks) that the IO loop is currently handling.
Performance impact
As many of you might be concerned about the performance impact of this library, I have run some benchmarks to measure the performance impact of this library.
You can find the results in the following README folder.
Roadmap
- Add support for the amount of
Handle
's on the event loop - Add visibility into which
Handle
are making the event loop slower - Add easier integration with popular monitoring tools like Prometheus
- Add easier integration with
uvicorn
- Add an examples folder
Credits
I took a lot of inspiration from the uvloop project with everythin regarding the user interface of swapping the IO loop.
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
Hashes for monitored_ioloop-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e0a12d8a132a99211191d4394c49661c1e7ef233c28df9d5b141cee9dd1b79c |
|
MD5 | aaa3642a7f2d1e213baab56916f8ff37 |
|
BLAKE2b-256 | 7e3f453e622c2542772f92261d61e270b70df6ead3b66348602dbccd9598f838 |