隨着達夢數據庫越來越流行,數據庫性能測試成為日常DBA或運維人員必備技能知識,常見的性能測試工具有jemeter、loadrunner、tpcc、tpc-h等軟件。常見的測試軟件中tpcc工具相對大眾化,適合用戶快速正確確定數據庫性能好壞的一個工具。
TPC-C是專門針對聯機交易處理系統(OLTP系統)的規范。TPC-C測試的結果主要有兩個指標,即流量指標(Throughput,簡稱tpmC)和性價比(Price/Performance,簡稱Price/tpmC)。
流量指標(Throughput,簡稱tpmC):按照TPC組織的定義,流量指標描述了系統在執行支付操作、訂單狀態查詢、發貨和庫存狀態查詢這4種交易的同時,每分鍾可以處理多少個新訂單交易。所有交易的響應時間必須滿足TPC-C測試規范的要求,且各種交易數量所占的比例也應該滿足TPC-C測試規范的要求。在這種情況下,流量指標值越大說明系統的聯機事務處理能力越高。
性價比(Price/Performance,簡稱Price/tpmc):即測試系統的整體價格與流量指標的比值,在獲得相同的tpmC值的情況下,價格越低越好。
本文通過實際用例介紹達夢數據的tpcc測試,旨在介紹達夢數據tpcc測試的方法和注意事項。
測試工具;bms5
達夢數據庫版本:dm8
測試操作系統:centos7.4
數據服務器內存;4g
Cpu: 4核
1初始化實例
1)准備初始化數據庫實例,最好選取SSD作為實例路徑,本例虛擬機所有磁盤都是SSD
./dminit path=/opt/ssd
2)啟動數據庫實例;
./dmserver /opt/ssd/DAMENG/dm.ini
2創建tpcc測試需要的數據庫對象
1) 創建表空間和用戶,注意由於此處虛擬機配置較低所以表空間大小此處設置的相對較小,需要根據實際環境進行相應的增加表空間大小和數據文件,因為數據庫表空間自動擴展的時候會消耗資源,需要提前分配好空間,避免自動擴展時候影響性能。
CREATE TABLESPACE BENCHMARKSQL_DATA DATAFILE 'BENCHMARKSQL_DATA01.dbf' SIZE 1024;
ALTER TABLESPACE BENCHMARKSQL_DATA ADD DATAFILE 'BENCHMARKSQL_DATA02.dbf' SIZE 1024;
ALTER TABLESPACE BENCHMARKSQL_DATA ADD DATAFILE 'BENCHMARKSQL_DATA03.dbf' SIZE 1024;
CREATE TABLESPACE BENCHMARKSQL_IDX DATAFILE 'BENCHMARKSQL_IDX01.dbf' SIZE 1024;
ALTER TABLESPACE BENCHMARKSQL_IDX ADD DATAFILE 'BENCHMARKSQL_IDX02.dbf' SIZE 1024;
ALTER TABLESPACE BENCHMARKSQL_IDX ADD DATAFILE 'BENCHMARKSQL_IDX03.dbf' SIZE 1024;
CREATE USER "BENCHMARKSQL" IDENTIFIED BY "123456789" DEFAULT TABLESPACE "BENCHMARKSQL_DATA" default index tablespace "BENCHMARKSQL_IDX";
GRANT DBA TO BENCHMARKSQL;
1) 創建表,對於達夢數據庫來說分區分區表需要根據達夢數據庫自生來進行修改,可以用普通表,也可以用分區表。
create table bmsql_config (
cfg_name varchar(30) primary key,
cfg_value varchar(50)
);
create table bmsql_warehouse (
w_id integer not null,
w_ytd decimal(12,2),
w_tax decimal(4,4),
w_name varchar(10),
w_street_1 varchar(20),
w_street_2 varchar(20),
w_city varchar(20),
w_state char(2),
w_zip char(9)
);
create table bmsql_district (
d_w_id integer not null,
d_id integer not null,
d_ytd decimal(12,2),
d_tax decimal(4,4),
d_next_o_id integer,
d_name varchar(10),
d_street_1 varchar(20),
d_street_2 varchar(20),
d_city varchar(20),
d_state char(2),
d_zip char(9)
);
create table bmsql_customer (
c_w_id integer not null,
c_d_id integer not null,
c_id integer not null,
c_discount decimal(4,4),
c_credit char(2),
c_last varchar(16),
c_first varchar(16),
c_credit_lim decimal(12,2),
c_balance decimal(12,2),
c_ytd_payment decimal(12,2),
c_payment_cnt integer,
c_delivery_cnt integer,
c_street_1 varchar(20),
c_street_2 varchar(20),
c_city varchar(20),
c_state char(2),
c_zip char(9),
c_phone char(16),
c_since timestamp,
c_middle char(2),
c_data varchar(500)
);
create sequence bmsql_hist_id_seq;
create table bmsql_history (
hist_id integer,
h_c_id integer,
h_c_d_id integer,
h_c_w_id integer,
h_d_id integer,
h_w_id integer,
h_date timestamp,
h_amount decimal(6,2),
h_data varchar(24)
);
create table bmsql_new_order (
no_w_id integer not null,
no_d_id integer not null,
no_o_id integer not null
);
create table bmsql_oorder (
o_w_id integer not null,
o_d_id integer not null,
o_id integer not null,
o_c_id integer,
o_carrier_id integer,
o_ol_cnt integer,
o_all_local integer,
o_entry_d timestamp
);
create table bmsql_order_line (
ol_w_id integer not null,
ol_d_id integer not null,
ol_o_id integer not null,
ol_number integer not null,
ol_i_id integer not null,
ol_delivery_d timestamp,
ol_amount decimal(6,2),
ol_supply_w_id integer,
ol_quantity integer,
ol_dist_info char(24)
);
create table bmsql_item (
i_id integer not null,
i_name varchar(24),
i_price decimal(5,2),
i_data varchar(50),
i_im_id integer
);
create table bmsql_stock (
s_w_id integer not null,
s_i_id integer not null,
s_quantity integer,
s_ytd integer,
s_order_cnt integer,
s_remote_cnt integer,
s_data varchar(50),
s_dist_01 char(24),
s_dist_02 char(24),
s_dist_03 char(24),
s_dist_04 char(24),
s_dist_05 char(24),
s_dist_06 char(24),
s_dist_07 char(24),
s_dist_08 char(24),
s_dist_09 char(24),
s_dist_10 char(24)
);
commit;
3裝載測試數據
一般標准的tpcc測試要求基准數據是100倉,但是由於我虛擬機配置相對底,所以以10倉的數據來模擬,實際情況讀者可以根據用戶要求進行基准數據裝載。
1)上傳bms5測試工具並完成解壓
2) 修改bms5配置連接數據庫,此處需要修改數據庫連接地址,用戶,裝載基准數據倉數,加載線程數,運行窗口數等。
3)拷貝數據庫驅動到bms5工具的lib下,驅動選擇一般是根據jdk環境進行選擇,如虛擬機jdk環境是1.8就需要拷貝達夢數據庫1.8的JDK驅動。
4)加載基准數據,裝載10個倉數據
cd /root/bms5/run/
./runLoader.sh props.dm numWarehouses 10
4優化數據庫
1) 創建序列和索引(此處用的達夢管理用具執行方便觀察結果)
create index ndx_customer_name on benchmarksql.bmsql_customer (c_w_id, c_d_id, c_last, c_first);
create or replace procedure benchmarksql.createsequence
as
n int;
stmt1 varchar(200);
begin
select count(*)+1 into n from benchmarksql.bmsql_history;
if(n != 1) then
select max(hist_id) + 1 into n from benchmarksql.bmsql_history;
end if;
PRINT n;
stmt1:='create sequence benchmarksql.bmsql_hist_id_seq start with '||n||' MAXVALUE 9223372036854775807 CACHE 50000;';
EXECUTE IMMEDIATE stmt1;
end;
/
call benchmarksql.createsequence;
alter table benchmarksql.bmsql_history modify hist_id integer default (benchmarksql.bmsql_hist_id_seq.nextval);
2) 優化數據庫參數
注意此處參是按照本虛擬機配置進行配置的,實際在服務器資源比較充足的情況下應該調大部分參數。
SP_SET_PARA_VALUE (2,'MAX_OS_MEMORY',10);
SP_SET_PARA_VALUE (2,'MEMORY_POOL',30);
SP_SET_PARA_VALUE (2,'BUFFER',2500);
SP_SET_PARA_VALUE (2,'BUFFER_POOLS',97);
SP_SET_PARA_VALUE (2,'FAST_POOL_PAGES',100);
SP_SET_PARA_VALUE (2,'FAST_ROLL_PAGES',800);
SP_SET_PARA_VALUE (2,'RECYCLE',2);
SP_SET_PARA_VALUE (2,'MULTI_PAGE_GET_NUM',1);
SP_SET_PARA_VALUE (2,'WORKER_THREADS',4);
SP_SET_PARA_VALUE (2,'CKPT_RLOG_SIZE',0);
SP_SET_PARA_VALUE (2,'CKPT_DIRTY_PAGES',0);
SP_SET_PARA_VALUE (2,'FORCE_FLUSH_PAGES',0);
SP_SET_PARA_VALUE (2,'DIRECT_IO',0);
SP_SET_PARA_VALUE (2,'IO_THR_GROUPS',4);
SP_SET_PARA_VALUE (2,'BDTA_SIZE',16);
SP_SET_PARA_VALUE (2,'FAST_COMMIT',99);
SP_SET_PARA_VALUE (2,'ENABLE_IN_VALUE_LIST_OPT',1);
SP_SET_PARA_VALUE (2,'ENABLE_SPACELIMIT_CHECK',0);
SP_SET_PARA_VALUE (2,'RLOG_PARALLEL_ENABLE',1);
SP_SET_PARA_VALUE (2,'SESS_CHECK_INTERVAL',30);
SP_SET_PARA_VALUE (2,'FAST_RELEASE_SLOCK',0);
SP_SET_PARA_VALUE (2,'NOWAIT_WHEN_UNIQUE_CONFLICT',1);
SP_SET_PARA_VALUE (2,'UNDO_EXTENT_NUM',32);
SP_SET_PARA_DOUBLE_VALUE (2,'UNDO_RETENTION',0.08);
SP_SET_PARA_VALUE (2,'MAX_SESSIONS',1000);
SP_SET_PARA_VALUE (2,'MAX_CONCURRENT_TRX',0);
SP_SET_PARA_VALUE (2,'MAX_SESSION_STATEMENT',20000);
SF_SET_SYSTEM_PARA_VALUE('SUBQ_EXP_CVT_FLAG', 0, 0, 1);
SF_SET_SYSTEM_PARA_VALUE('PURGE_DEL_OPT', 1, 0, 1);
SP_SET_PARA_VALUE (2,'ENABLE_FREQROOTS',0);
SP_SET_PARA_VALUE (2,'CACHE_POOL_SIZE',200);
SP_SET_PARA_VALUE (2,'DICT_BUF_SIZE',100);
SP_SET_PARA_VALUE (2,'RLOG_CHECK_SPACE',0);
SP_SET_PARA_VALUE (2,'CKPT_INTERVAL',3600);
SP_SET_PARA_VALUE (2,'BATCH_PARAM_OPT',0);
SP_SET_PARA_VALUE (2,'VM_MEM_HEAP',1);
SP_SET_PARA_VALUE (2,'COMM_VALIDATE',0);
SP_SET_PARA_VALUE (2,'DECIMAL_FIX_STORAGE',1);
SP_SET_PARA_VALUE(2, 'PARALLEL_PURGE_FLAG', 1);
SP_SET_PARA_VALUE(2, 'ENABLE_HASH_JOIN', 0);
修改數據庫靜態參數,並重啟數據庫服務。這幾次組參數對測試結果也有影響
CKPT_FLUSH_PAGES = 0
ENABLE_MONITOR = 0
RS_PRE_FETCH=0
FAST_RW_LOCK=2
3) 優化數據庫日志文件
alter tablespace "ROLL" resize datafile 'ROLL.DBF' to 1000;
alter database resize logfile 'DAMENG01.log' to 2000;
alter database resize logfile 'DAMENG02.log' to 2000;
5開始測試
1) 預加載數據,避免重復去磁盤上讀取數據
select count(*) from "BENCHMARKSQL"."BMSQL_CUSTOMER" union all
select count(*) from "BENCHMARKSQL"."BMSQL_DISTRICT" union all
select count(*) from "BENCHMARKSQL"."BMSQL_ITEM" union all
select count(*) from "BENCHMARKSQL"."BMSQL_NEW_ORDER" union all
select count(*) from "BENCHMARKSQL"."BMSQL_OORDER" union all
select count(*) from "BENCHMARKSQL"."BMSQL_ORDER_LINE" union all
select count(*) from "BENCHMARKSQL"."BMSQL_STOCK" union all
select count(*) from "BENCHMARKSQL"."BMSQL_WAREHOUSE" union all
select count(*) from "BENCHMARKSQL"."BMSQL_HISTORY" union all
select count("C_PAYMENT_CNT") from "BENCHMARKSQL"."BMSQL_CUSTOMER";
1) 運行測試,此處測試時間是5分鍾
./runBenchmark.sh props.dm
3)記錄測試結果
查看日志記錄結果
6總結
Tpcc測試時一個dba基本的技能知識,希望對您有所幫助。另外如果您想了解更多的達夢數據庫知識
推薦使用達夢的雲適配中心網站了解更多使用內容:http://eco.dameng.com。