BenchmarkSQL的安裝和使用指導書
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編譯原始碼:
[[email protected] ~] $ cd benchmarksql
[[email protected] benchmarksql] $ ant
4.3 建立配置檔案
進入run目錄, 複製props.pg檔案並編輯產生的副本,設定與基準測試有關的引數:
[[email protected] benchmarksql] $ cd run
[[email protected] run] $ cp props.pg my_postgres.properties
[[email protected] 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指令碼:
[[email protected] run] ./runDatabaseBuild.sh my_postgres.properties
4.5 執行配置的基準測試
執行下面的命令,驗證程式BenchmarkSQL是否能正確執行:
[[email protected] 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 重新執行基準測試。
依次執行下面的命令,重新初始化資料庫,並執行基準測試:
[[email protected] run]$ ./runDatabaseDestroy.sh my_postgres.properties
[[email protected] run]$ ./runDatabaseBuild.sh my_postgres.properties
[[email protected] 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