Phuks-co / throat

Open Source link aggregator and discussion platform powering Phuks
https://phuks.co
MIT License
73 stars 32 forks source link

Support gunicorn sync workers and deployment using docker #362

Closed happy-river closed 3 years ago

happy-river commented 3 years ago

response_times

We recently switched from running gunicorn with gevent and geventwebsocket workers, to running gunicorn with sync and geventwebsocket workers. The sync workers handle all routes which do not launch asynchronous tasks or make external network requests and the geventwebsocket worker handles those plus /socket.io/. This has improved our stability and backend response times.

Modify the Dockerfile to support launching gunicorn in production configurations with different worker types, using a shell script controlled by environment variables. The shell script also supports a configs directory containing alternative configurations, selected by an environment variable.

Add psycogreen to the dependencies to make psycopg2 green thread safe.

Since dividing the routes between sync and geventwebsocket workers is no longer as trivial as dividing between /socket.io/ and everything else, add a new decorator to mark routes as required to be run by greenlets, a command to list all routes including whether they are marked as requiring greenlets, and some enforcement at runtime.

Update the documentation on deployment to include deploying with docker, and share some things we've learned about configuring gunicorn and database connections.

In other minor changes, remove some no longer used dependencies from the Dockerfile, and have it include in the image all directories ending in migrations, to support forks with multiple migration directories.