python - Flask with gevent multicore -


what clear way run flask application gevent backend server , utilize processor cores? have idea run multiple copies of flask application gevent wsgiserver listen 1 port in diapason 5000..5003 (for 4 processes) , nginx load balancer.

but i'm not sure way best , may there other ways it. example, master process listen 1 port , workers process incoming connections.

i'll take shot!

nginx!

server section:

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

flask app

this simple flask app using example.

myapp.py:

from flask import flask app = flask(__name__)  @app.route("/") def hello():     return "hello world!"  if __name__ == "__main__":     app.run() 

uwsgi

okay know said wanted use gevent, if willing compromise on little bit think happy setup.

[uwsgi]     master = true     plugin = python     http-socket = 127.0.0.1:5000     workers = 4     wsgi-file = myapp.py     callable = app 

gunicorn

if must have gevent might little setup

config.py:

import multiprocessing  workers = multiprocessing.cpu_count() bind = "127.0.0.1:5000" worker_class = 'gevent' worker_connections = 30 

then can run:

gunicorn -c config.py myapp:app 

thats right have worker each cpu , 30 connections per worker.

see if works you.

if sold on using nginx load balancer try in http section

upstream backend {     server 127.0.0.1:5000;     server 127.0.0.1:5002;     server 127.0.0.1:5003;     server 127.0.0.1:5004; }  

then 1 of these in server section

location / {     include proxy_params;     proxy_pass http://backend; } 

good luck buddy!


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -