# cd mybench-1.0 # ls META.yml Makefile.PL MyBench.pm bench_example # perl Makefile.PL Writing Makefile for mybench # ls META.yml Makefile Makefile.PL MyBench.pm bench_example
Makefileができました。
とりあえず、bench_exampleを実行してみる
# bench_example forking: ++++++++++ sleeping for 2 seconds while kids get ready waiting: DBD::mysql::st execute failed: called with 1 bind variables when 0 are needed at /usr/local/bin/bench_example line 42. DBD::mysql::st execute failed: called with 1 bind variables when 0 are needed at /usr/local/bin/bench_example line 42. (省略) Use of uninitialized value in numeric gt (>) at /usr/local/share/perl/5.8.8/MyBench.pm line 134. Illegal division by zero at /usr/local/share/perl/5.8.8/MyBench.pm line 115.
エラーが出ました・・・。
というか、実行方法がすでに違います。 実は、perlをさわるのは初めてで、よくわかっていません。
あらためて、
perl bench_exampleとして実行してみます
# perl bench_example forking: ++++++++++ sleeping for 2 seconds while kids get ready waiting: ———- Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.8/MyBench.pm line 98. Use of uninitialized value in split at /usr/local/share/perl/5.8.8/MyBench.pm line 99. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.8.8/MyBench.pm line 101. (省略) Use of uninitialized value in numeric gt (>) at /usr/local/share/perl/5.8.8/MyBench.pm line 134. Use of uninitialized value in numeric gt (>) at /usr/local/share/perl/5.8.8/MyBench.pm line 134. Illegal division by zero at /usr/local/share/perl/5.8.8/MyBench.pm line 115.
・・・bench_exampleの設定何一つ替えていないので、エラーが出るのも当たり前ですよ。
ということで、
bench_exampleの編集
# cp bench_example bench_example.org # vi bench_example
bench_exampleファイル
#!/usr/local/bin/perl -w
use strict; use MyBench; use Getopt::Std; use Time::HiRes qw(gettimeofday tv_interval); use DBI;
my %opt; Getopt::Std::getopt(‘n:r:h:’, \%opt);
my $num_kids = $opt{n} || 10; my $num_runs = $opt{r} || 100; my $db = “test”; my $user = “test”; my $pass = “”; my $port = 3306; my $host = $opt{h} || “192.168.0.1”; my $dsn = “DBI:mysql:$db:$host;port=$port”;
my $callback = sub { my $id = shift; my $dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1 }); my $sth = $dbh->prepare(“SELECT * FROM mytable WHERE ID = ?”);
my $cnt = 0; my @times = ();
(以下略)
このファイルを以下のように編集
#!/usr/local/bin/perl -w
use strict; use MyBench; use Getopt::Std; use Time::HiRes qw(gettimeofday tv_interval); use DBI;
my %opt; Getopt::Std::getopt(‘n:r:h:’, \%opt);
my $num_kids = $opt{n} || 10; my $num_runs = $opt{r} || 100; my $db = “xxx_dev”; <=ここ(ベンチマークテストしたいDB名) my $user = “root”; <=ここ (上に記載したDBのユーザー) my $pass = “”; my $port = 3306; my $host = $opt{h} || “localhost”; <=ここ(上に記載したDBがあるホスト) my $dsn = “DBI:mysql:$db:$host;port=$port”;
my $callback = sub { my $id = shift; my $dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1 }); my $sth = $dbh->prepare(“SELECT * FROM users WHERE ID = ?”); <=ここ(ベンチマークテストしたいSQL文。)
my $cnt = 0; my @times = ();
(以下略)
ちなみに、 36行目あたりにある
my $v = int(rand(100_000));
の$vが
my $sth = $dbh->prepare(“SELECT * FROM users WHERE ID = ?”);
の?に入ります。
いざ実行!
# perl bench_example forking: ++++++++++ sleeping for 2 seconds while kids get ready waiting: ———- test: 1000 0.000173 0.367284 0.001990417 1.990417 5024.07284503699 clients : 10 queries : 1000 fastest : 0.000173 slowest : 0.367284 average : 0.001990417 serial : 1.990417 q/sec : 5024.07284503699
forking: ++++++++++ sleeping for 2 seconds while kids get ready waiting: ———- Use of uninitialized value in scalar chomp at /usr/local/share/perl/5.8.8/MyBench.pm line 98. Use of uninitialized value in split at /usr/local/share/perl/5.8.8/MyBench.pm line 99. Use of uninitialized value in addition (+) at /usr/local/share/perl/5.8.8/MyBench.pm line 101. (省略) Use of uninitialized value in numeric gt (>) at /usr/local/share/perl/5.8.8/MyBench.pm line 134. Use of uninitialized value in numeric gt (>) at /usr/local/share/perl/5.8.8/MyBench.pm line 134. Illegal division by zero at /usr/local/share/perl/5.8.8/MyBench.pm line 115.
***************************************************************** *config.breakpoint_server has been deprecated and has no effect.* ***************************************************************** /****/****/****/…. (以下ファイル名など) というエラーが表示されました。調べていくうちに、おそらくローカル環境がおかしいだろう というところまで突き止めまして、 インストールされている gem を調べてみました。
gem list でインストールされている gem を見ます。
*** LOCAL GEMS ***
actionmailer (1.3.3.7116, 1.3.3, 1.2.5) Service layer for easy email delivery and testing. … 妙なバージョンがインストールされていました。1.3.3.7116 ですね。
** [out :: 192.168.0.1] stopping port 3000 ** [out :: 192.168.0.1] stopping port 3001 ** [out :: 192.168.0.1] starting port 3000 ** [out :: 192.168.0.1] starting port 3001
スッキリです。 mongrelの目覚めもバッチリです。 いつもこの調子で頑張ってほしいものです。
とはいえ、もやしっこのmongrelはたまにスッキリ立ち上がりません。 そのときのログはこちら。
*** [err :: 192.168.0.1] ** !!! PID file tmp/pids/mongrel.3000.pid already exists. Mongrel could be running already. Check your log/mongrel.3000.log for errors. *** [err :: 192.168.0.1] ** !!! Exiting with error. You must stop mongrel and clear the .pid before I’ll attempt a start. *** [err :: 192.168.0.1] ** !!! PID file tmp/pids/mongrel.3001.pid already exists. Mongrel could be running already. Check your log/mongrel.3001.log for errors. *** [err :: 192.168.0.1] ** !!! Exiting with error. You must stop mongrel and clear the .pid before I’ll attempt a start. ** [out :: 192.168.0.1 stopping port 3000 ** [out :: 192.168.0.1] stopping port 3001 ** [out :: 192.168.0.1] starting port 3000 ** [out :: 192.168.0.1] ** [out :: 192.168.0.1] starting port 3001 ** [out :: 192.168.0.1]