2011年(14)
分类: LINUX
2011-04-09 14:02:58
Gearman perl 实践
环境:3台Linux主机
软件:gearman-0.14.tar.gz
Client:安装gearman::client
Work:安装 gearman::worker
Job 安装 gearman-0.14.tar.gz
Client端代:
use Gearman::Client;
my $client = Gearman::Client->new;
$client->job_servers(’192.168.0.2:4730′);
my $result = $client->do_task(‘wordcount’,’the quick brown fox jumps over the lazy dog’);
print “Words $$result\n”;
Worker端代码:
use Gearman::Worker;
my $worker = Gearman::Worker->new;
$worker->job_servers(’192.168.0.2:4730′);
$worker->register_function(‘wordcount’ => \&wordcount);
$worker->work while 1;
sub wordcount
{
my ($input) = @_;
my @words = split /\s+/,$input->arg;
return (scalar @words);
}
Job端开启gearman的服务
Gearmand –d –u root
详细信息:
Gearmand –vvv