docs: improved write-up

added code documentation

clarified language in `README.md`

updated details in `pyproject.toml`
This commit is contained in:
2024-04-18 18:29:32 +01:00
parent c8cfbadfc6
commit 16ceeb7dae
6 changed files with 123 additions and 14 deletions

View File

@@ -1,14 +1,12 @@
# Request Coalescing in Async Python
## About
This repository is a simple experiment revolved around implementing request coalescing in Python using Asyncio and FastAPI, inspired by the Discord Engineering team's blog post on [How Discord Stores Trillions of Messages.](https://discord.com/blog/how-discord-stores-trillions-of-messages)
A simple experiment revolved around implementing request coalescing in Python, using Asyncio and FastAPI, inspired by the Discord Engineering team's blog post on [How Discord Stores Trillions of Messages.](https://discord.com/blog/how-discord-stores-trillions-of-messages)
## How does it work?
When a client makes a request for an item of a specific id, it adds a task to the coalescer queue and waits for the result of that task.
When a client makes a request for an item of a specific id, it will add a task to the coalescer queue and await the result of that task.
Any subsequent requests, recieved in the meantime, for items of the same ID will subscribe to the future result of that first pending task instead of performing their own read query.
Any subsequent requests recieved in the meantime, for items of the same id, will subscribe to the future result of that first pending task instead of performing their own expensive read query.
![Coalescing Diagram](/docs/img-1.png)
@@ -16,7 +14,6 @@ Any subsequent requests, recieved in the meantime, for items of the same ID will
```bash
> poetry run pytest
tests\test_standard.py Making 5x100 concurrent requests (500 total)...
Standard Requests: Took 457.228ms
Standard Metrics: {'requests': 500, 'db_calls': 500}
@@ -26,10 +23,10 @@ Coalesced Requests: Took 49.328ms
Coalesced Metrics: {'requests': 500, 'db_calls': 100}
```
The number of database queries has fallen from 1:1 with requests to 1 database call per 5 requests (lining up with there being 5 requests being made concurrently in the tests).
The number of database queries has fallen from 1:1 with requests to 1 database call per 5 requests (when coalescing and performing 5 requests concurrently).
## License and Contributing
Please feel free to make pull requests containing any suggestions for improvements.
Please feel free to open an issue or a pull request to discuss suggestions for improvements.
This repository is open sourced under the [MIT License.](/LICENSE)
This repository is open source under the [MIT License.](/LICENSE)