Nucleus処理時間計測(NP_CoreBench)
別記事『個別アイテムパース時間』で処理時間の測定を行ないました。
今回はパース開始前の処理時間(初期化)も含め計測しました。
Nucleus高速化の為のチェックポイントとしてメモします。
サーバ環境
- CPU: VIA C3 600MHz (4.5 x 133) Celeron 300A と同等の性能
- Memory: 512MB
- OS: Windows 2000 sp4
- Apache 1.3.37
- PHP 4.4.6
- MySQL 3.23.58-nt
Nucleus環境(インストール直後の状態)
- Nucleus 3.24 EUC
- インストール直後の状態
- プラグインは時間計測用の簡易的なもの1つ(NP_CoreBench)
- 記事の表示時間を計測(index?itemid=1)
結果(インストール直後の状態)
- PreSkinParse (スキンのパースの直前): 約0.31~0.35秒で通過
- PostSkinParse (スキンのパースの直後): 約0.51から0.57秒で通過
Nucleusインストール直後の状態のでトータル0.6秒弱の処理時間が発生しています。
初期化処理(PreSkinParseまで)に60%前後、パース(PreSkinParse~PostSkinParse)に40%前後の割合です。
Nucleus環境(当記事)
- Nucleus 3.24 EUC
- 当サイトのデータを開発環境へコピー
- プラグインは30個弱
- 記事の表示時間を計測
結果(当記事)
- PreSkinParse (スキンのパースの直前): 約0.53~0.6秒で通過
- PostSkinParse (スキンのパースの直後): 約1.75から1.84秒通過
当サイトのデータを利用した場合、約1.8秒の処理時間が発生しています。
初期化処理(PreSkinParseまで)に約30%、パース(PreSkinParse~PostSkinParse)に70%前後の割合です。
前述のNucleusインストール直後状態と比較すると処理時間は3倍になり、パースに要する処理時間比率が40%から70%へと増えています。
PreItemイベントを利用するプラグインを8つ入れてますので、記事表示の負荷が増大していると推測されます。
計測に利用した簡易的なプラグイン NP_CoreBench
管理者がページを参照した場合のみ処理時間が管理操作履歴に記録されます。
NP_CoreBench.phpという名前でソースをコピーして保存して下さい。
インストール前にlibs/globalfunctions.phpに1行コードを追加する必要があります。
globalfunctions.phpへの記述例
<?php
$benchmark_start = microtime();
以下省略.....
<?php
class NP_CoreBench extends NucleusPlugin {
var $buf_bench, $time_start, $time_pass;
function getName() { return 'CoreBench'; }
function getAuthor() { return 'Yaibeen'; }
function getURL() { return 'http://nucleus.yaibeen.com/'; }
function getVersion() { return '0.1'; }
function getEventList() { return array('PreSkinParse', 'PostSkinParse'); }
function getDescription() { return 'Core Benchmark'; }
function supportsFeature($w) { return ($w == 'SqlTablePrefix') ? 1 : 0; }
function init() {
global $benchmark_start, $member;
$this->buf_bench = "";
$this->time_start = $this->_getTime($benchmark_start);
$this->time_pass = 0;
$this->time_check = ($member->isloggedin() && $member->isAdmin());
}
function event_PreSkinParse(&$data) {
if (!$this->time_check) return;
$this->_setBuf("PreSkinParse:");
}
function event_PostSkinParse(&$data) {
if (!$this->time_check) return;
$this->_setBuf("PostSkinParse:");
ACTIONLOG::add(INFO, $this->buf_bench ." =>" .serverVar('REQUEST_URI'));
}
function _setBuf($buf) {
$time_now = $this->_getTime(microtime());
$time_ttl = $time_now - $this->time_start;
if (!empty($this->time_pass)) {
$buf_time = number_format($time_now - $this->time_pass, 4) ." ( " .number_format((($time_now - $this->time_pass) * 100) / $time_ttl,2) ."% ) / ";
} else {
$buf_time = "";
}
$buf_time .= number_format($time_ttl,4);
$this->buf_bench .= $buf .'['. $buf_time .'sec.] ';
$this->time_pass = $time_now;
}
function _getTime($t) {
list($usec, $sec) = explode(" ", $t);
return ((float)$usec + (float)$sec);
}
}
?>
