On Thu, Mar 9, 2017 at 1:04 PM, Roberto De Ioris <[email protected]> wrote:
> > > Hi, > > > > Help me wrap my head around async implementation in uwsgi. I come from > > perl > > world and use psgi, coroae and really enjoy uwsgi. Great thing you wrote. > > > > My problem is that Coro is an overkill for me as my programs mostly > > AnyEvent (AE) based and I don't use coroutines to full power. Also, we > > have > > problems restarting uwsgi as Coro seg faults during perl's global > > destruction in our setup. In recently written service this cause a lot of > > pain as our worker spawns a child and due to seg fault has no chance to > > cleanup the child, what prevents uwsgi to start again. > > > > I wonder if it's possible to get rid of Coro and implement a plugin that > > would allow us to write async psgi applications using AnyEvent. > > > > Spent some time in uwsgi's code and from what I can see uwsgi's async > > implementation is a combination of co-routines and event loop. async > > option > > allocates N "cores" within a worker to handle N requests simultaneously. > > uGreen (co-routines) plugin implements uwsgi's context switches between > > these N "cores" by providing operations to suspend/resume a "core". > uGreen > > also calls suspend/resume hooks in the request handler plugin if > provided, > > in my case it would probably be psgi plugin or my custom. > > > > Open question: > > * can I write such plugin that works without co-routines in perl world? > > * how does event loop fits into uwsgi's async world? > > > > > > Hi, your analysis is correct, the internal core expects some kind of stack > switching features (that basically is what causes your headaches ;) > Was digging more and feels like my situation is quite close to tornado plugin. Tornado provides event loop, leaves context switches to other plugins. From what I see Tornado server provides abstraction on top of kqueue/epoll and tornado plugin switches uwsgi's ioloop onto this implementation. It's kind of strange a bit. AnyEvent is a single API on top of event loops (libev, libuv, pure perl loop, ...). Sure I can use AE's implementation instead of uwsgi's default, but it feels wrong. Instead of replacing uwsgi's ioloop it feels more correct to teach AE to use uwsgi's default ioloop. As technologies like asyncio are becoming a standard, in latest 2.0 > versions the 'worker override feature has been added': > > http://uwsgi-docs.readthedocs.io/en/latest/WorkerOverride.html > Basically you can write your worker core in the native language > (perl+AnyEvent in your case) to support more paradigms. > >From what I can see this way completely replaces worker process, so you just take over everything except a few basic aspects. Example in the doc uses a python web server implementation that handles every aspect of HTTP. The perl plugin currently lacks the .worker hook: > > https://github.com/unbit/uwsgi/blob/master/plugins/ > python/python_plugin.c#L2070 > > but is super easy to add: > > https://github.com/unbit/uwsgi/blob/master/plugins/ > python/python_plugin.c#L2003 > > basically that function runs your perl loop in the worker process address > space, so all the uwsgi api is supported. > > So, you need three steps: > > - implement the .worker hook > - implement the uwsgi.accepting() api func (if you plan to support > chain-reloading) > - implement the perl script that cooperate with AnyEvent > This is one way to go, but I don't like all or nothing way. My plan: * dig more into using as much as possible from what uwsgi itself and psgi plugin has. * investigate ugreen and if I can do suspend/resume in psgi without much pain * if above steps fail then I'm going to work on aepsgi plugin that would use worker hook, but wouldn't force you to take care of HTTP protocol. Usage would look like "--aepsgi xxx.psgi". * --perl-work-override sounds like good option in either case Take in account that i would absolutely merge such a patch in the stable > branch :) > > -- > Roberto De Ioris > http://unbit.com > _______________________________________________ > uWSGI mailing list > [email protected] > http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi > -- Руслан Закиров Руководитель отдела разработки веб-сервисов +7(916) 597-92-69, ruz @ <http://www.sports.ru/>
_______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
