[Dancer-users] Dancer and EV/thread-based servers

Nick Knutov mail at knutov.com
Wed Jan 25 11:39:22 CET 2012


I'm new to it, and I always worked with preforked scripts (like FastCGI 
or Starman). Now I want to process several requests at the same time 
with one app process (without [pre]forking), with servers like Coro 
(green threads, I think) or Feersum (EV). Is it possible?

And the main question about compatibility, I think, is how to declare 
global variables, which are local to current handled request (because I 
don't know how are they shared inside one process between threads/etc).

For example, I have hashref $data, some functions in my modules (or my 
Dancer' plugins) generates $data->{fields} and it passes to template() 
at the end of route execution. $data now is `our $data` in app.pm. The 
same with DBI connections. Is it ok or should I change it in some way?


25.01.2012 15:57, Pedro Melo пишет:
> Hi,
>
> On Tue, Jan 24, 2012 at 10:27 PM, Nick Knutov<mail at knutov.com>  wrote:
>> the question may be not about Dancer itself, but what should I know to write
>> Dancer' plugins and applications compatible with EV- and threads-based
>> servers?
>
> I regularly use Dancer with EV-based servers (Twiggy using the EV
> backend to AnyEvent and Feersum), I don't have any problems, but maybe
> I'm missing what you mean by "compatible".
>
> If you are asking if the plugins can use the EV capabilities during a
> single request to start several calls to external network services,
> collect responses and generate the result, the answer is yes. See the
> metacpan web app for an example using Catalyst that should be
> applicable to Dancer with little modification.
>
> But if you're are looking for a way to process several requests at the
> same time, for example processing a second request while the first is
> waiting on some network protocol, then the answer is no, at least for
> Dancer v1, don't know Dancer v2 yet. AFAIK, only Tatsumaki will allow
> you to multiplex multiple HTTP requests on the same process.
>
> But between Dancer requests, when the control returns to the EV core,
> you can run other callbacks. So you can, for example, have a XMPP bot
> (using AnyEvent::XMPP2) running in the same process as a Dancer app,
> and interact with it, even to query Dancer internals and/or modify
> configurations. The XMPP processing will occur between Dancer
> requests.
>
> You can also use AnyEvent timers with a Dancer app. Again, they will
> be triggered between requests. Useful to collect stats on a Dancer app
> and send them to a remote server.
>
> I use those last two quite a lot actually.
>
> Bye,

-- 
Best Regards,
Nick Knutov
http://knutov.com
ICQ: 272873706
Voice: +7-904-84-23-130


More information about the Dancer-users mailing list