PostgreSQL壓測工具sqlbench

sqlbench是阿里雲數據庫內核團隊的mark wong大大開源的一款TPC-C測試軟件,完全遵循TPC-C標準編寫,關鍵它是純C的,效率非常高,並且在遵循TPC-C的標準同時對請求模型進行優化。
https://github.com/swida/sqlbench

環境介紹:

RHEL 7.5
PG 11.5

環境準備:

PG數據庫初始化完成(Port:5435),創建壓測用戶(sqlbench)、數據庫(sqlbench)。

[postgres@rhel75 ~]$createuser -s sqlbench
[postgres@rhel75 ~]$createdb sqlbench


sqlbench安裝,通過git進行安裝,需要連接外網,可下載後上傳的服務器進行解壓:
--提前安裝相關軟件
[root@rhel75 ~]# yum -y install automake.noarch autoconf-2.69-11.el7.noarch

[root@rhel75 soft]# git clone https://github.com/swida/sqlbench  
Cloning into 'sqlbench'...
remote: Enumerating objects: 62, done.
remote: Counting objects: 100% (62/62), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 916 (delta 23), reused 45 (delta 22), pack-reused 854
Receiving objects: 100% (916/916), 414.13 KiB | 9.00 KiB/s, done.
Resolving deltas: 100% (567/567), done. 

[root@rhel75 sqlbench]# autoreconf -if
configure.ac:13: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
src/core/Makefile.am: installing './depcomp'

查看支持的配置選項,如--with-postgresql=yes會導致Command pg_config not found問題
[root@rhel75 sqlbench]# ./configure --help
[root@rhel75 sqlbench]# ./configure --with-postgresql=/usr/local/pgsql
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
......
config.status: creating config.h
config.status: executing depfiles commands

make && make install
注:如不執行make install,可以進入以下路徑執行,本次實驗環境通過make install進行測試
[postgres@rhel75 core]$pwd
/soft/sqlbench/src/core

sqlbench支持命令參數
[postgres@rhel75 ~]$sqlbench --help
usage: sqlbench -t <dbms> -c # -w # -l # [-r #] [-s #] [-e #] [-o p] [-z]
-t <dbms>
        available: postgresql
        for postgresql: --dbname=<dbname> --host=<host> --port=<port> --user=<user>
-c #
        number of database connections
-w #
        warehouse cardinality, default 1
-l #
        the duration of the run in seconds

-r #
        the duration of ramp up in seconds
-s #
        lower warehouse id, default 1
-e #
        upper warehouse id, default <w>
-o p
        output directory of log files, default current directory
-z
        perform database integrity check
......
--sqlapi
        run test using sql interface, available:
        simple      default, just send sql statement to database
        extended    use extended (prepare/bind/execute) protocol, better than simple
        storeproc   use store procedure

初始化測試數據
/soft/sqlbench/src/scripts/pgsql
--配置數據庫及路徑
[postgres@rhel75 pgsql]$export DBT2DBNAME=sqlbench
[postgres@rhel75 pgsql]$export DBT2TSDIR=/postgres/data5435
[postgres@rhel75 pgsql]$sh create-tables 
[postgres@rhel75 pgsql]$datagen -t postgresql --dbname=sqlbench --user=sqlbench -w 10 -j 4
[postgres@rhel75 pgsql]$sh create-indexes 
分析表
psql -U sqlbench -d sqlbench <<EOF
VACUUM analyze customer;  
VACUUM analyze district;  
vacuum analyze history;  
vacuum analyze item;  
vacuum analyze new_order;  
vacuum analyze order_line;  
vacuum analyze orders;  
vacuum analyze stock;  
vacuum analyze warehouse;  
checkpoint;  
EOF
--配置日誌地址
[postgres@rhel75 pgsql]$export OUTPUT_DIR=~/


sqlbench=# \d
           List of relations
 Schema |    Name    | Type  |  Owner   
--------+------------+-------+----------
 public | customer   | table | postgres
 public | district   | table | postgres
 public | history    | table | postgres
 public | item       | table | postgres
 public | new_order  | table | postgres
 public | order_line | table | postgres
 public | orders     | table | postgres
 public | stock      | table | postgres
 public | warehouse  | table | postgres
(9 rows)

sqlbench=# \di
                   List of relations
 Schema |     Name      | Type  |  Owner   |   Table    
--------+---------------+-------+----------+------------
 public | i_customer    | index | postgres | customer
 public | i_orders      | index | postgres | orders
 public | pk_customer   | index | postgres | customer
 public | pk_district   | index | postgres | district
 public | pk_item       | index | postgres | item
 public | pk_new_order  | index | postgres | new_order
 public | pk_order_line | index | postgres | order_line
 public | pk_orders     | index | postgres | orders
 public | pk_stock      | index | postgres | stock
 public | pk_warehouse  | index | postgres | warehouse
(10 rows)

sqlbench=# select pg_database_size('sqlbench')/1024/1024||'mb';
 ?column? 
----------
 1022mb
(1 row)


壓測:
[postgres@rhel75 ~]$sqlbench -t postgresql --dbname=sqlbench --user=sqlbench --no-thinktime -w10 --sleep 10 -c10 -l120 -r5 --sqlapi extended  
use extended sql interface
Output directory of log files: current directory

database connection:
connections = 10
.....
opening 10 connection(s) to database...
10 DB worker threads have started
driver is starting to ramp up at time 2019-10-30 13:53:02
driver will ramp up in 5 seconds
will stop test at time 2019-10-30 13:55:07
terminals started...
steady status started...
driver is exiting normally

[postgres@rhel75 ~]$post_process -l mix.log 
                         Response Time (s)
 Transaction      %    Average :    90th %        Total        Rollbacks      %
------------  -----  ---------------------  -----------  ---------------  -----
    Delivery   3.93      0.136 :     0.152         1759                0   0.00
   New Order  45.13      0.035 :     0.049        20203             1088   5.39
Order Status   4.05      0.005 :     0.007         1815                0   0.00
     Payment  42.90      0.011 :     0.018        19203                0   0.00
 Stock Level   3.99      0.013 :     0.021         1785                0   0.00
------------  -----  ---------------------  -----------  ---------------  -----

10101.50 new-order transactions per minute (NOTPM)
2.0 minute duration
0 total unknown errors
5 second(s) ramping up

參考文檔:https://github.com/digoal/blog/blob/master/201805/20180530_01.md

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章