freebsd-logo

これを見て、「おや?でもそこまでsyslogdって遅かったっけ」と思ったのだけど、どうやらLinuxとFreeBSDでは事情が違うようで。

syslogは実は重い→syslog-ngやdaemontoolsのmultilogにしてみるとか
なんでそんなにsyslogdは遅いのよ?!という話は以下の記事が詳しい。
99syslog - syslog() 及び syslogd の考察(最終更新:2003/5/30)
ここでは、私が、Linux システムで使われている syslogd(sysklogd-1.4.1) の ソースを解析して分かった事について述べます。
syslogd は、標準ではログメッセージを記録する度に fsync() します。

まず、FreeBSDのsyslogdでは、kern.*なものだけfsync()が強制されます。しかも、それも設定ファイルの設定で変更可能です。

man syslog.conf
To ensure that kernel messages are written to disk promptly, syslog.conf calls fsync(2) after writing messages from the kernel. Other messages are not synced explicitly. You may prefix a pathname with the minus sign, ``-'', to forego syncing the specified file after every kernel message. Note that you might lose information if the system crashes immediately following a write attempt. Nevertheless, using the ``-'' option may improve performance, especially if the kernel is logging many messages.

その事は、sourceを見ても確認できます。

/usr/src/usr.sbin/syslogd/syslogd.c
1036: static void
1037: dofsync(void)
1038: {
1039:   struct filed *f;
1040: 
1041:   for (f = Files; f; f = f->f_next) {
1042:           if ((f->f_type == F_FILE) &&
1043:               (f->f_flags & FFLAG_NEEDSYNC)) {
1044:                   f->f_flags &= ~FFLAG_NEEDSYNC;
1045:                   (void)fsync(f->f_file);
1046:           }
1047:   }
1048: }

わざわざFFLAG_NEEDSYNCを外してからfsync()してます。

syslogに限らず、/sbin/usr/sbinまでちゃんと面倒みてくれるところも私が鯖にFreeBSDを好んで使う理由です。Linux Binaryも動くし:)

そうそう。AudreyたんもメインはFreeBSDですよ、といってファンを増やしてみるテスト;)

Dan the Daemonphilia