hi, LWP fetches normally by 4k chunks, if you want to time them you can use the code1 below.
On the other hand for some reason code2 doesn't work.
The output should look something like specified below.
If you wrap "LWP::Protocol::collect", you will time the whole fetch, not every chunk.

One more thing which may be interesting to know is, that the timeout you specify (LWP,Mechanize...) is the timeout for every chunk not the whole request (default:180sec).
So the request timeout could go far above 3 min.
hth
-----code1-----
use LWP::Debug qw(+); use Time::HiRes qw(gettimeofday tv_interval); my $ts; use LWP::Protocol::http; use Hook::LexWrap; wrap 'LWP::Protocol::http::SocketMethods::sysread', pre => sub { $ts = [gettimeofday] }, post => sub { printf ">>%.5f\n" , tv_interval($ts) };
-----code2-----
use LWP::Debug qw(+); use Aspect; my $pcut = call qr/LWP::Protocol::http::SocketMethods::sysread/; before { $ts = [gettimeofday] } $pcut; after { printf ">>%.5f\n" , tv_interval($ts) } $pcut;
====output=====
LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () >>0.00536 LWP::Protocol::collect: read 796 bytes >>0.00007 LWP::Protocol::collect: read 3356 bytes >>0.00071 LWP::Protocol::collect: read 1460 bytes >>0.00103 LWP::Protocol::collect: read 1460 bytes >>0.00005 LWP::Protocol::collect: read 997 bytes LWP::UserAgent::request: Simple response: OK

Replies are listed 'Best First'.
Re: Timing LWP fetches
by merlyn (Sage) on Jan 03, 2007 at 23:32 UTC