Created
September 3, 2009 08:28
-
-
Save typester/180187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rate AnyEvent::Gearman::Client Gearman::Client::Async | |
AnyEvent::Gearman::Client 1435/s -- -60% | |
Gearman::Client::Async 3571/s 149% -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::Base; | |
use Test::TCP; | |
use FindBin; | |
use Benchmark 'cmpthese'; | |
use AnyEvent::Gearman::Client; | |
use Gearman::Client::Async; | |
eval q{ | |
use Gearman::Worker; | |
use Gearman::Server; | |
}; | |
if ($@) { | |
plan skip_all | |
=> "Gearman::Worker and Gearman::Server are required to run this test"; | |
} | |
my $port = empty_port; | |
my $child = fork; | |
if (!defined $child) { | |
die "fork failed: $!"; | |
} | |
elsif ($child == 0) { | |
my $server = Gearman::Server->new( port => $port ); | |
$server->start_worker("$FindBin::Bin/worker.pl -s 127.0.0.1:$port"); | |
Danga::Socket->EventLoop; | |
} | |
else { | |
END { kill 9, $child if $child } | |
} | |
my $danga = Gearman::Client::Async->new( | |
job_servers => ["127.0.0.1:$port"], | |
); | |
my $ae = AnyEvent::Gearman::Client->new( | |
job_servers => ["127.0.0.1:$port"], | |
); | |
cmpthese( 10000, { | |
'Gearman::Client::Async' => sub { | |
$danga->add_task( | |
Gearman::Task->new( echo => \'Hello! Hello!', { | |
on_complete => sub { | |
my $res = $_[0]; | |
die unless $$res eq 'Hello! Hello!'; | |
Danga::Socket->SetPostLoopCallback(sub { 0 }); | |
}, | |
}), | |
); | |
Danga::Socket->EventLoop; | |
}, | |
'AnyEvent::Gearman::Client' => sub { | |
my $cv = AnyEvent->condvar; | |
$ae->add_task( | |
echo => 'Hello! Hello!', | |
on_complete => sub { | |
my $res = $_[1]; | |
die unless $res eq 'Hello! Hello!'; | |
$cv->send; | |
}, | |
on_fail => sub { die }, | |
); | |
$cv->recv; | |
}, | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Gearman::Worker; | |
use Getopt::Long; | |
my $opt_js; | |
GetOptions('s=s' => \$opt_js); | |
my $worker = Gearman::Worker->new; | |
$worker->job_servers(split(/,/, $opt_js)); | |
$worker->register_function( echo => sub { | |
my $job = shift; | |
my $arg = $job->arg; | |
return $arg; | |
}); | |
$worker->work while 1; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment