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
📺 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:
callback_wall_time: Wall executing time of the callback.loop_handles_count: The amount of handles (think about them as tasks) that the IO loop is currently handling.loop_lag: The amount of time it took from the moment the task was added to the loop until it was executed.callback_pretty_name: The pretty name of the callback that was executed
Please Note: This is a best effort, the name of the callback may still be of little help, depending on the specific callback implementation.
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.
In summary the performance impact is negligible for most use cases.
You can find the more detailed information in the following README.md.
Usage examples
You can find examples projects showing potential use cases in the examples folder.
Currently there is only the fastapi with prometheus exporter example but more will be added in the future.
Roadmap
- Add support for the amount of
Handle's on the event loop - Add an examples folder
- Add loop lag metric (Inspired from nodejs loop monitoring)
- Add visibility into which
Handleare making the event loop slower - Add easier integration with
uvicorn - Add easier integration with popular monitoring tools like Prometheus
Credits
- I took a lot of inspiration from the uvloop project with everything regarding the user interface of swapping the IO loop.
- The great pycon talk - https://www.youtube.com/watch?v=GSiZkP7cI80&t=16s
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file monitored_ioloop-0.0.13.tar.gz.
File metadata
- Download URL: monitored_ioloop-0.0.13.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d5f894013ed979c8efe6b414cc9faf5d566527caf5ab56e8fd8edc4529db3ef
|
|
| MD5 |
68341f363d0211c8ab473dc6e76dc2f2
|
|
| BLAKE2b-256 |
39ce0e79c2fb931f2eab0fa29a65d9775f749160ce49b5cdb87f835b417a662b
|
Provenance
The following attestation bundles were made for monitored_ioloop-0.0.13.tar.gz:
Publisher:
deployment.yaml on gnir-work/monitored-ioloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
monitored_ioloop-0.0.13.tar.gz -
Subject digest:
9d5f894013ed979c8efe6b414cc9faf5d566527caf5ab56e8fd8edc4529db3ef - Sigstore transparency entry: 165889167
- Sigstore integration time:
-
Permalink:
gnir-work/monitored-ioloop@797f3a69c2c3474eb6e6ddf3fc438314a5b0b7f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gnir-work
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deployment.yaml@797f3a69c2c3474eb6e6ddf3fc438314a5b0b7f6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file monitored_ioloop-0.0.13-py3-none-any.whl.
File metadata
- Download URL: monitored_ioloop-0.0.13-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2db3c27e05c8a6ef9a73e0369505f16d224d77a0cfcc44dfee2206b914216e29
|
|
| MD5 |
6633f3dcf788066dfb65f8cafafd8ba8
|
|
| BLAKE2b-256 |
1dd863b31302da8718bf4288c00387d9a23e2732b5f125b8f68e9c32d918e0f3
|
Provenance
The following attestation bundles were made for monitored_ioloop-0.0.13-py3-none-any.whl:
Publisher:
deployment.yaml on gnir-work/monitored-ioloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
monitored_ioloop-0.0.13-py3-none-any.whl -
Subject digest:
2db3c27e05c8a6ef9a73e0369505f16d224d77a0cfcc44dfee2206b914216e29 - Sigstore transparency entry: 165889169
- Sigstore integration time:
-
Permalink:
gnir-work/monitored-ioloop@797f3a69c2c3474eb6e6ddf3fc438314a5b0b7f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gnir-work
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deployment.yaml@797f3a69c2c3474eb6e6ddf3fc438314a5b0b7f6 -
Trigger Event:
push
-
Statement type: