773
技術社區[雲棲]
PostgreSQL 11 preview - pgbench 變量、函數擴展 - 暨pgbench 自定義 benchmark講解
標簽
PostgreSQL , pgbench , 壓測 , 變量 , tpc-b , 自定義壓測
背景
pgbench是PostgreSQL軟件包中的一款benchmark軟件,純C編碼,效率高,壓測方便。
內置TPC-B benchmark測試,同時支持自定義benchmark。
詳細文檔見
https://www.postgresql.org/docs/10/static/pgbench.html
pgbench 自定義benchmark腳本支持的語法
變量賦值的語法
壓測需要生成輸入變量,才能使得壓測覆蓋更廣的數據範圍。
1、pgbench 命令行輸入變量
-D varname=value
--define=varname=value
Define a variable for use by a custom script (see below). Multiple -D options are allowed.
2、benchmark腳本內變量,表達式的值賦予給變量
\set varname express
3、pgbench 自帶的兩個變量(一個是指client id, 每個連接一個,另一個是scale factor,即pgbench -s 輸入的值。)
表達式語法
1、數據類型
INT,浮點類型
2、支持的操作符
unary operators (+, -)
binary operators (+, -, *, /, %)
括號
3、函數調用
睡眠語法
模擬真實環境,APP處理消耗時間,再次發起請求的間隔。
\sleep number [ us | ms | s ]
shell調用語法1
調用shell並將標準輸出賦予變量,用於在測試過程中調用SHELL命令。
\setshell varname command [ argument ... ]
\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon
shell調用語法2
調用shell並拋棄結果,用於在測試過程中調用SHELL命令。
\shell command [ argument ... ]
\shell command literal_argument :variable ::literal_starting_with_colon
生成隨機值的幾個函數
1、隨機分布隨機數
在取值區間內,所有值的概率一致。
\set varname random(min, max)
\set id random(1,100000)
2、高斯分布隨機數
\set varname random_gaussian(lb, ub, parameter)
在取值區間內,
約67%的值分布在以min,max數學期望為中心的 "1.0 / 參數" 這個區間。
約95%的值分布在以min,max數學期望為中心的 "2.0 / 參數" 這個區間。
參數越大,鈡的曲線越陡峭
參數越小,鈡的曲線越平緩
3、指數分布隨機數
\set varname random_exponential(lb, ub, parameter)
在取值區間內,"1%" 的高頻詞,在最靠近min的區間,出現 "參數%" 次。
參數越大,越趨向生成更小的值(越靠近min,出現概率越高)。
參數越小,越趨向隨機分布。
4、也可以使用shell調用生成隨機數。
1 -----------------------
\setshell varname command [ argument ... ]
Sets variable varname to the result of the shell command command with the given argument(s).
The command must return an integer value through its standard output.
command and each argument can be either a text constant or a :variablename reference to a variable.
If you want to use an argument starting with a colon, write an additional colon at the beginning of argument.
Example:
\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon
2 -----------------------
\shell command [ argument ... ]
Same as \setshell, but the result of the command is discarded.
Example:
\shell command literal_argument :variable ::literal_starting_with_colon
pgbench 例子
tpc-b benchmark 例子
1、初始化測試數據(如已有,可忽略)
-s 100 單位為10萬行,100表示1000萬行數據。
pgbench -i -s 100
2、壓測
32個連接,測試120秒。
pgbench -M prepared -n -r -P 1 -c 32 -j 32 -T 120
自定義 benchmark 例子
1、創建測試腳本
vi test.sql
\set aid random(1, 100000 * :scale)
\set bid random(1, 1 * :scale)
\set tid random(1, 10 * :scale)
\set delta random(-5000, 5000)
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
2、壓測
32個連接,測試120秒。
pgbench -M prepared -n -r -f ./test.sql -P 1 -c 32 -j 32 -T 120
PostgreSQL 11 preview
增加 pow 函數
https://commitfest.postgresql.org/15/1357/
增加 操作符
https://commitfest.postgresql.org/15/985/
Here is a simple patch which adds a bunch of operators :
bitwise: & | ^ ~,
comparisons: =/== <>/!= < <= > >=,
logical: and/&& or/|| xor/^^ not/!
functions (exp ln if)
to pgbench. I've tried to be pg's SQL compatible
where appropriate.
參考
《PostgreSQL 使用 pgbench 測試 sysbench 相關case》
《PostgreSQL pgbench SQL RT 與 事務RT 淺析》
其他例子
《HTAP數據庫 PostgreSQL 場景與性能測試之 43 - (OLTP+OLAP) unlogged table 含索引多表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 42 - (OLTP+OLAP) unlogged table 不含索引多表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 41 - (OLTP+OLAP) 含索引多表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 40 - (OLTP+OLAP) 不含索引多表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 39 - (OLTP+OLAP) 含索引多表單點寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 38 - (OLTP+OLAP) 不含索引多表單點寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 37 - (OLTP+OLAP) 含索引單表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 36 - (OLTP+OLAP) 不含索引單表批量寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 35 - (OLTP+OLAP) 含索引單表單點寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 34 - (OLTP+OLAP) 不含索引單表單點寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 33 - (OLAP) 物聯網 - 線性字段區間實時統計》
《HTAP數據庫 PostgreSQL 場景與性能測試之 32 - (OLTP) 高吞吐數據進出(堆存、行掃、無需索引) - 閱後即焚(JSON + 函數流式計算)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 31 - (OLTP) 高吞吐數據進出(堆存、行掃、無需索引) - 閱後即焚(讀寫大吞吐並測)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 30 - (OLTP) 秒殺 - 高並發單點更新》
《HTAP數據庫 PostgreSQL 場景與性能測試之 29 - (OLTP) 高並發空間位置更新(含空間索引)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 28 - (OLTP) 高並發點更新》
《HTAP數據庫 PostgreSQL 場景與性能測試之 27 - (OLTP) 物聯網 - FEED日誌, 流式處理 與 閱後即焚 (CTE)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 26 - (OLTP) NOT IN、NOT EXISTS 查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 25 - (OLTP) IN , EXISTS 查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 24 - (OLTP) 物聯網 - 時序數據並發寫入(含時序索引BRIN)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 23 - (OLAP) 並行計算》
《HTAP數據庫 PostgreSQL 場景與性能測試之 22 - (OLTP) merge insert|upsert|insert on conflict|合並寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 21 - (OLTP+OLAP) 排序、建索引》
《HTAP數據庫 PostgreSQL 場景與性能測試之 20 - (OLAP) 用戶畫像圈人場景 - 多個字段任意組合條件篩選與透視》
《HTAP數據庫 PostgreSQL 場景與性能測試之 19 - (OLAP) 用戶畫像圈人場景 - 數組相交查詢與聚合》
《HTAP數據庫 PostgreSQL 場景與性能測試之 18 - (OLAP) 用戶畫像圈人場景 - 數組包含查詢與聚合》
《HTAP數據庫 PostgreSQL 場景與性能測試之 17 - (OLTP) 數組相似查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 16 - (OLTP) 文本特征向量 - 相似特征(海明...)查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 15 - (OLTP) 物聯網 - 查詢一個時序區間的數據》
《HTAP數據庫 PostgreSQL 場景與性能測試之 14 - (OLTP) 字符串搜索 - 全文檢索》
《HTAP數據庫 PostgreSQL 場景與性能測試之 13 - (OLTP) 字符串搜索 - 相似查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 12 - (OLTP) 字符串搜索 - 前後模煳查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 11 - (OLTP) 字符串搜索 - 後綴查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 10 - (OLTP) 字符串搜索 - 前綴查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 9 - (OLTP) 字符串模煳查詢 - 含索引實時寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 8 - (OLTP) 多值類型(數組)含索引實時寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 7 - (OLTP) 全文檢索 - 含索引實時寫入》
《HTAP數據庫 PostgreSQL 場景與性能測試之 6 - (OLTP) 空間應用 - KNN查詢(搜索附近對象,由近到遠排序輸出)》
《HTAP數據庫 PostgreSQL 場景與性能測試之 5 - (OLTP) 空間應用 - 空間包含查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 4 - (OLAP) 大表OUTER JOIN統計查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 3 - (OLAP) 大表JOIN統計查詢》
《HTAP數據庫 PostgreSQL 場景與性能測試之 2 - (OLTP) 多表JOIN》
《HTAP數據庫 PostgreSQL 場景與性能測試之 1 - (OLTP) 點查》
最後更新:2017-11-19 15:04:31
上一篇:
Python 入門指南(中文) 3.6 & 2.7 版本
下一篇:
PostgreSQL 11 preview - compress method 接口 - 暨開放接口係列
PostgreSQL 異步消息實踐 - 億級/分鍾 FEED係統實時監測
mybatis動態SQL語句
Nginx學習之負載均衡
賦能生態 變現為王——雲市場生態變現之道
mysql源碼安裝
Android開發12——Andorid中操作數據庫的insert的兩種方法以及nullColumnHack
≪統計學習精要(The Elements of Statistical Learning)≫課堂筆記(二)
Android UI開發第二十七篇——實現左右劃出菜單
[XSS](javascript://sadas/%0aalert`1`)
雲服務器 ECS 配置:ECS之Windows服務器時鍾同步設置