"Eamon Daly" <[EMAIL PROTECTED]> writes:
> I've seen a couple posts on this subject but no replies. I
> need to cut off a request with at least 98% accuracy at 2
> seconds. For a particular URL (which I can't reveal,
> unfortunately), LWP's timeout doesn't always do the trick,
> and even wrapping an eval/ALRM around it fails to the tune
> of 50%. Stranger still, when the timeout /does/ finally come
> around, it rings on 5 second intervals, no matter /what/ the
> timeout was set to. Here's the sample code:
>
> use Time::HiRes qw(alarm sleep);
> ...
> my $t0 = [gettimeofday];
> my $res;
> eval {
> local $SIG{ALRM} = sub { die "alarm timeout" };
> alarm($timeout);
> $res = $ua->get($np_key_url);
> alarm(0);
> };
> alarm(0);
> my $real_time_taken = &tv_interval($t0);
>
> Sample output from my test run:
>
> 500 alarm timeout Fetch took 1.000 seconds.
> 500 alarm timeout Fetch took 1.003 seconds.
> 500 alarm timeout Fetch took 1.000 seconds.
> 500 alarm timeout Fetch took 5.018 seconds.
> 500 alarm timeout Fetch took 1.003 seconds.
> 500 alarm timeout Fetch took 15.149 seconds.
>
> Does this sound like an issue with LWP, IO:Socket, perl, or
> RedHat? I'm absolutely dying, here. I'm using:
>
> LWP::UserAgent 2.004
> Time::HiRes 1.51
> IO 1.20
> IO::Socket 1.27
> IO::Socket::INET 1.26
LWP relies on IO::Socket to do the connect timeout. Once it is
connected it will do its own timeout before each read/write.
On Linux it might be instructive to run you program with
'strace -tt'. That would show where the time is spent.
Regards,
Gisle