MySQL壓測神器HammerDB的部署及使用詳解

前言

HammerDB 是一個開源的數據庫負載測試和基準測試工具,同時支持 Windows 和 Linux 平臺。

⛳️ 1. HammerDB簡介

HammerDB 是一個開源的數據庫負載測試和基準測試工具,同時支持 Windows 和 Linux 平臺,可以針對 Oracle 、SQL Server、DB2、TimesTen、 MySQL、MariaDB、
PostgreSQL、Postgres Plus Advanced Server、Greenplum、Redis、Amazon Aurora、Redshift 等進行壓力測試。
它主要模擬兩種不同的測試模型:TPC-C 測試模型和 TPC-H 測試模型。相比於標準的 TPC-C 和 TPC-H,HammerDB 運行成本低,操作簡單, 是服務器數據庫壓力測試
的很好選擇。
• HammerDB 通過模擬 批發商的貨物管理環境,實現瞭 TPC-C 測試模型,即在線事務處理(OLTP)的基準測試模型。測試結果由 TPC-C 吞吐率衡量,標準測試模型中
的單位是 tpmC(在 在 B HammerDB 是 中,測試結果的單位是 tpm,不是 tpmC。m tpm 表示每分鐘的事務交易數量,tpmC 是 TPC-C 的事務交易單位)。
• HammerDB 通過模擬供應商和采購商之間的交易行為,實現瞭 TPC-H 測試模型,即在線分析處理(OLAP)的基準測試模型。測試結果由 TPCH Power 來衡量,該值
與數據量和交易平均時間有關,表示一小時內能夠完成的復雜交易的數量。
關於 TPC-C 和 TPC-H 的詳細介紹請參考 TPC 官方網站(http://www.tpc.org/)

⛳️ 2. 容器部署

✨ 2.1 鏡像下載

docker pull techerwang/oracle:centos76

✨ 2.2 創建容器

docker rm -f jemhammerdb

docker run -d --name jemhammerdb -h jemhammerdb \
-p 34389:3389 -p 42222:22 \
techerwang/oracle:centos76 init

docker exec -it jemhammerdb bash

✨ 2.3 Linux 下安裝

wget https://github.com/TPC-Council/HammerDB/releases/download/v4.0/HammerDB-4.0-Linux.tar.gz

[root@jeames ~]# tar -zxvf HammerDB-4.0-Linux.tar.gz -C /usr/local/
[root@jeames ~]# cd /usr/local/HammerDB-4.0
[root@jeames HammerDB-4.0]# ./hammerdbcli
HammerDB CLI v4.0
Copyright (C) 2003-2020 Steve Shaw
Type "help" for a list of commands
The xml is well-formed, applying configuration
hammerdb>

hammerdb>help
HammerDB v4.0 CLI Help Index

Type "help command" for more details on specific commands below

        buildschema
        clearscript
        customscript
        datagenrun
        dbset
        dgset
        diset 
        distributescript
        librarycheck
        loadscript
        print 
        quit
        runtimer
        switchmode
        vucomplete
        vucreate
        vudestroy
        vurun
        vuset
        vustatus 
        waittocomplete

✨ 2.4 相關校驗

hammerdb>librarycheck
Checking database library for Oracle
Error: failed to load Oratcl - can't read "env(ORACLE_HOME)": no such variable
Ensure that Oracle client libraries are installed and the location in the LD_LIBRARY_PATH environment variable
Checking database library for MSSQLServer
Error: failed to load tdbc::odbc - couldn't load file "libiodbc.so": libiodbc.so: cannot open shared object file: No such file or directory
Ensure that MSSQLServer client libraries are installed and the location in the LD_LIBRARY_PATH environment variable
Checking database library for Db2
Error: failed to load db2tcl - couldn't load file "/usr/local/HammerDB-4.0/lib/db2tcl2.0.0/libdb2tcl.so.0.0.1": libdb2.so.1: cannot open shared object file: No such file or directory
Ensure that Db2 client libraries are installed and the location in the LD_LIBRARY_PATH environment variable
Checking database library for MySQL
Success ... loaded library mysqltcl for MySQL
Checking database library for PostgreSQL
Error: failed to load Pgtcl - couldn't load file "/usr/local/HammerDB-4.0/lib/pgtcl2.1.1/libpgtcl2.1.1.so": libpq.so.5: cannot open shared object file: No such file or directory
Ensure that PostgreSQL client libraries are installed and the location in the LD_LIBRARY_PATH environment variable

⛳️3 . HammerDB壓測MySQL

1.如果是Windows直接點擊hammerdb.bat,如果是Linux需要調用圖形化界面
2.windows平臺壓測,非常耗CPU

## 調用圖形化界面
export DISPLAY=192.168.1.1:0.0
echo $DISPLAY

[root@jeames ~]# cd /usr/local/HammerDB-4.0
[root@jemhammerdb HammerDB-4.0]# ./hammerdb

註:生產環境壓測,建議倉庫數不少於100

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mes_db             |
| mysql              |
| performance_schema |
| sbtest             |
| sys                |
| tpcc               |
+--------------------+
7 rows in set (0.00 sec)

mysql> use tpcc
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_tpcc |
+----------------+
| customer       |
| district       |
| history        |
| item           |
| new_order      |
| order_line     |
| orders         |
| stock          |
| warehouse      |
+----------------+
9 rows in set (0.00 sec)

select a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME,
sum(table_rows) as '記錄數',
sum(truncate(data_length/1024/1024, 2)) as '數據容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)',
sum(truncate((data_length+index_length)/1024/1024, 2)) as '總大小(MB)',
sum(truncate(max_data_length/1024/1024, 2)) as '最大值(MB)',
sum(truncate(data_free/1024/1024, 2)) as '空閑空間(MB)'
from INFORMATION_SCHEMA.SCHEMATA a
left outer join information_schema.tables b
on a.SCHEMA_NAME=b.TABLE_SCHEMA
group by a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME
order by sum(data_length) desc, sum(index_length) desc;

mysql> show processlist;

到此這篇關於MySQL壓測神器HammerDB的部署及使用的文章就介紹到這瞭,更多相關mysql  壓測神器HammerDB內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: