learning_notes

学习笔记

View project on GitHub

压力测试

pgbench

-T 执行时间
-c 客户端数量
-j 线程数
-r 导出每个命令的延迟
-f 执行的文件
-M 执行的模式 simple|extended|prepared
-i 初始化
-F 填充因子 比如:10 数据扩大10倍
-n --no-vacuum 测试运行前不执行vacuum 定制测试时 这个选项是必要的
-s 数据量
-S select_only

使用默认脚本执行

/ $ pgbench -c 4 -j 4 -T 30s -r test
starting vacuum...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 1
query mode: simple
number of clients: 4
number of threads: 4
duration: 30 s
number of transactions actually processed: 32601
latency average = 3.681 ms
tps = 1086.591042 (including connections establishing)
tps = 1086.645617 (excluding connections establishing)
statement latencies in milliseconds:
         0.002  \set aid random(1, 100000 * :scale)
         0.000  \set bid random(1, 1 * :scale)
         0.000  \set tid random(1, 10 * :scale)
         0.000  \set delta random(-5000, 5000)
         0.043  BEGIN;
         0.119  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
         0.075  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
         0.578  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
         1.978  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
         0.081  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
         0.805  END;

常用命令

  1. 初始化数据
    pgbench -i test