Skip Menu |

This queue is for tickets about the Memcached-Client CPAN distribution.

Report information
The Basics
Id: 74253
Status: open
Priority: 0/
Queue: Memcached-Client

People
Owner: Nobody in particular
Requestors: TJC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.01
Fixed in: (no value)



Subject: Sync calls should detect if operating under AnyEvent
Problem: You write a bunch of code using Memcached::Client, using the synchronous API, and package it up into a module. Then someone else takes your module and uses it in *their* code.. and then they try to run it under something like Twiggy, the default webserver used by Plack.. which happens to use AnyEvent. Suddenly all the memcached calls fail in your module. Wishlist: The synchronous calls to memcached should check if AnyEvent/EV is loaded, and if so, switch to making asynchron-ish calls internally.
From: mdorman [...] ironicdesign.com
Show quoted text
> Then someone else takes your module and uses it in *their* code.. and > then they try to run it under something like Twiggy, the default > webserver used by Plack.. which happens to use AnyEvent. > > Suddenly all the memcached calls fail in your module. > > Wishlist: The synchronous calls to memcached should check if
AnyEvent/EV Show quoted text
> is loaded, and if so, switch to making asynchron-ish calls internally.
Hrm. Well you can't just look for AnyEvent/EV, because that's going to be loaded regardless---the module doesn't function at all without AnyEvent. ;) The bigger issue is that the module can't just switch behind your back-- -if you haven't written the code with callbacks, in an asynchronous mode the module would have no way to return the data you requested to your code.
I know it can't use the callback style of API calls, but couldn't it use the method whereby it waits on its own CondVar to complete, then returns the value of that? Essentially, doing this, but internally: my $cv = AnyEvent->cv; $client->get ($key, $cv); my $value = $cv->recv;
From: mdorman [...] ironicdesign.com
On Sun Jan 22 21:05:57 2012, TJC wrote: Show quoted text
> I know it can't use the callback style of API calls, but couldn't it
use Show quoted text
> the method whereby it waits on its own CondVar to complete, then
returns Show quoted text
> the value of that? > > Essentially, doing this, but internally: > > my $cv = AnyEvent->cv; > $client->get ($key, $cv); > my $value = $cv->recv;
That might work if you were using Coro as well, but without Coro, you can't have more than one CondVar doing ->recv at once. If Twiggy is doing one, then if M::C does ->recv, it will try to enter the event loop recursively and everything explodes. So while I agree it would be great if this could be done somehow, I really don't see any way to make it happen, at least not without rewriting M::C's interface in its entirety to use something like deferreds/promises and dispensing with the idea of offerring separate sync/async interfaces entirely. I do will point out, though, that Twiggy is *not* the default web server layer for Plack; in fact it is a specialized back-end for writing non- blocking asynchronous code, and if you're expecting code to be used under Twiggy, you need to write it in a callback style.
On Sun Jan 22 21:27:08 2012, michael.alan.dorman wrote: Show quoted text
> On Sun Jan 22 21:05:57 2012, TJC wrote: > I do will point out, though, that Twiggy is *not* the default web
server Show quoted text
> layer for Plack; in fact it is a specialized back-end for writing non- > blocking asynchronous code, and if you're expecting code to be used > under Twiggy, you need to write it in a callback style.
Sorry, I wasn't very clear in what I wrote there. I meant that Twiggy is the default back-end used by the "plackup" script that comes with Plack, if AnyEvent has been loaded. So, the act of using Memcached::Client causes Plack to use Twiggy, which then breaks on synchronous calls to Memcached::Client.