1. 概述
BenchmarkSQL 是一個易於使用的 JDBC 基準測試程序, 它與 OLTP 的TPC-C標準非常相似。它支持的數據庫包括 PostgreSQL/EnterpriseDB、DB2,、Oracle、 SQL Server和 MySQL。
BenchmarkSQL 是開源的, 採用的協議是 GNU 通用公共許可協議版本 2.0 (GPL v2),這意味着它不允許修改後的和衍生的代碼做爲閉源的商業軟件發佈和銷售 。
本文將介紹如何安裝BenchmarkSQL並使用它測量PostgreSQL的性能參數。
2. 實驗環境
硬件環境:
CPU,Intel(R) Xeon(R) 4核以上
內存,8G 以上
操作系統:
Linux,推薦使用CentOS 7.x。
軟件環境:
Java,JDK 7以上版本
PostgreSQL,本文采用 PostgreSQL 10.0。可安裝在另一臺計算機上。
Ant,本文采用ant 1.7.1
EPEL 倉庫,本文采用epel-release-6-8
R語言,本文采用R 3.5.1
以及上述軟件的依賴。
3. 安裝BenchmarkSQL及相關軟件
本文默認Java和PostgreSQL已經安裝成功。若讀者未安裝Java和PostgreSQL,請首先自行安裝,然後閱讀後續內容。
3.1 安裝Ant
執行命令:
yum -y install ant
3.2 安裝EPEL 倉庫
如果你使用的是CentOS 6.x的版本,執行命令:
su -c 'rpm -Uvh https://download.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm'
如果你使用的是CentOS 7.x的版本,執行命令:
su -c 'rpm -Uvh https://download.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
然後更新yum倉庫:
sudo yum -y update
3.3 安裝R 語言
執行命令:
sudo yum -y install R
安裝過程中,若出現如下問題:
下載軟件包時出錯
texinfo-tex-4.13a-8.el6.x86_64: failure: Packages/texinfo-tex-4.13a-8.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
請參考5.1節“下載軟件包失敗”。
3.4 下載並安裝BenchmarkSQL
在下載地址中下載BenchmarkSQL 安裝包。本文下載的文件是benchmarksql-5.0.zip(見附錄)。下載完成後解壓文件:
unzip ./benchmarksql-5.0.zip
4. 用BenchmarkSQL測試PostgreSQL
4.1 創建benchmark用戶和數據庫
在安裝了PostgreSQL的服務器上啓動PostgreSQL並登錄,然後創建名爲benchmarksql的用戶數據庫:
postgres=# CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'changeme';
postgres=# CREATE DATABASE benchmarksql OWNER benchmarksql;
postgres=# \q
這裏,你可以將“changeme” 替換爲自己的數據庫密碼。
4.2 編譯BenchmarkSQL源碼
進入BenchmarkSQL 解壓後的目錄,並使用ant編譯源碼:
[wieck@localhost ~] $ cd benchmarksql
[wieck@localhost benchmarksql] $ ant
4.3 創建配置文件
進入run目錄, 複製props.pg文件並編輯產生的副本,設置與基準測試有關的參數:
[wieck@localhost benchmarksql] $ cd run
[wieck@localhost run] $ cp props.pg my_postgres.properties
[wieck@localhost run] $ vi my_postgres.properties
首次實驗時,首先修改下面的參數:
conn=jdbc:postgresql://localhost:5432/postgres
將其中的 “localhost” 修改爲postgresql所在服務器的ip地址,將“5432”修改爲 postgresql所在的端口,將末尾的 “postgres” 修改爲所測量的數據庫。本次實驗,將其修改爲 conn=jdbc:postgresql://localhost:5432/ benchmarksql
user=benchmarksql
將“benchmarksql”修改爲用來測試的用戶。本次實驗不做修改。
password=PWbmsql
將“PWbmsql”修改爲測試的用戶的密碼。本次實驗將其修改爲“changeme”。
4.4 創建模式和初始化數據庫
執行當前路徑下的shell腳本:
[wieck@localhost run] ./runDatabaseBuild.sh my_postgres.properties
4.5 運行配置的基準測試
執行下面的命令,驗證程序BenchmarkSQL是否能正確運行:
[wieck@localhost run]$ ./runBenchmark.sh my_postgres.properties
基準測試的報告的結尾如下所示:
01:58:09,081 [Thread-1] INFO jTPCC : Term-00,
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Measured tpmC (NewOrders) = 179.55
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Measured tpmTOTAL = 329.17
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Session Start = 2016-05-25 01:58:07
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Session End = 2016-05-25 01:58:09
01:58:09,082 [Thread-1] INFO jTPCC : Term-00, Transaction Count = 10
這表示你成功運行了一次測試。
4.6 修改基準測試的配置參數
進行正式的測試之前,需要修改my_postgres.properties中的參數。
本次實驗中,我們將下面兩個參數修改爲:
runTxnsPerTerminal=0
runMins=120
其中,runTxnsPerTerminal代表測試時,每個終端運行的事務數量。運行的事務數量達到這個值後測試結束;runMins 代表測試的時長,以分鐘爲單位。
當這兩個參數之一的值大於零時,另一個的值必須設置爲0。
4.7 重新運行基準測試。
依次執行下面的命令,重新初始化數據庫,並運行基準測試:
[wieck@localhost run]$ ./runDatabaseDestroy.sh my_postgres.properties
[wieck@localhost run]$ ./runDatabaseBuild.sh my_postgres.properties
[wieck@localhost run]$ ./runBenchmark.sh my_postgres.properties
接下來,BenchmarkSQL會對相應的Postgresql 數據庫進行時長爲120分鐘的性能測試。
4.8 生成報告
測試結束後,run目錄下會生成一個新目錄,它的命名格式爲 my_result_%tY-%tm-%td_%tH%tM%tS。
使用 generateReport.sh my_result_* 腳本創建具有圖形的 HTML 文件:
例如:
./generateReport.sh my_result_2018-09-30_133047
隨後會在my_result_* 目錄下生成一個html文件。
用瀏覽器打開,即可查看報告。如圖所示:
5. 安裝過程中其他問題及解決方法
5.1下載軟件包失敗
問題描述:
使用命令 “sudo yum -y install R” 下載軟件包時報錯:
下載軟件包時出錯
texinfo-tex-4.13a-8.el6.x86_64: failure: Packages/texinfo-tex-4.13a-8.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
libicu-devel-4.2.1-14.el6.x86_64: failure: Packages/libicu-devel-4.2.1-14.el6.x86_64.rpm from base: [Errno 256] No more mirrors to try.
解決方法:
1. 首先,手動在官網上下載缺失的組件:
texinfo-tex-4.13a-8.el6.x86_64
libicu-devel-4.2.1-14.el6.x86_64
2. 下載完成後,使用如下命令安裝:
rpm -ivh texinfo-tex-4.13a-8.el6.x86_64.rpm
rpm -ivh texinfo-tex-4.13a-8.el6.x86_64
3. 重新安裝相關組件:sudo yum -y install R
參考文獻
[1] BenchmarkSQL開發團隊. Instructions for running BenchmarkSQL on PostgreSQL.
[2] Martyn Plummer. R RPMS for Fedora, Red Hat Enterprise Linux and Derivatives. 2014-07-22.
[3] Jason A. French. Installing R in Linux. 2013-05-11