fix(docker): Make Gunicorn Keepalive Adjustable #20348
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
This PR helps to solve 16742
We were getting frequent 502 errors during loading of charts in dashboard forcing us to refresh the page.
This is how traffic flows in our Superset setup: AWS ALB --> Gunicorn --> Superset App
We are using official Superset docker image.
I modified timeout settings i.e. GUNICORN_TIMEOUT and SUPERSET_WEBSERVER_TIMEOUT but it didn't resolve the problem.
I have already increased SERVER_WORKER_AMOUNT to 8 and using default thread value of 20 but it didn't resolve the issue.
My ECS task cpu/memory are underutilized so scaling is not a cause of the problem.
Finally, I saw this blog which says solution is to keep Gunicorn --keep-alive more than alb idle timeout: https://www.tessian.com/blog/how-to-fix-http-502-errors/
Default value for --keep-alive is 2, please see https://docs.gunicorn.org/en/stable/settings.html#keepalive
Even Gunicorn's official documentation here https://docs.gunicorn.org/en/stable/settings.html#keepalive says:
"Generally set in the 1-5 seconds range for servers with direct connection to the client (e.g. when you don’t have separate load balancer). When gunicorn is deployed behind a load balancer, it often makes sense to set this to a higher value."
But run-server.sh in official docker image doesn't has an option for setting Gunicorn's --keep-alive to a custom value.
So I have done improvements in run-server.sh to allow this customization keeping the default value as 2 taken from Gunicorn's default.
I hope this helps people with similar setup as mine.
Note: This change is non-disruptive, no end user will be impacted unless they turn on settings.
You can also refer https://apache-superset.slack.com/archives/C014LS99C1K/p1653678959786229
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
Set GUNICORN_KEEPALIVE to more than alb timeout in your docker containers environment and see issue disappear.
ADDITIONAL INFORMATION