P
P
pcdesign2020-10-02 18:06:50
Nginx
pcdesign, 2020-10-02 18:06:50

How to deploy Flask-SocketIO with gunicorn and nginx?

For example, an application with a chat:
https://github.com/miguelgrinberg/Flask-SocketIO-Chat

If you follow the official documentation:
gunicorn --worker-class eventlet -w 1 module:app
Everything works fine, but we get only one worker.
If you put -w 4, then everything will break.

According to the documentation, in order to launch several workers, dancing with a tambourine is already starting there - with redis, etc.

Is there an option to just run two gunicorns, on two different ports.
One gunicorn will work with 4 workers and will be responsible for everything except chat on port 8888.
And the second gunicorn will only work with socketio and will work with one worker on port 7777.
In nginx it will look something like this:

location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:8888;
    }


    location /socket.io {
        include proxy_params;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://127.0.0.1:77777/socket.io;
    }
}


Is it worth it to bother? And maybe there are better solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2020-10-03
@pcdesign

As a result of my research, such a summary.
It makes no sense to do so.
--worker-class eventlet hint
https://pypi.org/project/eventlet/
Runs a non-blocking library that can service requests in parallel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question