develooper Front page | perl.libwww | Postings from July 2001

Re: Web Client Library BOF

Thread Previous | Thread Next
From:
troc
Date:
July 18, 2001 13:15
Subject:
Re: Web Client Library BOF
Message ID:
slrn9lbaji.1lf.troc@eyrie.homenet
On 17 Jul 2001 17:25:59 -0700, Gisle Aas <gisle@ActiveState.com> wrote:
>
>I'm planing on running a "Web Client Library BOF" at the ORA Conference
>this year (have a timeslot on Thursday;
>http://conferences.oreillynet.com/cs/os2001/pub/10/bofs.html).
>
>As a bit of research before the BOF I today tried out various
>libraries that are available to Perl.  One of the things I tried was
>to write a little loop that fetches the ActiveState homepage 50 times.
>I got kind of strange results:
>
>LWP             1.8s  0.45s   0.07s    5680 kB
>LWP::Simple     1.8s  0.15s   0.07s    4432 kB
>HTTP::GHTTP    10.9s  0.06s   0.07s    3484 kB
>HTTP::Lite     11.2s  1.56s   0.13s    5244 kB
>HTTP::Webdav    1.3s  0.01s   0.02s    4152 kB

[...]

Included is a test for yet another HTTP client library.

-- Rocco Caputo / troc@netrus.net / poe.perl.org / poe.sourceforge.net

#!/usr/bin/perl -w

# Required modules:
#
# Time::HiRes                   (for benchmarking)
# HTTP::Request::Common         (for building request objects)
# POE                           (for the events/select framework)
# POE::Component::Client::HTTP  (the user agent)

use strict;
use lib '/home/troc/perl/poe';
use lib '/home/troc/perl/poco/client-http/blib/lib';

use HTTP::Request::Common qw(GET);
use Time::HiRes qw(time);
use POE qw(Component::Client::HTTP);

# Tweakable parameters.  MAX_REQUESTS is the maximum number of times
# to fetch a pages.  MAX_PARALLEL is the number of outstanding
# requests to run at any given time.  PAGE_TO_FETCH is the URL to get
# each time.

sub MAX_REQUESTS  () { 50 }
sub MAX_PARALLEL  () { 10 }
sub REQUEST       () { +GET 'http://localhost/' }

# Start the user agent.

POE::Component::Client::HTTP->spawn();

# Start something to use it.

POE::Session->create
  ( inline_states =>
    { _start => sub {
        my ($kernel, $heap) = @_[KERNEL, HEAP];
        $heap->{total_requests} = 0;
        $heap->{current_requests} = 0;
        $heap->{before} = [ time(), times() ];
        $_[KERNEL]->yield('fetch');
      },
      fetch => sub {
        my ($kernel, $heap) = @_[KERNEL, HEAP];
        if ( $heap->{current_requests} < MAX_PARALLEL and
             $heap->{total_requests} < MAX_REQUESTS
           ) {
          $heap->{current_requests}++;
          $heap->{total_requests}++;
          $kernel->call( weeble => request => got_response => REQUEST );
        }
      },
      got_response => sub {
        $_[HEAP]->{current_requests}--;
        $_[KERNEL]->yield('fetch');
      },
      _stop => sub {
        my $heap = $_[HEAP];

        my @after = ( time(), times() );
        for my $i (0..$#after) {
          $after[$i] -= $heap->{before}->[$i];
        }

        print "@after\n";
      },
    },
  );

# Run the main loop.

$poe_kernel->run();
exit 0;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About