分散関数呼び出し
Posted feedbacks - Perl
これまたPerlのカバレッジを上げるため。 非常にtrivialなAPI. http://host/dir/doukaku_remote/fun/arg/more/args にアクセスすると、text/plainで Remote::Server::Trivial::fun(arg,more,args) の実行結果が返る。 測定環境として, ・Server: FreeBSD 6.2-Stable; Xeon 2.4GHz; 2GB RAM; apache-1.3.x; mod_perl ・完全remote ・Perl 5.8.8 速度はmod_perlで100req/sほど。Web API、単一serverとしては悪くないかな。 もっともこの程度のtrivialな作業にHTTPはいささか重たくもあるのではあるけれど。 Dan the Perl Monger
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #!/usr/local/bin/perl
#
# $Id: doukaku_remote.cgi,v 0.1 2007/11/08 14:49:27 dankogai Exp dankogai $
#
use strict;
use warnings;
use CGI;
use URI::Escape;
use CGI::Carp qw/fatalsToBrowser/;
sub Remote::Server::Trivial::pricestring{
my ($price, $discount) = @_;
my $dprice = $price * (1 - $discount/100);
"Price: $dprice Yen ($discount% discount from $price Yen)\n";
}
my (@args) = split m/\//, uri_unescape($ENV{PATH_INFO});
shift @args;
my $cmd = shift @args;
my $result = eval{
no strict 'refs';
&{'Remote::Server::Trivial::' . $cmd}(@args);
};
die $@ if $@;
use bytes;
print
"Content-Type: text/plain\n",
"Content-Length: ", bytes::length($result), "\n\n",
$result;
# end of server
#!/usr/local/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $times = shift || 10000;
my $api_root = 'http://where.ever/you/put/doukaku_remote.cgi';
my $cmd = "pricestring";
$|=1; # autoflush;
for (1..$times){
my $req = join "/", $api_root, $cmd, $_, int(rand(100));
my $result = get($req);
chomp $result;
print "$_:$result\r"
}
print "\n";
#end of client
|


沢渡 みかげ
#3401()
Rating0/0=0.00
[ reply ]