遠くのサーバーにファイルを保存。
おかげさまで風邪は、かなり抜けてきたんですが、
そのドタバタ前のメンテで、第二弾をリリースしましたー。
毎度の事ながら、あらゆる方面にありがとう、あーりがとう。
今回は劇的な改修はしてないので、効果も劇的ではないのですが、
少しメモリの節約している影響でちょっと速くなったよねー…という感じです。
てな訳で、最終回となる第三弾に向けて
調査フェーズ→コーディングに入るところなんですが
ちょっと気になってる事があって、週末は毎度の事ながらお勉強タイム。
さて、気になってるのは、ファイルの保存先について。
だいたい、どこのサービスも、静的なユーザーデータは、
アプリサーバーからnfsでマウントしているサーバー上に保存してたりしますが、
そこに保存するのが、ローカルに保存するのと比べて
どれくらい遅いのだろう?って事です。
てな訳で、めっさ適当に実験。
まずはnfsでマウント。
・/etc/exports を設定
/home/anigon localhost(rw)
・/etc/hosts.allow を設定
portmap:127.0.0.1
・デーモン起動
/usr/sbin/rpc.mountd/usr/sbin/rpc.nfsd
・設定した内容でエクスポート
[root@localhost anigon]# /usr/sbin/exportfs -v/home/anigon localhost.localdomain(rw,wdelay,root_squash)
・nfsを起動
/etc/init.d/nfs start
・マウント
mkdir /nfs
・マウントされているのを確認
[root@localhost anigon]# df -kFilesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
2677024 2429248 111792 96% /
/dev/hda1 101086 9522 86345 10% /boot
none 127908 0 127908 0% /dev/shm
127.0.0.1:/home/anigon
2677024 2429248 111808 96% /nfs
ほんじゃ、ベンチとりましょー。
・test.pl
#!/usr/bin/perl -wuse strict;
use Benchmark qw(:all);
my $localPath = '/home/anigon/nfs/testLocal.txt';
my $nfsPath = '/nfs/nfs/textNfs.txt';
my $loopCount = 100;
my $result = timethese($loopCount, {
'nfs' => '&_writeNfs',
'local' => '&_writeLocal'
});
cmpthese($result);
exit;
sub _writeLocal() {
return 0 unless open WR, ">${localPath}";
print WR 'test';
close WR;
return 1;
}
sub _writeNfs() {
return 0 unless open WR, ">${nfsPath}";
print WR 'test';
close WR;
return 1;
}
# end of this script
結果。
Benchmark: timing 100 iterations of 1local, nfs...local: 0 wallclock secs ( 0.03 usr + 0.06 sys = 0.09 CPU) @ 1111.11/s (n=100)
(warning: too few iterations for a reliable count)
nfs: 1 wallclock secs ( 0.02 usr + 0.32 sys = 0.34 CPU) @ 294.12/s (n=100)
(warning: too few iterations for a reliable count)
Rate nfs 1local
nfs 294/s -- -74%
local 1111/s 278% --
Benchmark: timing 1000 iterations of 1local, nfs...local: 1 wallclock secs ( 0.19 usr + 0.36 sys = 0.55 CPU) @ 1818.18/s (n=1000)
nfs: 21 wallclock secs ( 0.19 usr + 3.23 sys = 3.42 CPU) @ 292.40/s (n=1000)
Rate nfs 1local
nfs 292/s -- -84%
local 1818/s 522% --
案の定、マウントした先に保存すると、めちゃめちゃ遅い。
ちなみに、
「一度ローカルに保存したものをマウントした先にmv」と
「マウントした先でファイル生成して、同じくマウントした先にmv」を比較すると
一気にその差は縮まる模様?
んあー。あれー?localの方が wallclock やCPUん所の数字が大きいのになぁ。Benchmark: timing 100 iterations of 1local, nfs...
local: 15 wallclock secs ( 0.06 usr 1.46 sys + 0.56 cusr 6.17 csys = 8.25 CPU) @ 65.79/s (n=100)
nfs: 12 wallclock secs ( 0.06 usr 1.98 sys + 0.50 cusr 4.64 csys = 7.18 CPU) @ 49.02/s (n=100)
Rate nfs 1local
nfs 49.0/s -- -25%
local 65.8/s 34% --
うーんうーん。なんだこりゃ。