Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

http benchmark using POE

by Kanishka.black0 (Beadle)
on Feb 08, 2013 at 09:29 UTC ( #1017780=perlquestion: print w/ replies, xml ) Need Help??
Kanishka.black0 has asked for the wisdom of the Perl Monks concerning the following question:

i have looked at Apache Benchmark 2 which has obviosuly a single url benchmark stuff

Well it fall short of dynamic URL

i tried to create http broadcaster using POE

its wokring fine, i can't figure out where i can get time taken for each session

#!/usr/bin/perl use warnings; use HTTP::Request::Common qw(GET POST); use POE qw(Component::Client::HTTP); use YAML; my @url_list; for(1 .. 10) { my $a = rand(900); my $b= rand(900); my $t = int(rand(100000)); my $url = "http://127.0.0.1:3000/search/".$t."/?a=".$a."&b=".$b; push @url_list, $url; } POE::Component::Client::HTTP->spawn(Alias => 'ua'); sub got_response { my ($SESSION, $heap, $request_packet, $response_packet) = @_[SESSION +,HEAP, ARG0, ARG1]; my $http_request = $request_packet->[0]; my $http_response = $response_packet->[0]; } sub _start { my $kernel = $_[KERNEL]; foreach my $url (@url_list) { $kernel->post("ua" => "request", "got_response", GET $url); } } POE::Session->create(package_states => [main => ["_start", "got_respon +se"]]); $poe_kernel->run();

Comment on http benchmark using POE
Download Code
Re: http benchmark using POE
by rcaputo (Chaplain) on Feb 10, 2013 at 14:33 UTC

    My response is embedded as comments in my revised version of your sample program:

    #!/usr/bin/perl use warnings; use HTTP::Request::Common qw(GET POST); use POE qw(Component::Client::HTTP); use Time::HiRes qw(time); # TODO - If @url_list gets very large, see the first example at # http://poe.perl.org/?POE_Cookbook/Web_Client for known pitfalls and # solutions. my @url_list; for (1 .. 10) { my $a = rand(900); my $b = rand(900); my $t = int(rand(100000)); my $url = "http://127.0.0.1:80/search/$t/?a=$a&b=$b"; push @url_list, $url; } # TODO - POE::Component::Client::HTTP uses default keep-alive socket # concurrency and timeouts that are friendly to web sites but may not # be appropriate for benchmarking. To change that, see the # ConnectionManager at: # http://search.cpan.org/~rcaputo/POE-Component-Client-HTTP-0.947/lib/ +POE/Component/Client/HTTP.pm#spawn POE::Component::Client::HTTP->spawn(Alias => 'ua'); sub got_response { my $now = time(); my ($SESSION, $heap, $request_packet, $response_packet) = @_[SESSION, HEAP, ARG0, ARG1]; my $http_request = $request_packet->[0]; my $http_response = $response_packet->[0]; # Find the time since the "tag" was defined. # This may not be appropriate for benchmarking since a lot of # interpreter-level work has been done to get here. HTTP headers # have been parsed by HTTP::Response, for example. This overhead # can't be separated from the web server's performance at this high # level. print "$http_request:\n", ($now - $request_packet->[1]), " sec\n"; } sub _start { my $kernel = $_[KERNEL]; foreach my $url (@url_list) { $kernel->post( "ua" => "request", "got_response", GET($url), time(), # Called a "tag" in PoCo::Client::HTTP's docs. ); } } POE::Session->create(package_states => [main => ["_start", "got_respon +se"]]); POE::Kernel->run();

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-09-19 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (130 votes), past polls