C ã§ãªã©ã¤ãããã¦ãã¸ã§ããµã¼ãã¼ gearmand ã試ãã
ãã¤ã®éã«ãã http://gearmanproject.org/doku.php ã«ã¦ãgearman library 0.1 ã C ã§æ¸ãç´ããã¦ã¾ãããMySQL ã§æå㪠Brian Aker ããéçºãã¦ããããã§ãã
ããã¯æå¾
åºæ¥ãããï¼
追試 (2009-01-16T21:49:11+09:00)
0.02 ããªãªã¼ã¹ãã¦ãã®ã§è©¦ãã¦ã¿ã¾ãããä¸ã®ãµã³ãã«ã¯æ£å¸¸ã«å®å®ãã¦åãã¦ã¾ããã
ä¸å¿å ±åã
ã¤ã³ã¹ãã¼ã«
CentOS 5.2 ã§è©¦ãã¦ã¿ã¾ããã
libevent ã®ã¤ã³ã¹ãã¼ã«
CentOS ã® libevent 㯠yum ã§ã¤ã³ã¹ãã¼ã«ããã¨ã1.1a ã¨è¨ãã¨ãã§ããªãå¤ããã®ã§ãããã§ã¯ gearman library ã¯ã³ã³ãã¤ã«åºæ¥ã¾ãããå¾ã£ã¦ã½ã¼ã¹ããã¤ã³ã¹ãã¼ã«ãã¾ãã
$ cd /usr/local/src $ wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz $ tar xfz libevent-1.4.9-stable.tar.gz $ cd libevent-1.4.9-stable $ ./configure --enable-shared $ make && make install
ã¨ããããªæãã§ã
gearman ã®ã¤ã³ã¹ãã¼ã«
ãã£ã¡ãã½ã¼ã¹ããã¤ã³ã¹ãã¼ã«ãã¾ãã
$ cd /usr/local/src $ wget http://launchpad.net/gearmand/trunk/0.1/+download/gearmand-0.1.tar.gz $ tar xfz gearmand-0.1.tar.gz $ cd gearmand-0.1 $ ./configure --enable-shared --with-event=/usr/local $ make && make install
試ãã¦ã¿ã
以前書いた奴ãã³ããããã
ã½ã¼ã¹
worker.pl
#!/usr/bin/perl use strict; use warnings; use Gearman::Worker; use Storable qw(thaw); use List::Util qw(sum); my $worker = Gearman::Worker->new; $worker->job_servers('localhost'); $worker->register_function( sum => sub { my $job = shift; my @args = @{thaw($job->arg)}; return sum @args; } ); $worker->work while(1);
client.pl
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use Perl6::Say; use Storable qw(freeze thaw); use Gearman::Client; use Gearman::Task; my $client = Gearman::Client->new; $client->job_servers(qw|localhost|); my $args = freeze([1..9]); my $result_ref = $client->do_task("sum", \$args, {}); say dump($$result_ref);
試ãã¦ã¿ã
gearmand ãèµ·åãã¦ã¿ããä»åã¯ãã¹ãç®çãªã®ã§ -v ã¤ãã¦ããã
$ /usr/local/bin/gearmand -v
ã§ã©ããªã£ããã¨è¨ãã¨ã
Method for libevent: epoll Listening on port 7003 127.0.0.1:49696 Connected (1 current, 1 total) 127.0.0.1:49697 Connected (2 current, 2 total) 127.0.0.1:49697 Disconnected Segmentation fault
ã£ã¦æããclient ã®ã³ã¼ãä¸åå®è¡ãã¦çµæãè¿ã£ã¦ãããã ãã©ãçµå± Seg ã£ã¦è½ã¡ãï¼ï¼
ã¾ã ã¾ã å®å®çã¨ã¯è¨ããªãããã§ããã
ã¡ãªã¿ã« Client Library ãæä¾ããã¦ãã®ã§ C ã C++ 㧠worker ã client ãè¨è¿°ããäºãå¯è½ã¿ããã§ãã
å®å®ãã¦ãããé¢ç½ããã
ããããã°ãStorable ãããªã㦠JSON å½¢å¼ã§ãã¼ã¿æ±ãã°ããã®ããªããã£ã¡ã®ããã¼ã¿ãã«ã§ãããã
ã¨ããããçãQ4M 使ã£ã¨ãã£ã¦äºããªï½