uWSGI-Flask对同一用户使用同一个worker。

问题描述 投票:0回答:1

我有一个简单的应用程序,通过socket提供数据,我需要为一些用户贴上一些worker。这和nginx的配置很相似,称之为sticky headers。但是nginx不知道我有多少个worker,uWSGI知道并且可以为用户提供特定的worker。但我不知道怎么做。我所需要的就是这个,因为在多工位的情况下,我有一个竞赛条件的问题。

这是我的配置

[uwsgi]
module = wsgi

socket = backend.sock
processes = 16
master = true
enable-threads = true
single-interpreter = true
vacuum = true
die-on-term = true
thunder-lock = true

http-websockets = true
http-socket = :1234
chmod-socket = 660
gevent = 1024
gevent-early-monkey-patch = 1

当我设置进程 1 所有的工作都是完美的,因为用户由同一个工作者服务。

python flask socket.io uwsgi
1个回答
0
投票
processes = 4
socket = $(PWD)/run/socket_http
socket = $(PWD)/run/socket_ws
map-socket = 0:1,2,3
map-socket = 1:4

这将为web套接字分配1个worker(第4个),在nginx中你终于可以做这样的事情了。

location /socket.io/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        include uwsgi_params;
        uwsgi_pass unix:/path/to/project/run/socket_ws;
    }

https:/github.commiguelgrinbergFlask-SocketIOissues1195#issuecomment-619586400。

© www.soinside.com 2019 - 2024. All rights reserved.