Hey All,
So I've been working on a detailed Plack + AnyEvent tutorial. It's over on Github (https://github.com/jjn1056/Example-PlackStreamingAndNonblocking)
The intention here is to have something detailed enough that people walking away can actually use it. Evented and nonblocking code is becoming a big deal lately, particularly with some of the new applications we see hitting the web. Right now I am not too bullish on Perl really competing in this area, based on my research and the dearth of docs I am finding.
So, if you are an evented + nonblocking codefu master please look over what I have so far and if you can fork it and send issues or pull requested that help me make it better I would be grateful. Right now I am looking for people that are experts in this to review what I have so far and correct it as needed. I also desparately need a handful of real life, real world examples that are also simple enough for people to understand, yet complicated enough that they can use those examples as inspiration for their own work.
Right now I am find a pretty huge gap betwen trivial examples using AnyEvent timer and something that actually does real work. I'm hoping to make this tutorail strong enough that it can help people who are finding themselves being pressured by some of the really interesting (and easy) things you can do with say something like node.js.
So, if you think Perl can go head to head in this technology space, now is the time to show up to the fight. I'm personallt having a really, really hard time making non trivial examples that actually work, and this is sorta worrying to me :)
Thanks!
Sorry, I don't have time to write significant text, etc., right now, but you mentioned having a hard time coming up with "real-world" reasons for doing this, and I thought of two real-world scenarios where doing the AnyEvent dance with Plack might make sense.
First, if you're mostly just doing code that is a thin shim (marshalling+auth) over a bunch of database calls, and you are using a database layer that has good AnyEvent support---Redis being the only one that comes to mind, though it is possible to do it with PostgreSQL without too much hassle---then you could perhaps get by with a single-process server, which would lower the resource requirements, etc., for serving your application. If you're running on memory-constrained VM images, that could be a nontrivial cost-savings.
A generalization of that would be if you were pushing all processing off on some set of back-end machines, via ZeroMQ or RabbitMQ or Gearman or something---again, you have the light-weight front-end that controls access and frobs data, and then it hands off to other boxes for actual processing.
Both of those notions are somewhat artificial, but not toy usages just to prove a point.
Posted by: Michael Alan Dorman | 02/10/2013 at 08:25 PM
Not sure if it'll help, but you can use this talk as a real life example description. It has all the code at the end. It's using twiggie + Dancer, but you can probably addapt it easily.
http://slideshare.net/dkrotkine/dancing-with-websocket
Posted by: dams | 02/11/2013 at 12:26 PM
I added AnyEvent::HTTPD to my app so that another application could monitor me asynchronously. Just by pinging me on my port, any number of questions could be asked about how my main process is going (it's something that will take 4+ hours to perform, and the monitoring app is written in JS/Java). Makes for a reasonably language-independent "chat" whereby most of the heavy lifting (HTTP requests/responses) are handled by Someone Else's Code.
My main app will be using Coro/AnyEvent to co-ordinate itself already, so slapping this on top should be fairly cheap.
Posted by: Darin | 02/11/2013 at 05:11 PM