前編ではAmazon Auroraの紹介をいたしました。
後編となる今回は前編でも紹介したように、本当にMySQLと比べて5倍速いのか?について検証していきたいと思います。
検証環境
- MySQL 5.6.27 db.r3.large
- Amazon Aurora(MySQL 5.6.10a互換)db.r3.large
設定は初期値のままです。
上記のRDSインスタンスにEC2インスタンスからアクセスして、sysbenchを使ってベンチマークを行います。
ベンチマーク準備
EC2インスタンスへsysbenchのインストール
SysbenchはEPELでrpmが用意されていますが、EC2のAmazon Linuxでは使えないのでtarballからインストールします。
# cd /usr/local/src # wget http://downloads.mysql.com/source/sysbench-0.4.12.5.tar.gz # gunzip -c sysbench-0.4.12.5.tar.gz |tar zx # cd sysbench-0.4.12.5
READMEを見るとインストール手順が書かれていますのでそのまま実施しますが、autoconfとlibtoolが必要になるので先にインストールしておきます。
# yum install autoconf libtool # ./autogen.sh # ./configure # make # make install
RDSインスタンスへSysbenchの設定
各RDSインスタンスに接続して、sysbench用のsbtestという名称のデータベースを作成しておきます。
# mysql -u xxxxxx -p -h ndmysql.xxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 31 Server version: 5.6.27-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database sbtest; Query OK, 1 row affected (0.02 sec)
sbtestデータベースの作成が完了したら、EC2インスタンスからRDSインスタンスへSysbench用のデータを流しておきます。
# sysbench --test=oltp --mysql-user=MySQLユーザー名 --mysql-password=パスワード \ --mysql-host=ホスト名 --db-driver=mysql prepare
ベンチマーク実施
準備ができたのでベンチマークを実施します。
ベンチマークは以下のコマンドで走らせることができます。
# sysbench --test=oltp --mysql-user=MySQLユーザー名 --mysql-password=パスワード \ --mysql-host=ホスト名 --db-driver=mysql run
oltpオプションを設定することで、MySQLのトランザクション性能を計測することができます。
MySQLインスタンスのベンチマーク結果
# sysbench --test=oltp --mysql-user=xxxxxxxx --mysql-password=xxxxxxxxxx \
--mysql-host=ndmysql.xxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com --db-driver=mysql run
sysbench 0.4.12.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 1 test tables
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
transactions: 10000 (38.96 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (740.19 per sec.)
other operations: 20000 (77.91 per sec.)
Test execution summary:
total time: 256.6905s
total number of events: 10000
total time taken by event execution: 256.6409
per-request statistics:
min: 22.76ms
avg: 25.66ms
max: 999.84ms
approx. 95 percentile: 27.88ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 256.6409/0.00
Amazon Auroraインスタンスのベンチマーク結果
# sysbench --test=oltp --mysql-user=xxxxxxxx --mysql-password=xxxxxxxxxx \
--mysql-host=ndaurora-cluster.xxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com --db-driver=mysql run
sysbench 0.4.12.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 1 test tables
Threads started!
Done.
OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
transactions: 10000 (18.71 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (355.49 per sec.)
other operations: 20000 (37.42 per sec.)
Test execution summary:
total time: 534.4806s
total number of events: 10000
total time taken by event execution: 534.4277
per-request statistics:
min: 50.21ms
avg: 53.44ms
max: 270.96ms
approx. 95 percentile: 55.49ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 534.4277/0.00
ベンチマーク結果のまとめ
上記の結果だと見づらいので、まとめたものが以下の通り。
| MySQL | Amazon Aurora | |
|---|---|---|
| 秒間トランザクション処理数 | 38.96 | 18.71 |
| ベンチマーク完了時間 | 256.6905s | 534.4806s |
| 1リクエスト平均処理時間 | 25.66ms | 53.44ms |
なんということでしょう。MySQLの方が約2倍速いではないですか!
念のため何度かベンチマークを取り直してみましたが傾向は変わりませんでした。
MySQLの方が2倍速かった理由
意外な結果となった理由を考えてみましたが、正直どれも推測の域を出ないように思います。
- MySQL 5.6.27に対してMySQL 5.6.10a互換のAmazon Auroraには分が悪かった
- sysbenchのオプションが悪かった
- チューニングしないとパフォーマンスが出ない
- そもそもベンチマーク自体がAmazon Auroraに合っていない
まとめ
正直このブログを執筆する段階では「Amazon Auroraの方がこんなに速いんですよ」という結果で終わらせるつもりだったのですが、ベンチマーク結果を見て愕然としました。
今回の結果だけ見ればAmazon Auroraを積極的に採用する理由は見当たらないように思います。
Amazon AuroraだけでなくMaria DBの台頭などで割を食っているイメージのMySQLですが、本家も捨てたもんじゃないということを証明した結果だったようにも感じました。
機会があれば環境等を変えて再挑戦してみたいと思います。



![群馬の法人ITサポートサービス Wide Net[ワイドネット] 群馬の法人ITサポートサービス Wide Net[ワイドネット]](https://www.nedia.ne.jp/wp-content/themes/nedia/images/bnr_bt_widenet03.png)



