[Catalyst] timeouts
Yuval Kogman
nothingmuch at woobling.org
Fri Apr 14 11:09:57 CEST 2006
On Thu, Apr 13, 2006 at 16:49:41 -0500, Peter Karman wrote:
> greetings cattle-lusters,
>
> I've got a Cat app where I'm running into issues with DBI timeouts. I'm
> using raw DBI, but as I know there are lots of ORM developers here as
> well as us mere mortal Cat-rustlers, wondering how folks deal with this
> situation:
>
> sub foo : Local
> {
eval {
local $SIG{ALRM} = sub { die };
alarm $timeout;
> # create dbi object, prepare, execute
> # but at least one of those steps results in a long
> # delay due to ... whatever (traffic, load, etc.)
alarm 0; # cancel the timeout
$value; # return it
}
> }
Perhaps you should really make it into something like do_txn, that
takes a sub and executes it in this timed out eval, so that you
have:
my $value = $self->with_timeout( 10, sub {
....
});
> The DBI pod refers to Sys::SigAction as a good timeout handler. I'm
> headed that way. But wonder how folks deal with timeouts in Cat apps
> when a controller sends off for some info and there's a wait coming
> back. A quick cpan search for 'catalyst plugin alarm' didn't turn up
> anything.
I'm guessing Sys::SigAction is pretty compatible with what I just
proposed.
Either way, Catalyst does not (currently) make use of 'alarm'
anywhere. The problem with alarms is that they're process global. I
don't knoww how this behaves in mod_perl, but you should find out on
e.g. the mod_perl mailinglist/channel/manual.
I have a suspicion that you can use Time::HirRes's itimers to get
around this one per process limitation.
> I've got another example doing login auth against a server that may or
> may not feel like responding immediately. Since I'm using LWP::UserAgent
> in that case I just set the timeout explicitly, but DBI is a little
> trickier.
I am almost sure LWP::UserAgent does exactly what I pasted above -
it's very standard (I know for a fact that Net::Ping does it, since
that's where I learned it ;-)
--
Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060414/fbe6a18c/attachment.pgp
More information about the Catalyst
mailing list