Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run web app with gevent

I want to try playing around with gevent as a web server and application framework. I don't see any way to "restart" the server or update the application code without killing and starting the whole python application again.

Is this just how it's done? Maybe it's just a matter of me understanding a different paradigm to the apache way.

Also, as a semi-related question, is it even a good idea to run a web server AND the site/service itself through gevent. I've seen other implementations using gunicorn for the server and gevent for the application but from the benchmarks I've seen, gevent far outperforms gunicorn as a server when it comes to scaling.

like image 482
Endophage Avatar asked Oct 21 '11 21:10

Endophage


People also ask

How do I run Gunicorn with gevent?

By default, Gunicorn uses a synchronous worker class to serve requests, but it can be easily configured to use gevent by simply adding -k gevent to the run command.

How do you use a gevent flask?

The easiest way to run a Flask application is to use a built-in development server. But even this beast supports two modes of request handling. In the single-threaded mode, a Flask application can handle no more than one HTTP request at a time. I.e. the request handling becomes sequential.

Is gevent a server?

server – TCP/SSL server. If the user initialized the server with an address rather than socket, then this function must create a socket, bind it, and put it into listening mode.

What is gevent Pywsgi?

pywsgi – A pure-Python, gevent-friendly WSGI server. A pure-Python, gevent-friendly WSGI server. The server is provided in WSGIServer , but most of the actual WSGI work is handled by WSGIHandler — a new instance is created for each request.


1 Answers

Gunicorn has 3 gevent workers:

  • -k gevent (using gunicorn's HTTP parser)
  • -k gevent_pywsgi (using gevent.pywsgi module)
  • -k gevent_wsgi (using gevent.wsgi module)

gevent.wsgi is a fast HTTP server based on libevent.

gevent.pywsgi is WSGI server implemented in Python.

The reason for existence of gevent.pywsgi is libevent-http having a few limitations, such as not supporting keep-alive, streaming, ssl and websockets.

Note, that the new alpha version (1.0a3) of gevent uses libev and does not include a WSGI server based on libevent-http. Currently, gevent.wsgi here is an alias for gevent.pywsgi.

The server classes in gevent don't have any features related to process management, restart, reload and so on. Those features are necessary for deployment though. Gunicorn provides that for gevent's WSGI servers. Use it.

like image 93
Denis Avatar answered Sep 27 '22 00:09

Denis