Hi all,

Thanks for all of the responses yesterday. I did some testing today
using IO::Socket::INET vs LWP::Simple, and it was a wash:

Averages: (based on a test fetch to www.cnn.com)
IO AVG: 0.250 seconds/request
LWP AVG: 0.254 seconds/request

This is averaged over 20 requests each. IO may have had the advantage
here, but on other runs the numbers were reversed.

I think Uri is correct that the delay from the server is a much bigger
factor and that the overhead from either method is negligible.

I did also test this against one of my actual web service requests, and
the numbers had a similar relationship. No clear advantage to one method
or the other.

I think I'll stick with LWP for the time being for its dependability,
familiarity, and ease of use.

My test script (with sanitized test data) is attached for your perusal.

Thanks everyone. :-)

Peter


> -----Original Message-----
> From: Dan West [mailto:[email protected]]
> Sent: Wednesday, February 16, 2011 5:25 PM
> To: Uri Guttman; Peter Wood
> Cc: [email protected]
> Subject: RE: [Boston.pm] Lightweight module for web service calls?
> 
> I used JSON::RPC::Client to open up a bunch of services to my
> application's architecture over HTTPS. I also require HTTPS basic
> authentication with all requests which JSON::RPC::Client is able to
handle
> upon initialization. It has worked well thus far and I found that it
> actually uses LWP behind the scenes. Although, that part was not well
> documented. I have attached a testing script (real values removed, of
> course) that I use to access my services when I make changes to them.
> Peter, if you find this of any interest, I can also forward the
service
> library that I wrote to handle all of the JSON::RPC requests (it
actually
> also handles XML::RPC requests). Let me know.
> --Dan
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:boston-pm-
> [email protected]] On Behalf Of Uri Guttman
> Sent: Wednesday, February 16, 2011 4:09 PM
> To: Peter Wood
> Cc: [email protected]
> Subject: Re: [Boston.pm] Lightweight module for web service calls?
> 
> >>>>> "PW" == Peter Wood <[email protected]> writes:
> 
>   PW> Hi Uri,
>   >> https is just http over an ssl socket with a different port than
>   >> http. you can use IO::Socket::SSL for that. but the problems you
will
>   >> run into are wide and varied which is why LWP is so large. if you
> know
>   >> your http transactions will be very basic and not need help, it
is
>   PW> easy
>   >> to write a simple module. but it is so easy to get things wrong
and
>   PW> when
>   >> it gets more complicated, you will want LWP.
> 
>   PW> The requests are going to be in the form of POST requests using
>   PW> structured URLs with an optional POST body payload, the
responses
> will
>   PW> be JSON. I feel like that's simple enough to warrant a barebones
> module.
>   PW> That being said, I should probably write a simple socket module
and
> do
>   PW> some tests to compare it to LWP to confirm that LWP has as much
> overhead
>   PW> as I think it does.
> 
> it won't have as much as you think. parsing http headers is work as is
> generating them. the delays in response from the server will likely
> dwarf the cpu usage anyhow. is it worth your time to write this code?
> and it will take longer to write than you think.
> 
> uri
> 
> --
> Uri Guttman  ------  [email protected]  --------
http://www.sysarch.com
> --
> -----  Perl Code Review , Architecture, Development, Training, Support
---
> ---
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com
------
> ---
> 
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
#!/usr/local/bin/perl

use strict;
use Time::HiRes qw( time );

my $lwp_total      = 0;
my $io_total       = 0;
my $total_requests = 20;

my $hostname = 'www.cnn.com';
my $port     = '80';
my $proto    = 'tcp';
my $uri      = '/';

foreach my $count ( 1 .. $total_requests ) {
    print "Test $count:\n";

    # Do test on IO::Socket::INET;
    my $io_content = '';
    my $io_start   = time();
    use IO::Socket;
    my $sock = IO::Socket::INET->new(
        PeerAddr => $hostname,
        PeerPort => $port,
        Proto    => $proto,
    );
    print $sock "GET $uri HTTP/1.0\n\n";
    while ( my $line = <$sock> ) {
        $io_content .= $line;
    }
    my $io_finish = time();
    my $io_elapsed = sprintf( '%.3f', $io_finish - $io_start );
    print "IO Elapsed: $io_elapsed\n";
    $io_total += $io_elapsed;

    # Do test on LWP::Simple;
    my $lwp_content = '';
    my $lwp_start   = time();
    use LWP::Simple;
    $lwp_content = get( 'http://' . $hostname . ':' . $port . $uri );
    my $lwp_end = time();
    my $lwp_elapsed = sprintf( '%.3f', $lwp_end - $lwp_start );
    print "LWP Elapsed: $lwp_elapsed\n";
    $lwp_total += $lwp_elapsed;

    print "\n";
}

# Calculate Averages
my $io_avg  = sprintf( '%.3f', $io_total / $total_requests );
my $lwp_avg = sprintf( '%.3f', $lwp_total / $total_requests );
print "\nAverages:\n";
print "IO AVG: $io_avg seconds/request\n";
print "LWP AVG: $lwp_avg seconds/request\n";
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to