A small library to patch FastAPI to remove deadlock issues when using sync database sessions.
Project description
FastAPI Overflow
When using FastAPI with a synchronous SQLAlchemy session dependency, per the official example https://fastapi.tiangolo.com/tutorial/sql-databases/, high loads can lead to temporary deadlocks, timeouts and poor performance.
This is a known issue, for which a PR is open. This library exists to allow users to easily patch the issue and run their code in the mean time.
We provide a single function to patch fastapi: fastapi_overflow.patch() should be called before starting your app in order to patch FastAPI's thread handling.
Usage
Use it like this:
import fastapi_overflow
from fastapi import FastAPI
fastapi_overflow.patch() # run this before starting your app
app = FastAPI()
Changing the default thread limit
You can increase the number of threads from the default (40) using the fastapi_overflow.set_thread_limit function.
With a very high number of threads you might also want to increase the reserve used to prevent deadlocks from its
default of 5. You will need to add this to your startup events, or lifetime function:
@app.on_event("startup")
def on_startup():
fastapi_overflow.set_thread_limit(default_limit=80, reserve_limit=10)
... # any other setup here
Some experimentation is needed to find the best numbers for your workload.
Project details
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 fastapi_overflow-0.1.6.tar.gz.
File metadata
- Download URL: fastapi_overflow-0.1.6.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67f5c1eca33afaf1d7b007343dddc883913d53edfe06901705e5313154638ba3
|
|
| MD5 |
58ea97bf288edde16148a802faf04984
|
|
| BLAKE2b-256 |
9092975fac4d61d527c2fed5ee48224f76099e4092dfef739015de595b032352
|
Provenance
The following attestation bundles were made for fastapi_overflow-0.1.6.tar.gz:
Publisher:
ci.yml on olliemath/fastapi-overflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_overflow-0.1.6.tar.gz -
Subject digest:
67f5c1eca33afaf1d7b007343dddc883913d53edfe06901705e5313154638ba3 - Sigstore transparency entry: 1357200754
- Sigstore integration time:
-
Permalink:
olliemath/fastapi-overflow@cf4b6fc0f0088a44db189e487e9db0e3c2ddb787 -
Branch / Tag:
refs/tags/0.1.6 - Owner: https://github.com/olliemath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@cf4b6fc0f0088a44db189e487e9db0e3c2ddb787 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_overflow-0.1.6-py3-none-any.whl.
File metadata
- Download URL: fastapi_overflow-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e08d98174b67299d68a7ddf0855f57e72b05c8ba7b31138d3dee661d9a7ea8c4
|
|
| MD5 |
ef56a2ba6def325dce072d99ee2d3d6e
|
|
| BLAKE2b-256 |
ae0ceff88edfa13e084e9c52457a71d3b1abe43d941acb467826b603f0207896
|
Provenance
The following attestation bundles were made for fastapi_overflow-0.1.6-py3-none-any.whl:
Publisher:
ci.yml on olliemath/fastapi-overflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_overflow-0.1.6-py3-none-any.whl -
Subject digest:
e08d98174b67299d68a7ddf0855f57e72b05c8ba7b31138d3dee661d9a7ea8c4 - Sigstore transparency entry: 1357200759
- Sigstore integration time:
-
Permalink:
olliemath/fastapi-overflow@cf4b6fc0f0088a44db189e487e9db0e3c2ddb787 -
Branch / Tag:
refs/tags/0.1.6 - Owner: https://github.com/olliemath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@cf4b6fc0f0088a44db189e487e9db0e3c2ddb787 -
Trigger Event:
release
-
Statement type: