tags:

views:

140

answers:

3

Hi all,

I'm calling a .net webservice from Linux using Perl (5.8.7). I'm using the SOAP::Lite library.

The basic proof of concept worked fine and now I'm trying it in the real world where I have to call the webservice many times. Now it looks like the web service call opens a file but does not release the file descriptor. The default maximum number of available is set to 256 and it suns out of that quickly after which the program dies. :(

Here's the code:

# Create the soap client
my $client = SOAP::Lite->new;

# Get raw SOAP xml output
$client->outputxml(1);

# Set connection parameters
$client->uri($namespace);

# set the url in the proxy member. The keep_alive parameter is needed if user authentication
# is used, it is passed on to the user agent class to set up an authenticated HTTP session
$client->proxy($url, keep_alive => 1);

# Set the user credentials 
$client->transport->credentials("$host:$port", ''
    , $user
    , $password
);

# define the webservice method
$client->on_action( sub { return "$namespace$method" } );
my $soapmethod = SOAP::Data->name($method)
    ->attr({xmlns => $namespace});

# Generate the SOAP parameters and make the call
my @paramarray = ( \%paramhash );
my $ps = ${MakeSoapParameters(\@paramarray)};

# output the current number of filedescriptors used for this process
system("ls -l /proc/$$/fd | wc -l");
# Make the call
my $result = $client->call($soapmethod => $ps );
# output the current number of filedescriptors used for this process AFTER the call
system("ls -l /proc/$$/fd | wc -l");

If I monitor the file descriptors used with ls -l /proc/$$/fd | wc -l I notice the number of used filedescriptors to go up every time I make a web service call.

Any help or hint would be appreciated.

A: 

I can't easily test this, but try deleting the created SOAP object. Or wrap this code in a function so when it goes out of scope, the destructor is called automatically.

xcramps
I tried that. Letting it og out of scope or even setting to 'undef'. Didn't change much.
Locutus
A: 

I think these file descriptors are sockets and usually it takes some time for system to shutdown TCP socket.

gonzo
Yup, that's what I'm suspecting at the moment. It is probably caused by the keep_alive flag in the proxy call. I'm look now for ways to either forcibly kill those connections or keep just one alive for all web service calls. the latter is probably the best.
Locutus
A: 

Solved it.
Apart from the fact that I need to learn more about object creation, instances and destruction in Perl...
Only creating the SOAP::Lite object once and keeping it around as long as I need to make calls to that webservice, does the trick. Before I created a SOAP::Lite object for every call.
Everybody thanks for thinking with me.

my $client;

sub MakeTheCall
{
    if (! defined $client)
    {
        # Create the soap client
        my $client = SOAP::Lite->new;
        # Get raw SOAP xml output
        $client->outputxml(1);
        # Set connection parameters
        $client->uri($namespace);
        # set the url in the proxy member. The keep_alive parameter is needed if user authentication
        # is used, it is passed on to the user agent class to set up an authenticated HTTP session
        $client->proxy($url, keep_alive => 1);
        # Set the user credentials 
        $client->transport->credentials("$host:$port", ''
            , $user
            , $password);
    }

    # rest of the code here

}
Locutus