やること
この前、Zabbix: イベント情報の表示を省略させない。でZabbixServer用のhttpdにコンテンツ圧縮モジュール(mod_deflate)を仕込んだが、負荷を把握していなかったので、
今回はmod_deflateを導入することによる負荷影響を調査してみた。
今回の設定(deflate)内容
httpdのコンフィグに、以下設定を入れコンテンツタイプをtext/htmlにのみ圧縮を適用することでZabbixコンテンツのサイズ圧縮を実現している。
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html application/json application/json-rpc text/javascript
</IfModule>
abツール利用
httpリスクエストのレスポンスを計測できればいいので、昔ながらのABツールを使用します。
また、今回性能テストするZabbix画面は、「監視データ」⇒「イベント」としています。
問題点(1)
URLでいうと"http://{ZabbixServer-IP}/zabbix/events.php"になるわけですが、この画面含めZabbixの画面はログインしないと参照できません。
ab -n 1 -c 1 http://192.168.10.84/zabbix/events.php
つまり、上記のように単純に"http://{ZabbixServer-IP}/zabbix/events.php"としても実際の画面を参照させてくれるわけではありません。
問題点(2)
プラスもう一点。
ABツールはブラウザじゃないので、圧縮機能についても指定してあげないとサーバ側で圧縮が有効にならないです。
では、どうするか?
解決(1)セッション情報の指定
ZabbixはセッションIDの情報を付加することで、ログイン状態となり各画面(ここではイベント画面)を参照できるようになります。
セッションID情報は、ZabbixのDBに記載されています。
別のところで、一度ブラウザにZabbixサーバにログインしてください。すると、下記のように、sessionsテーブルのカラム"sessionid"にセッションID情報(2f2eb524...)が生で記載(生成)されます。この値を流用してABツールを動かします。
MariaDB [zabbix]> select * from sessions where userid = 1;
+----------------------------------+--------+------------+--------+
| sessionid | userid | lastaccess | status |
+----------------------------------+--------+------------+--------+
| 2f2eb524db3afff5f9745b09efce4114 | 1 | 1495928633 | 0 |
+----------------------------------+--------+------------+--------+
1 row in set (0.00 sec)
補足(セッション情報の指定)
デフォルト(以下,usersテーブル参照)だと、Adminユーザはuserid=1なので、"where userid = 1"を使用。
MariaDB [zabbix]> select * from users;
+--------+-------+--------+---------------+------------------.........
| userid | alias | name | surname | passwd .........
| 1 | Admin | Zabbix | Administrator | 5fce1b3e34b520afe...... <--- これ
| 2 | guest | | | d41d8cd98f00b204e.........
+--------+-------+--------+---------------+------------------.........
2 rows in set (0.00 sec)
解決(2)圧縮許可の指定
今回は圧縮機能をしようしているため、ヘッダ情報で以下を指定する必要があります。
Accept-Encoding: gzip,deflate
さあ、やってみよう
先ほどのセッションIDと圧縮許可をヘッダ情報(-Hオプション)で付加しコマンド実行する。
[root@sv ~]# ab -n 200 -c 20 -H "Accept-Encoding: gzip,deflate" -H "cookie: zbx_sessionid=2f2eb524db3afff5f9745b09efce4114" http://192.168.10.84/zabbix/events.php
結果
event.phpのコンテンツサイズは 18KB -> 4.3KBに縮小(約23%)。
今回は非力の1coreの仮想サーバで実施。1秒当たりのリクエスト処理数はほぼ同数。
deflateを有効にすることにより、処理能力がほぼ落ちていないことが言えた。
...
Document Path: /zabbix/events.php
Document Length: 17963 bytes
Concurrency Level: 20
Time taken for tests: 22.075 seconds
Complete requests: 200
Failed requests: 191
(Connect: 0, Receive: 0, Length: 191, Exceptions: 0)
Write errors: 0
Total transferred: 3715731 bytes
HTML transferred: 3592931 bytes
Requests per second: 9.06 [#/sec] (mean)
...
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 198 2165 457.2 2168 3481
Waiting: 191 2153 457.4 2155 3477
Total: 198 2165 457.1 2169 3482
...
...
Document Path: /zabbix/events.php
Document Length: 4304 bytes
Concurrency Level: 20
Time taken for tests: 22.224 seconds
Complete requests: 200
Failed requests: 145
(Connect: 0, Receive: 0, Length: 145, Exceptions: 0)
Write errors: 0
Total transferred: 997194 bytes
HTML transferred: 860594 bytes
Requests per second: 9.00 [#/sec] (mean)
...
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 237 2158 479.3 2202 3488
Waiting: 236 2158 479.3 2202 3488
Total: 237 2158 479.3 2202 3488
...
別角度から検証
今度はZabbix(重い)コンテンツ表示ではなく、軽いコンテンツ表示時に、deflateの処理時間が邪魔になるかどうかテストしてみた。
以下の約18Kbytesをランダムで生成するPHPをWEBページに設置し、同様のABテストを実施。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
system( 'cat /dev/urandom | base64 | head -c 18000');
ab -n 200 -c 20 -H "Accept-Encoding: gzip,deflate" http://192.168.10.84/test.php
結果は、
- test.phpのコンテンツサイズは 18KB -> 13.8KBに縮小(約76%)
- 1秒当たりの処理数はほとんど同値
ランダムすぎで圧縮率が違いすぎ(最悪時)でも、CPU負荷はそこまで上がらないと。
よって、mod_deflateは利用OKですね。
Document Length: 18113 bytes
...
Requests per second: 63.07 [#/sec] (mean)
Document Length: 13799 bytes
...
Requests per second: 61.45 [#/sec] (mean)
※一応NW上限には達しておらず、両作業中CPUが100%FULLで稼働していることを確認。