Sync endpoints dont finish requests before accepting a next one in high load #11887
Replies: 2 comments 2 replies
-
|
Ill just mention that async endpoint of the same test works flawlessly, also sync endpoint with query that is very fast and pool_size is set to 10 000 instead of 100 also works well. The problems are only with sync endpoint and at least a little bit blocking IO operation. Feel free to ask if any futher explanation or simplification is needed... |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@tiangolo can we make an issue out of this one? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I have two VMs
and
first is hosting fastapi's above code run by (install necessary requirements in the venv):
PYTHONPATH=$PYTHONPATH:~/pack:~/pack/web2py ~/venv/pack/bin/gunicorn --config /home/vagrant/pack/iadmin_fastapi/modules/resources/test_sync.conf.py --timeout 120 -b 127.0.0.1:8001sync.conf.py:
Now the other VM is hosting a postgresql with one table subject with column id and name. It cant be quick query, so that the db was blocking a little big. In my case 1000 000 of records without index made it take 200 ms each search by id.
You also have to set postgresql.conf max_connections to 10 000 and restart, so that its not blocking the test.
Now in my local server thats hosting these 2 VMs, I run this script
This makes 1000 requests at a time.
The problem is my observation:
Expected behaviour:
Operating System
Linux
Operating System Details
Centos7 (see VMs above)
FastAPI Version
0.111.0
Pydantic Version
2.7.1
Python Version
3.8.19
Additional Context
As you can see in fastapi code I am using with statement for connections in the endpoint. At first I was using dependency:
However it wouldnt close my connections ever and the whole code would not process not a single request and the client would time out eventually.
This I feel is connected. However I then read somewhere that the sync dependency exit part is evaluated in separate thread and that would make sense then why it doesnt work. But what would I think is that once I dont use dependency, the thread would finish without a problem and wont hold.
Beta Was this translation helpful? Give feedback.
All reactions