On Sun, Apr 18, 2010 at 7:45 PM, Andy <
selfor...@gmail.com> wrote:
> A few questions:
>
> - is it a good idea to run a reverse proxy like Nginx in front of
> gevent's WSGI server? The normal reason to have a reverse proxy is to
> reduce concurrency on the app server and to buffer slow client
> connections -- do those reasons still apply to gevent?
Probably not as much as to threading-based or forking server but I
think it will still reduce load
on the application server.
There are other reasons to run your app behind nginx, such as better logging,
better configuration, better security, ability to serve an error
message while app is down,
and not hit python app to serve a static file.
> - In the example
http://bitbucket.org/denis/gevent/src/tip/examples/webchat/run.py
> presumably only 1 python process & 1 python thread are created. In
> that case it wouldn't be able to take advantage of multiple CPU cores.
> What is the recommended way to make gevent wsgi server run on
> multicore CPU? In gevent.wsgi.WSGIServer in base_env both
> 'wsgi.multithread' & 'wsgi.multiprocess' are set to False. If I change
> that to True would that make the wsgi server multiprocess/
> multthreaded?
Just setting those values in the dictionary won't change the server's behavior.
It still will be one process and one thread.
> Or should I just put a load balancer in front of multiple WSGIServer
> processes each running on its own core?
That would work.
> In that case how do I start up multiple WSGIServer processes?
fork() and start a bunch of WSGIServers in the child processes.
You might find gunicorn interesting:
http://gunicorn.org/
It can use gevent and supports forking multiple workers, reloading on
signals, etc.
>
> - When does it make sense to use "spawn=None" when starting a WSGIServer, and when does it not?
If your requests are short-lived and don't use blocking gevent API.
Most of gevent API is blocking.
The nonblocking functions are:
- everything that has 'block' argument can be made non-blocking by
passing block=False
- everything from gevent.core module
- a number of functions that don't need to wait for anything:
- spawn() function
- start() function on Greenlet and various servers
- set() and clear() on Event class
- put_nowait() and get_nowait() on Queue class
This list is not extensive. To check that a function is non-blocking
check if it switches to the Hub in the code.
Or make an experiment: when you call a blocking function from the Hub
greenlet, you'll get an AssertionError
saying "cannot switch from mainloop to mainloop" or something like that.
If unsure, don't bother with spawn=None.