TiUPベンチ コンポーネントを使用した TiDB ストレス テスト
データベースのパフォーマンスをテストする場合、多くの場合、データベースのストレス テストが必要になります。これを容易にするために、 TiUP はストレス テストに複数のワークロードを提供するベンチコンポーネントを統合しました。これらのワークロードには、次のコマンドでアクセスできます。
tiup bench tpcc   # Benchmark a database using TPC-C
tiup bench tpch   # Benchmark a database using TPC-H
tiup bench ch     # Benchmark a database using CH-benCHmark
tiup bench ycsb   # Benchmark a database using YCSB
tiup bench rawsql # Benchmark a database using arbitrary SQL files
tpcc 、 tpch 、 ch 、およびrawsql 、次の共通コマンド フラグを共有します。ただし、 ycsbは主に.propertiesファイルによって構成されており、その使用ガイドで説明されています。
  -t, --acThreads int         OLAP client concurrency, only for CH-benCHmark (default to 1)
      --conn-params string    Session variables, such as setting `--conn-params tidb_isolation_read_engines='tiflash'` for TiDB queries and setting `--conn-params sslmode=disable` for PostgreSQL connections
      --count int             Total execution count (0 means infinite count)
  -D, --db string             Database name (default to "test")
  -d, --driver string         Database driver: mysql, postgres (default to "mysql")
      --dropdata              Clean up historical data before preparing
  -H, --host strings          Database host (default to [127.0.0.1])
      --ignore-error          Ignore errors when running workload
      --interval duration     Output interval time (default to 10s)
      --isolation int         Isolation Level (0: Default; 1: ReadUncommitted;
                              2: ReadCommitted; 3: WriteCommitted; 4: RepeatableRead;
                              5: Snapshot; 6: Serializable; 7: Linerizable)
      --max-procs int         runtime.GOMAXPROCS of golang, the limits of how many cores can be used
      --output string         Output style. Valid values can be { plain | table | json } (default to "plain")
  -p, --password string       Database password
  -P, --port ints             Database port (default to [4000])
      --pprof string          Address of pprof endpoint
      --silence               Don't print errors when running workload
  -S, --statusPort int        Database status port (default to 10080)
  -T, --threads int           Thread concurrency (default to 1)
      --time duration         Total execution time (default to 2562047h47m16.854775807s)
  -U, --user string           Database user (default to "root")
- カンマ区切りの値を
--hostと--portに渡すと、クライアント側の負荷分散を有効にすることができます。たとえば、--host 172.16.4.1,172.16.4.2 --port 4000,4001を指定すると、プログラムはラウンドロビン方式で選択された 172.16.4.1:4000、172.16.4.1:4001、172.16.4.2:4000、および 172.16.4.2:4001 に接続します。 --conn-paramsクエリ文字列の形式に従う必要があります。データベースが異なれば、パラメーターも異なる場合があります。例えば:--conn-params tidb_isolation_read_engines='tiflash'、TiDB にTiFlashからの読み取りを強制します。--conn-params sslmode=disable指定すると、PostgreSQL に接続するときに SSL が無効になります。
- CH-benCHmark を実行する場合、 
--ap-host、--ap-port、および--ap-conn-paramsを使用して、OLAP クエリ用のスタンドアロン TiDBサーバーを指定できます。 
次のセクションでは、 TiUPを使用して TPC-C、TPC-H、YCSB テストを実行する方法について説明します。
TiUPを使用して TPC-C テストを実行する
TiUPベンチコンポーネントは、 TPC-C テストを実行するための次のコマンドとフラグをサポートしています。
Available Commands:
  check       Check data consistency for the workload
  cleanup     Cleanup data for the workload
  prepare     Prepare data for the workload
  run         Run workload
Flags:
      --check-all            Run all consistency checks
  -h, --help                 Help for TPC-C
      --partition-type int   Partition type: 1 - HASH, 2 - RANGE, 3 - LIST (HASH-like), 4 - LIST (RANGE-like) (default to 1)
      --parts int            Number of partitions (default to 1)
      --warehouses int       Number of warehouses (default to 10)
試験手順
以下に、TPC-C テストを実行するための簡略化された手順を示します。詳細な手順については、 TiDB で TPC-C テストを実行する方法を参照してください。
ハッシュ経由で 4 つのパーティションを使用して 4 つのウェアハウスを作成します。
tiup bench tpcc --warehouses 4 --parts 4 prepareTPC-C テストを実行します。
tiup bench tpcc --warehouses 4 --time 10m run一貫性を確認します。
tiup bench tpcc --warehouses 4 checkデータをクリーンアップします。
tiup bench tpcc --warehouses 4 cleanup
大規模なデータセットを使用してベンチマークを実行する場合、SQL を介してデータを準備すると時間がかかる可能性があります。その場合は、以下のコマンドでCSV形式のデータを生成し、 TiDB Lightning経由でTiDBにインポートすることができます。
CSV ファイルを生成します。
tiup bench tpcc --warehouses 4 prepare --output-dir data --output-type=csv指定したテーブルの CSV ファイルを生成します。
tiup bench tpcc --warehouses 4 prepare --output-dir data --output-type=csv --tables history,orders
TiUPを使用して TPC-H テストを実行する
TiUPベンチコンポーネントは、 TPC-H テストを実行するための次のコマンドとパラメータをサポートしています。
Available Commands:
  cleanup     Cleanup data for the workload
  prepare     Prepare data for the workload
  run         Run workload
Flags:
      --check            Check output data, only when the scale factor equals 1
  -h, --help             help for tpch
      --queries string   All queries (default "q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20,q21,q22")
      --sf int           scale factor
試験手順
データを準備します:
tiup bench tpch --sf=1 prepare次のコマンドのいずれかを実行して、TPC-H テストを実行します。
結果を確認する場合は、次のコマンドを実行します。
tiup bench tpch --count=22 --sf=1 --check=true run結果を確認しない場合は、次のコマンドを実行します。
tiup bench tpch --count=22 --sf=1 run
データをクリーンアップします。
tiup bench tpch cleanup
TiUPを使用して YCSB テストを実行する
YCSB を介して TiDB と TiKV の両方をストレス テストできます。
ストレステスト TiDB
データを準備します:
tiup bench ycsb load tidb -p tidb.instances="127.0.0.1:4000" -p recordcount=10000YCSB ワークロードを実行します。
# The read-write percent is 95% by default tiup bench ycsb run tidb -p tidb.instances="127.0.0.1:4000" -p operationcount=10000
ストレステスト TiKV
データを準備します:
tiup bench ycsb load tikv -p tikv.pd="127.0.0.1:2379" -p recordcount=10000YCSB ワークロードを実行します。
# The read-write percent is 95% by default tiup bench ycsb run tikv -p tikv.pd="127.0.0.1:2379" -p operationcount=10000
TiUPを使用して RawSQL テストを実行する
SQL ファイルに任意のクエリを記述し、次のようにtiup bench rawsqlを実行してテストに使用できます。
データとクエリを準備します。
-- Prepare data CREATE TABLE t (a int); INSERT INTO t VALUES (1), (2), (3); -- Save your query in a SQL file. For example, you can save the following query in `demo.sql`. SELECT a, sleep(rand()) FROM t WHERE a < 4*rand();RawSQL テストを実行します。
tiup bench rawsql run --count 60 --query-files demo.sql