Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: using Net::Telnet to test Apache

by meonkeys (Chaplain)
on Nov 14, 2000 at 03:45 UTC ( #41472=note: print w/replies, xml ) Need Help??

in reply to using Net::Telnet to test Apache

I've seen the advice n times (where n > 3) to use the LWP libs instead of Net::Telnet. The problem is, does not specify which http daemon actually serves the page. It looks like IO::Socket::INET is the next best bet, this module lets one specify hostnames. Anyway, here's a working version of the originally posted code:
#!/usr/bin/perl use strict; use Time::HiRes qw( time tv_interval ); use Net::Telnet (); $0 = 'ruffbench'; unless (@ARGV){ die "Usage: $0 <host> [<host2> <host3> ...]\n"; } my $port = '80'; my $t = new Net::Telnet; my $get = "GET / HTTP/1.0\n\n"; my %time; foreach my $host (@ARGV) { print "$0: Connecting to $host. Starting timer.\n"; my $start = [ time() ]; $t->open(Host=>$host, Port=>$port); print "$0: Connected to $host. Sending request...\n"; $t->print($get); print $t->waitfor(String=>"Content-Type", Timeout=>5 ); my $end = [ time() ]; $t->close; print "\n$0: Connection closed. Timer stopped.\n\n"; $time{$host} = tv_interval($start, $end); } print "$0: Summary of results:\n"; foreach my $host (@ARGV) { printf "%9s: %10s ... %2.2f seconds\n", $0, $host, $time{$host}; }

Replies are listed 'Best First'.
RE: Re: using Net::Telnet to test Apache
by Fastolfe (Vicar) on Nov 14, 2000 at 03:52 UTC
    I'm not following. Presumably the only httpd daemon is the one listening on port 80. If you want a different daemon listening on a different port, LWP can handle just as easily.
      I'm talking about different hosts. Sorry for not being clearer. What I meant is that a URL does not necessarily specify which host a http daemon is active on. For instance, you could have 20 boxes that all correspond to one URL-- for example--that alternately serve pages to balance the load. I'm sure you already know all this.

      So, now the question is, what is the best way to test how each individual host's http daemon is doing? The only way I know how is by telnetting into that host's port 80 and doing a HTTP get. IO::Socket::INET sounds interesting, although I don't quite understand how it differs and I haven't successfully implemented it yet.
        No matter what you use, be it Net::Telnet or IO::Socket or the LWP modules, if you connect to '' and that hostname is load balanced, you're going to get different servers handling the request, sure. Sorry, I didn't realize that was going to be an issue (it's the first time you brought it up). If you can access each server individually by IP, perhaps you can simply pass that URL to the LWP modules: e.g. If you're using virtual hosting such that the Host: header makes a difference, I guess you're better off using IO::Socket and speaking HTTP yourself. If there isn't a way you can reach an arbitrary server directly, I don't see how any of the methods presented can help you, as they'd all be influenced by the load-balancing setup.
        I don't quite understand why you don't use LWP::Simple. In order to best simulate a real web browser, you should be downloading all of the web page anyway, so complicating your code with Net::Telnet just isn't worth it- unless you have a counter argument, I just don't see the point...
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://41472]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2021-10-24 09:43 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.