Reputation: 445
I have a Django application deployed on Google Cloud Run using a Gunicorn server. There is a daily task triggered by Google Cloud Scheduler. The task job involves patching a Microsoft subscription. For this patch to complete successfully, Microsoft makes a call to another API endpoint on the same Django application to validate a token. The Gunicorn server is running with multiple threads. When the task is triggered and the container has a cold start, the validation request is blocked, the patch request fails and the container only responds to it after the patch failure. However, if the container is warm, the task completes successfully and the additional thread is able to respond to the validation check. Any idea why this is occurring and how it can be addressed? This was working previously but started encountering this error in recent weeks. Have tried setting multiple workers and more threads on the Gunicorn server as well as enabling CPU boost on Cloud Run but neither of these worked.
Upvotes: 0
Views: 344
Reputation: 2045
This is the result of cold starts as no requests have been received for a while by the application. This is to set by default to mitigate costs in exchange for performance. Cloud Run will then "warm up" again after a series of requests have been received.
Here are some of the suggestions that I could recommend to ensure smooth request processing:
Configuring the minimum instance
1
will prevent the CPU from idling, leading to cold starts.You may also refer to this blog on optimizing Cloud Run response times for additional tips that could be helpful for your setup.
Please be advised that these methods will incur costs, and may affect your final billing. You may check first Google Cloud's pricing calculator as this will serve as the estimated prices when using the aforementioned services for Cloud Run.
Upvotes: 1