[Xml-compile] Request advice on a networking (??) issue

Mark Overmeer mark at overmeer.net
Fri Sep 21 21:20:39 GMT 2012


* David Tindall Mcmath (mcdave at stanford.edu) [120921 20:46]:
> When I run the script below from my Mac laptop, it hangs after
> about 250 requests.  On my Linux box, it runs just fine.

LWP::UserAgent can do connection caching. The X::C::Transport::SOAPHTTP
creates a LWP::UserAgent object by default with this 'keep_alive' on.
When the object is destructed, it does not shutdown the socket cleanly.  
Different UNIXes (and other OSes) have other ways to cleanup those
sockets, for instance with timeouts.

> my $wsdl = XML::Compile::WSDL11->new( 'centra2.wsdl' ) ;
> for my $i (1 .. 300 ) {
>     my $method = $wsdl->compileClient('getVersion', port => 'CWSSoap');
>     my $ans = $method->() ;

This is not how XML::Compile::SOAP is intented to be used: you do the
expensive compilation step each time again.  This should be:

  my $wsdl = XML::Compile::WSDL11->new( 'centra2.wsdl' ) ;
  my $method = $wsdl->compileClient('getVersion', port => 'CWSSoap');
  for my $i (1 .. 300 ) {
      my $ans = $method->() ;

The other side is, that it seems that the caching in ::SOAPHTTP
should be smart enough not to recreate LWP::UserAgents all the time.
Hum.

Can you test this:  XML/Compile/Transport/SOAPHTTP.pm

  + my $default_ua;
    sub userAgent(;$)
    {   my ($self, $agent) = (shift, shift);
        return $self->{user_agent} = $agent
            if defined $agent;
   
  -     $self->{user_agent} ||= LWP::UserAgent->new
  +     $self->{user_agent} ||= $default_ua ||= LWP::UserAgent->new
          ( requests_redirectable => [ qw/GET HEAD POST M-POST/ ]
          , parse_head => 0
          , protocols_allowed => [ qw/http https/ ]
          , @_
          );
    }

But the reorder is the real fix.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list