Dancer and EV/thread-based servers
Hello all, 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? -- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
Hi, On Tue, Jan 24, 2012 at 10:27 PM, Nick Knutov <mail@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, -- Pedro Melo @pedromelo http://www.simplicidade.org/ http://about.me/melo xmpp:melo@simplicidade.org mailto:melo@simplicidade.org
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@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
+ How to change (if needed) all initialization in the app.pm, which are not in `before hook`, example: #env perl use ...; # this is calling at startup of the script some_init(); connect_to_my_DBs(); # and later hook before, get, etc get '/' => sub {...}; 25.01.2012 16:39, Nick Knutov пишет:
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@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
Hi, On Wed, Jan 25, 2012 at 10:39 AM, Nick Knutov <mail@knutov.com> wrote:
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?
AFAIK, with Dancer1 no, its not possible. Bye, -- Pedro Melo @pedromelo http://www.simplicidade.org/ http://about.me/melo xmpp:melo@simplicidade.org mailto:melo@simplicidade.org
Greetings, If today one were to start making a "production-mode" site that must work reliably and be available in early May, should one use dancer 1 or 2? Niels L http://genomics.dk
One should still use Dancer 1. Dancer 2 is under heavy development but hasn't matured enough yet to be used in production. It's "bleeding edge" in every sense of the word. :) On Wed, Jan 25, 2012 at 11:05 PM, Niels Larsen <niels@genomics.dk> wrote:
Greetings,
If today one were to start making a "production-mode" site that must work reliably and be available in early May, should one use dancer 1 or 2?
Niels L
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Okay, will do. I may try Openshift, https://www.redhat.com/openshift/community/kb/kb-e1014-how-to-deploy-the-per... and just post this so all know that Redhat thinks Openshift + dancer is possible. Niels On Wed, 2012-01-25 at 23:06 +0200, sawyer x wrote:
One should still use Dancer 1.
Dancer 2 is under heavy development but hasn't matured enough yet to be used in production. It's "bleeding edge" in every sense of the word. :)
On Wed, Jan 25, 2012 at 11:05 PM, Niels Larsen <niels@genomics.dk> wrote: Greetings,
If today one were to start making a "production-mode" site that must work reliably and be available in early May, should one use dancer 1 or 2?
Niels L
Wow, that's pretty cool! Thanks for posting and good luck with it. I think an article/post about your experience with it will be very valuable. On Wed, Jan 25, 2012 at 11:18 PM, Niels Larsen <niels@genomics.dk> wrote:
Okay, will do. I may try Openshift,
https://www.redhat.com/openshift/community/kb/kb-e1014-how-to-deploy-the-per...
and just post this so all know that Redhat thinks Openshift + dancer is possible.
Niels
On Wed, 2012-01-25 at 23:06 +0200, sawyer x wrote:
One should still use Dancer 1.
Dancer 2 is under heavy development but hasn't matured enough yet to be used in production. It's "bleeding edge" in every sense of the word. :)
On Wed, Jan 25, 2012 at 11:05 PM, Niels Larsen <niels@genomics.dk> wrote: Greetings,
If today one were to start making a "production-mode" site that must work reliably and be available in early May, should one use dancer 1 or 2?
Niels L
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Ok, I will write a piece should I succeed. That would give both my little project, Redhat and Dancer good mention. If I fail, I can at least say if there is something about Dancer that does not work well. These "paas" things will likely make many more feel like jumping in, and if Dancer has good modules for common paas setups there should be many new users. Niels On Wed, 2012-01-25 at 23:20 +0200, sawyer x wrote:
Wow, that's pretty cool!
Thanks for posting and good luck with it. I think an article/post about your experience with it will be very valuable.
On Wed, Jan 25, 2012 at 11:18 PM, Niels Larsen <niels@genomics.dk> wrote:
На Wed, 25 Jan 2012 04:27:49 +0600 Nick Knutov <mail@knutov.com> записано:
Hello all,
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?
You just need to understand that EV-bases application is actually a single process, thus all the IO should be event-driven as well, including database requests. If you accidentally block in a route handler for noticeable amount of time your server will simply stop answering other queries. That's why message queues arise -- to offload lasting tasks to a separate process(es). -- С уважением, Роман Галеев, +7 347 2-900-145 www.ncom-ufa.ru
participants (5)
-
Nick Knutov -
Niels Larsen -
Pedro Melo -
sawyer x -
Роман Галеев