> 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 ;)

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.

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

Take in account that i would absolutely merge such a patch in the stable
branch :)

-- 
Roberto De Ioris
http://unbit.com
_______________________________________________
uWSGI mailing list
uWSGI@lists.unbit.it
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to