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

Hi - I'm running some tests on a server load balancer (foundry).

I have a virtual server IP that maps onto 6 possible "real" servers. The real servers have a simple html page that displays the hostname which allows me to view where the SLB has sent the http request.

I have put together a simple script using LWP::UserAgent to get the servername from the html returned.

I have this running in an endless while loop. I recreate the user-agent in each itteration of the loop but my results suggest that each new user-agent is re-using the previous user-agent's TCP connecion, consequently, the load balancer does not map me onto the next real server in the pool. If I kill and restart the script I do get mapped onto a new server (suggesting that the load balancer sees a new connection).

My question is:

How can I force LWP to initiate a new TCP connection every time I create a new useragent ?

Thanks

James

  • Comment on LWP::UserAgent - new connection for each new user-agent?

Replies are listed 'Best First'.
LWP::UserAgent - new connection for each new user-agent?
by pg (Canon) on Oct 31, 2004 at 03:13 UTC

    LWP::UserAgnet does not create any TCP connection. The connections are created for the get requests at the time when you get the html pages. The connection comes and goes, that's why you see the "same connection" all the time.

    You can cache the connection though LWP::ConnCache for certain protocols, as you didn't mention it, I assume you didn't go that complex.

Re: LWP::UserAgent - new connection for each new user-agent?
by Anonymous Monk on Oct 31, 2004 at 19:56 UTC
    If the virtual servers in your load balancer have no requests other than yours, it is possible the LB is being "smart" and mostly sending the requests to the first real server.

    Try with some real load, run ApacheBench or something against the LB while your LWP:UA script runs.

    $ ab -c 100 -n 10000 http://yoursite/