> Hello.
>    I wonder - how async mode is implemented in uWSGI
> it uses separate python interpreter for each async thread?
> or is it withing one python interpreter?


hi, multiple interpreters are used only to host multiple apps in the same
process. In async mode each process can accept (and manage) multiple
requests concurrently interrupting them (with yield or with some form of
co-routine). Hosting multiple apps in async mode is possibile but you have
to disable multiple interpreters (-i option)


>
> if my app use module level variables with async mode will it be messed
> by context switch?

all of the object in the process/interpreter are shared by all requests.
Each request set the uwsgi.core variable to allows you to store
request-specific object storing them somewhere and referring to them with
this value

For example:

my_request_vars[env['uwsgi.core']] = 'foo'

>
> How cheap is context switch using "yield '' " ?


pratically nothing relevant

> what if started with  --async=20 .. and currenly thereis only 1
> request from user
> and i am doing context switch with yield '' - what will be a overhead
> of doing so?


if you want something really accurrate, sadly there are no many way to
measure it, but if you call yield and there are no other requests it will
simply iterate the response.

>
> Is it a bad idea to do context switch in a IO loop of application ?
>

i am sure yielding/suspending waiting for I/O is the best choice.
Yielding/suspending for only splitting response is not so good as one may
think.

Remember that writing async apps with only python generators (read: yield)
is not an easy task. Most of the time you would want to add a co-routine
subsystem (like uGreen, greenlet or stackless python, all easy swappable
via uwsgi.suspend() call) or more high-level platform like gevent or
eventlet (eventlet uwsgi-plugin is still under-development).

the uWSGI async api is obviously faster, but it is very low-level, for
tiny apps it should be very good, otherwise i suggest you to implement an
abstraction on top of it or use the uwsgi-gevent plugin (it supports
pratically all of the uWSGI features except for multithreading)

-- 
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to