ablog

不器用で落着きのない技術者のメモ

sysbench で MySQL にカスタムクエリを同時多重実行して一時ファイルを大量に使ってみる

インストール

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench mysql

準備

  • 初期データロード
$ sysbench /usr/share/sysbench/oltp_read_write.lua \
 --db-driver=mysql \
 --table-size=100000 \
 --mysql-host=aurora01.*********.ap-northeast-1.rds.amazonaws.com \
 --mysql-user=awsuser \
 --mysql-password=********* \
 --mysql-db=mydb \
 --db-ps-mode=disable \
 prepare
function event(thread_id)
        db_query("select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad")
end

負荷をかける

  • 負荷をかける
$ sysbench /usr/share/sysbench/select_sort.lua \
 --db-driver=mysql \
 --mysql-db=mydb \
 --mysql-host=aurora01.*********.ap-northeast-1.rds.amazonaws.com \
 --mysql-user=awsuser \
 --mysql-password=********* \
 --time=300 \
 --db-ps-mode=disable \
 --threads=30 \
 run
  • 実行結果
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 30
Initializing random number generator from current time


Initializing worker threads...

Threads started!

FATAL: mysql_store_result() returned error 3 (Error writing file '/rdsdbdata/tmp/MYz8AJRr' (Errcode: 28 - No space left on device))
FATAL: `thread_run' function failed: /usr/share/sysbench/select_sort.lua:2: db_query() failed
FATAL: mysql_store_result() returned error 3 (Error writing file '/rdsdbdata/tmp/MY4EuUqw' (Errcode: 28 - No space left on device))
FATAL: `thread_run' function failed: /usr/share/sysbench/select_sort.lua:2: db_query() failed
(中略)
FATAL: mysql_store_result() returned error 3 (Error writing file '/rdsdbdata/tmp/MYoI30Js' (Errcode: 28 - No space left on device))
FATAL: `thread_run' function failed: /usr/share/sysbench/select_sort.lua:2: db_query() failed
FATAL: mysql_store_result() returned error 3 (Error writing file '/rdsdbdata/tmp/MYgWJgNX' (Errcode: 28 - No space left on device))

性能統計情報を確認する

  • performance_schema.events_statements_current を確認する
mysql> select thread_id, sql_text, sort_range, sort_rows, sort_scan,created_tmp_disk_tables, created_tmp_tables from performance_schema.events_statements_current where sql_text = 'select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad';
+-----------+-------------------------------------------------------------------------------------------+------------+-----------+-----------+-------------------------+--------------------+
| thread_id | sql_text                                                                                  | sort_range | sort_rows | sort_scan | created_tmp_disk_tables | created_tmp_tables |
+-----------+-------------------------------------------------------------------------------------------+------------+-----------+-----------+-------------------------+--------------------+
|       533 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       534 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       535 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       536 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       537 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       538 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       539 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       540 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       541 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       542 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       543 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       544 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       545 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       546 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       547 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       548 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       549 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       550 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       551 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       552 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       553 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       554 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       555 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       556 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       557 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       558 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       559 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       560 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       561 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
|       562 | select c.* from (select a.* from mydb.sbtest1 a cross join sbtest1 b) as c order by c.pad |          0 |         0 |         0 |                       1 |                  1 |
+-----------+-------------------------------------------------------------------------------------------+------------+-----------+-----------+-------------------------+--------------------+
30 rows in set (0.42 sec)