Aad has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a little Perl script (to beging with) that I want to run 24/7 for a week or two to monitor the base-response time of a websiet. The $latency, however, seems unreal after the first time... caching?

Is there a way to destroy the $ua object or disable caching some other way? Here it is...

# # pingloop.pl # use LWP::UserAgent; use Time::HiRes 'time', 'sleep'; $ua = LWP::UserAgent->new; $ua->proxy ('http', 'http://10.12.8.12:8080'); $count = 5; while ($count--) { $start = time(); $response = $ua->get("http://myaccount.polymerchemicals.com/ping.h +tm"); $latency = time() - $start; print "Received in $latency seconds\n"; sleep (60); }
And here are the number:
Received in 0.4375 seconds Received in 0.03125 seconds Received in 0.03125 seconds Received in 0.03125 seconds Received in 0.03125 seconds
TIA, Aad Slingerland, The Netherlands.

Replies are listed 'Best First'.
Re: LWP::UserAgent without caching?
by liz (Monsignor) on Aug 21, 2003 at 12:08 UTC
    It would seem to me the proxy server is messing up your response times.

    Can you do it without the proxy? If not, can you reconfigure the proxy so that requests from your IP will never get cached? Even if you can get it to not cache for you, any data you collect will more or less meaningless as you have no idea what the influence of the proxy server is. Can't you run this script from a machine in your DMZ?

    Liz

Re: LWP::UserAgent without caching?
by Anonymous Monk on Aug 21, 2003 at 12:25 UTC
    perldoc LWP::UserAgent |grep -i cach File STDIN: conn_cache undef a "LWP::ConnCache" is set up (see conn_cache() method below). +The for the connection cache. The "keep_alive" option also has the $ua->conn_cache([$cache_obj]) Get/set the *LWP::ConnCache* object to use.
    See, no caching is done.
Re: LWP::UserAgent without caching?
by tcf22 (Priest) on Aug 21, 2003 at 14:25 UTC
    To destroy the ua object, you could throw the new() call in the loop. I don't know if that will prevent caching, because of the proxy, but you could try this.
    use LWP::UserAgent; use Time::HiRes 'time', 'sleep'; $count = 5; while ($count--) { my $ua = LWP::UserAgent->new; $ua->proxy ('http', 'http://10.12.8.12:8080'); $start = time(); $response = $ua->get("http://myaccount.polymerchemicals.com/ping.h +tm"); $latency = time() - $start; print "Received in $latency seconds\n"; sleep (60); }