Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Finding the size of the reponse using SOAP::Lite

by ianbell (Novice)
on Aug 07, 2008 at 18:18 UTC ( [id://702958]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all,

I'm working on a website which aggregates a number of webservice feeds, some of which are REST (and are accessed using LWP), and some which are SOAP (accessed using SOAP::Lite)

I'm trying to add in some benchmarking for these feeds, and i need to find out the size (in bytes) of the response to requests. for the RESTful ones, this is easy, i can just do content_length() on the LWP response.

Is there an similar way to do this with SOAP::Lite? I can't seem to find one.

The only approach I can find is to use the set the outputxml option in SOAP::Lite to true, and parse the returned XML myself, but I want to avoid this if I can.

Ian

  • Comment on Finding the size of the reponse using SOAP::Lite

Replies are listed 'Best First'.
Re: Finding the size of the reponse using SOAP::Lite
by AltBlue (Chaplain) on Aug 07, 2008 at 23:02 UTC
    for the RESTful ones, this is easy, i can just do content_length() on the LWP response.

    content_length?! Take care, as it does not do what you might think: it just returns the value of the Content-Length header, which - of course - may be missing... or just plain wrong (as I've seen already too many wanna-be-smart web apps that have no idea about its meaning).

    Is there an similar way to do this with SOAP::Lite?

    Quite similar in fact, as SOAP::Lite uses the same LWP modules for HTTP transport.

    The usual way to reach those HTTP::Response objects is to enable runtime tracing of transport events. Here's an example:

    use strict; use warnings; use SOAP::Lite +trace => [ transport => sub { my ($in) = @_; return if ref $in ne 'HTTP::Response'; printf "Response length: %d bytes.\n", bytes::length( $in->con +tent ); } ]; my $sv = SOAP::Lite->new->service('.../foo.wsdl'); $sv->fooMethod( 'foo', 'bar' );
Re: Finding the size of the reponse using SOAP::Lite
by spivey49 (Monk) on Aug 07, 2008 at 20:40 UTC

    I'm not a Soap expert, but from what I've read you should have access to the raw response. From there I would imagine you would be able to evaluate the response like a string and find the legnth in bytes.

    Something like this maybe:

    { use bytes; my $response_bytes= length($response); }

    Posting the reponse portion of your client might help

Re: Finding the size of the reponse using SOAP::Lite
by cbrandtbuffalo (Deacon) on Aug 07, 2008 at 19:29 UTC
    You might be able to use the trace/debug options to dump the output, then redirect it to a file or a variable and measure the size that way. See SOAP::Trace. Note the module versions as there have been some updates lately.
Re: Finding the size of the reponse using SOAP::Lite
by ianbell (Novice) on Aug 08, 2008 at 15:07 UTC
    OK, I think i've found a solution. It's not great but it'll do.

    Things based on trace aren't ideal, as I want to stick the results in a db, and i don't want to interfere with the normal behaviour too much.

    For the RESTful ones I'm going to start using length($response) (thanks for the tip on Content-Length, AltBlue)

    For the SOAP, I have two possibilities. I can either use outputxml and parse the SOAP response myself, or I can re-serialize the SOAP::Data response and just do a length() on the results.

    I think I'll do the latter. It'll be inaccurate, but it's ok as long as I'm consistent, since I'm trying to get results for the feeds relative to each other.

    Ian

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://702958]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found