unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 691 forks source link

Still blocking when using gevent #1943

Open fr0der1c opened 5 years ago

fr0der1c commented 5 years ago

I've been using uwsgi as web server of my Flask application. Recently I want to use gevent to optimize concurrency. But unluckily I found uWSGI is still blocking when using gevent.

Here are my configurations: server.py:

from gevent import monkey; monkey.patch_all()
import gevent.pywsgi

from everyclass.server import create_app
app = create_app()

if __name__ == '__main__':
    gevent_server = gevent.pywsgi.WSGIServer(('', 5000), app)
    gevent_server.serve_forever()

uwsgi.ini:

[uwsgi]
wsgi-file = server.py
callable = app

master = true
processes = 1
gevent = 100
thunder-lock = true

lazy-apps = false
listen = 4096
stats = /tmp/uwsgi-stats.sock
memory-report = true
enable-threads = true
touch-reload = /var/everyclass-server/reload
auto-procname = true
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true

To test if the server is blocking, I wrote a view function:

@main_blueprint.route('/sleep')
def sleep():
    time.sleep(60)
    return render_template('index.html')

When runing server.py directly, which uses gevent.pywsgi.WSGIServer, it just works fine. But If I'm using uWSGI to serve, after accessing /sleep, I cannot visit any other pages.

fr0der1c commented 5 years ago

I found the problem. I use a modular build and I thought the gevent plugin is already included in the python plugin. In fact gevent plugin is a separated plugin. Using pip install uwsgi solved the problem.

However, requests are still occasionally not being responded. And I don't know why.