-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving Delayed Response Times for Requests in FastAPI with Cloud SQL #1189
Comments
Hi @tayamaYuto thanks for the question! 😄
Can you share where you are deploying your application? Is it GKE, App Engine, Cloud Run? If it is Cloud Run then it sounds like you are application is having slow "cold starts". From the Cloud Run docs:
The Cloud Run docs have some recommendations for optimizing peformance. As a side-note for the Python Connector in a serverless environment, we recommend setting the Connector to be in "lazy refresh" mode. This may also help reduce the cold start latency. self.connector = Connector(refresh_strategy="LAZY") If you are not deploying with Cloud Run, or continue to see additional request latency I will happily take a deeper look 😄 |
Thank you for your response. Currently, I’m in the verification stage in my local environment and haven’t deployed yet, but I intend to use Cloud Run. I understand that Cloud Run starts instances in response to requests. Since the setup and connection are happening repeatedly in my local development, I thought that the slow connection issues I’m experiencing locally might also occur in the deployed environment, which is why I asked. If, in Cloud Run, the instance startup and request processing are indeed separated, then there’s a chance that the issue I’m concerned about might not occur. After deployment, if I still encounter the issue despite implementing the solution you provided, I’ll reach out again with further questions. |
@tayamaYuto Another suggestion for speeding up your overall application would be to use |
@tayamaYuto any luck speeding up your coldstarts? |
Question
I'm developing with FastAPI and Cloud SQL, and when I try to handle a simple GET request like in my code, it takes about 8 seconds to retrieve information. If I send consecutive GET requests, the response time is faster, but after some time, it again takes around 8 seconds.
Since this response time is slow for an optimal user experience, I’m looking to resolve this issue. I suspect the connection establishment part of my code is not placed optimally, but do you have any ideas or know of any existing Q&A that addresses this?
Code
database.py
dps.py
main.py
The text was updated successfully, but these errors were encountered: