1. 测试方案
使用obd部署oceanbase 数据库,集群部署规模为1:1:1,obproxy、obclient以及tpc-c与tpc-h测试工具部署在另一台服务器上, 作为客户端的压力测试服务器,分别进行tpc-c与tpc-h测试。测试集群拓扑示意图如下:
2. 测试环境
2.1. 硬件配置
测试祼金属服务器四台,硬件配置如下:
ip地址 | cpu | 内存 | 硬盘 |
---|---|---|---|
10.30.30.11 | intel(r) xeon(r) cpu e5-2640 v4 @ 2.40ghz 40核 | 256gb | 480gb ssd 7*4tb sata raid5 |
10.30.30.12 | 256gb | ||
10.30.30.13 | 256gb | ||
10.30.10.27 | 128gb | ||
10.30.30.11, 10.30.30.12, 10.30.30.13服务器用于安装observer
10.30.10.27服务器用于安装obproxy、obclient以及tpc-c与tpc-h测试工具
2.2. 软件环境
安装主要软件及其版本如下:
软件名称 | 软件用途 | 版本 |
---|---|---|
centos | 服务器操作系统 | 7.6.1810 |
oceanbase数据库开源版 | 用于压测的oceanbase数据库 | 3.1.1 |
obclient | oceanbase客户端,用于连接oceanbase数据库 | 3.1.1 |
gcc | 用于编译构建修改后的tpc-h tools源代码 | 4.8.5 20150623 |
jdk | java开发与运行环境 | 1.8.0_202 |
jdbc | mysql-connector-java.jar,用于java连接oceanbase | 5.1.47 |
ant | 用于编译构建修改后的benchmark sql源代码 | 1.10.6 |
python | python开发与运行环境 | 2.7.5 |
benchmark sql | 用于执行tpc-c测试的工具 | 5.0 |
tpc-h tools | 用于执行tpc-h测试的工具 | 3.0.0 |
2.3. centos内核参数优化
- 进程打开文件参数优化
- 网络参数优化
2.4. oceanbase安装配置
distribute.yml完整配置如下:
user:
username: admin
key_file: /home/admin/.ssh/id_rsa
port: 48539
oceanbase-ce:
servers:
- name: server1
ip: 10.30.30.11
- name: server2
ip: 10.30.30.12
- name: server3
ip: 10.30.30.13
global:
devname: eth3
memory_limit: 128g
system_memory: 30g
datafile_disk_percentage: 20
syslog_level: info
enable_syslog_wf: false
enable_syslog_recycle: true
max_syslog_file_count: 4
skip_proxy_sys_private_check: true
server1:
mysql_port: 2881
rpc_port: 2882
home_path: /opt/oceanbase_data/admin
data_dir: /opt/oceanbase_data/data
redo_dir: /opt/oceanbase_data/repo
zone: zone1
server2:
mysql_port: 2881
rpc_port: 2882
home_path: /opt/oceanbase_data/admin
data_dir: /opt/oceanbase_data/data
redo_dir: /opt/oceanbase_data/repo
zone: zone2
server3:
mysql_port: 2881
rpc_port: 2882
home_path: /opt/oceanbase_data/admin
data_dir: /opt/oceanbase_data/data
redo_dir: /opt/oceanbase_data/repo
zone: zone3
obproxy:
depends:
- oceanbase-ce
servers:
- 10.30.10.27
global:
listen_port: 2883
prometheus_listen_port: 2884
home_path: /home/admin/oceanbase/proxy/
enable_cluster_checkout: false
skip_proxy_sys_private_check: true
3. 测试方法
3.1. tpc-c测试方法
3.1.1. 测试准备
- 先安装jdk、ant、benchmark sql、oceanbase数据库与obclient,安装方法与步骤按照官方文档执行。
- 修改benchmarksql5部分源码,修改及编译构建方法按照官方文档执行。
- 创建租户tpcc_tenant用于测试,并分配租户资源,使用root@sys用户登录并执行sql如下:
create resource unit tpcc_unit max_cpu 26,
max_memory = '32g',
max_iops 128,
max_disk_size '100g',
max_session_num 64,
min_cpu = 26,
min_memory = '32g',
min_iops = 128;
create resource pool tpcc_pool unit = 'tpcc_unit',
unit_num = 1,
zone_list =('zone1','zone2','zone3');
create tenant tpcc_tenant resource_pool_list =('tpcc_pool'),
charset = utf8mb4,
replica_num = 3,
zone_list('zone1','zone2','zone3'),
primary_zone = random,
locality = 'f@zone1,f@zone2,f@zone3' set ob_compatibility_mode = mysql;
alter tenant tpcc_tenant set variables ob_tcp_invited_nodes = '%';
grant file on *.* to root@tpcc_tenant;
- 对obp、oceanbase系统配置与变量参数进行优化,优化方法按照官方文档执行。由于导数据阶段与执行测试阶段优化参数存在部分冲突,此时暂不优化执行测试阶段的优化参数。
- 修改配置文件prop.oceanbase,配置warehouse数量为100,装载数据并行度loadworkers设置为34,tpc-c压测并行度terminals设置为300,完整配置如下:
db=oceanbase
driver=com.mysql.jdbc.driver
conn=jdbc:mysql://10.30.10.27:2883/tpcc?rewritebatchedstatements=true&allowmultiqueries=true&uselocalsessionstate=true&useunicode=true&characterencoding=utf-8&sockettimeout=30000000
user=root@tpcc_tenant
password=
warehouses=100
loadworkers=34
terminals=300
database=tpcc
runtxnsperterminal=0
runmins=5
limittxnspermin=0
terminalwarehousefixed=true
neworderweight=45
paymentweight=43
orderstatusweight=4
deliveryweight=4
stocklevelweight=4
resultdirectory=my_result_%ty-%tm-%td_%th%tm%ts
oscollectorscript=./misc/os_collector_linux.py
oscollectorinterval=1
6 生成并装载tpc-c测试数据到oceanbase数据库,数据装载完成后进行数据合并,装载数据与合并方法按照官方文档执行。
7. 测试数据装载完成后各表数据量情况:
表名 | 数据量 |
---|---|
bmsql_customer | 3000000 |
bmsql_district | 1000 |
bmsql_history | 3000000 |
bmsql_item | 100000 |
bmsql_new_orders | 900000 |
bmsql_order_line | 30004561 |
bmsql_orders | 3000000 |
bmsql_stock | 10000000 |
bmsql_warehouse | 100 |
3.1.2. 执行测试
- 按执行测试阶段优化参数对oceanbase系统配置参数进行优化,使用root@sys用户登录并执行sql语句如下,一些系统配置参数修改后需要重启oceanbase集群生效。
##如果导入阶段开启了限速需要关闭
alter system set writing_throttling_trigger_percentage=100 tenant=tpcc_tenant;
alter system set writing_throttling_maximum_duration='1h';
alter system set memstore_limit_percentage = 80;
alter system set freeze_trigger_percentage = 30;
alter system set large_query_threshold = '200s';
alter system set trx_try_wait_lock_timeout = '0ms';
alter system set cpu_quota_concurrency = 4;
alter system set minor_warm_up_duration_time = 0;
alter system set minor_freeze_times=500;
alter system set minor_compact_trigger=3;
alter system set sys_bkgd_io_high_percentage = 90;
alter system set sys_bkgd_io_low_percentage = 70;
alter system set minor_merge_concurrency =20;
alter system set builtin_db_data_verify_cycle = 0;
alter system set trace_log_slow_query_watermark = '10s';
alter system set gts_refresh_interval='500us';
alter system set server_permanent_offline_time='36000s';
alter system set weak_read_version_refresh_interval=0;
alter system set _ob_get_gts_ahead_interval = '5ms';
##为频繁空查的宏块建立bloomfilter并缓存,减少磁盘io和cpu消耗,提升写入性能
alter system set bf_cache_priority = 10;
alter system set user_block_cache_priority=5;
alter system set merge_stat_sampling_ratio = 0;
##close sql audit
alter system set enable_sql_audit=false;
##调整日志级别及保存个数
alter system set syslog_level='perf';
alter system set max_syslog_file_count=100;
alter system set enable_syslog_recycle='true';
alter system set ob_enable_batched_multi_statement=true tenant=tpcc_tenant;
alter system set _cache_wash_interval = '1m';
alter system set plan_cache_evict_interval = '30s';
alter system set enable_one_phase_commit=false;
alter system set enable_monotonic_weak_read = false;
2 使用./runbenchmark.sh prop.oceanbase命令执行tpc-c测试,等待测试完成,执行日志打印如下:
3.2. tpc-h测试方法
3.2.1. 测试准备
- 先安装gcc、python、tpc-h tools,安装方法与步骤按照官方文档执行,使用tpc-c测试已经创建好的tpcc_tenant测试租户用于tpc-h测试。
- 对oceanbase系统配置与变量参数进行优化,优化方法按照官方文档执行。
- 修改tpc-h tools部分源码,修改及编译构建方法按照官方文档执行。其中db13语句有语法错误,需要修改如下才能正常执行:
select /* parallel(96) */
c_count,
count(*) as custdist
from
(
select
c_custkey,
count(o_orderkey) as c_count #修改点
from
customer left outer join orders on
c_custkey = o_custkey
and o_comment not like '%special%packages%'
group by
c_custkey
) c_orders
group by
c_count
order by
custdist desc,
c_count desc;
- 生成10gb的tpc-h测试数据并装载测试数据到oceanbase数据库,数据装载完成后进行数据合并,装载数据与合并方法按照官方文档执行。load.py修改如下:
#/usr/bin/evn python
#-*- encoding:utf-8 -*-
import os
import sys
import time
import commands
hostname='10.30.30.11'
port='2881'
tenant='tpcc_tenant'
user='root'
password=''
data_path='/data1/tpch10'
db_name='tpch'
#创建表
cmd_str='obclient -h%s -p%s -u%s@%s < create_tpch_mysql_table_part.sql'%(hostname,port,user,tenant)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str='obclient -h%s -p%s -u%s@%s -d%s -e "show tables;" '%(hostname,port,user,tenant,db_name)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/customer.tbl' into table customer fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/lineitem.tbl' into table lineitem fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/nation.tbl' into table nation fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/orders.tbl' into table orders fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -d%s -e "load data /* parallel(80) */ infile '%s/partsupp.tbl' into table partsupp fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/part.tbl' into table part fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/region.tbl' into table region fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
cmd_str=""" obclient -h%s -p%s -u%s@%s -c -d%s -e "load data /* parallel(80) */ infile '%s/supplier.tbl' into table supplier fields terminated by '|';" """ %(hostname,port,user,tenant,db_name,data_path)
result = commands.getstatusoutput(cmd_str)
print result
- 测试数据装载完成后各表数据量情况:
表名 | 数据量 |
---|---|
customer | 1500000 |
lineitem | 59986052 |
nation | 25 |
order | 15000000 |
part | 2000000 |
partsupp | 8000000 |
region | 5 |
supplier | 100000 |
3.2.2. 执行测试
- 在tpc-h tools的dbgen/queries目录下,创建tpch.sh测试脚本,编写内容如下:
#!/bin/bash
tpch_test="obclient -h10.30.10.27 -p2883 -uroot@tpcc_tenant -dtpch -c"
#warmup预热
for i in {1..22}
do
sql1="source db${i}.sql"
echo $sql1| $tpch_test >db${i}.log || ret=1
done
#正式执行
for i in {1..22}
do
starttime=`date %s%n`
echo `date ' [%y-%m-%d %h:%m:%s]'` "begin q${i}"
sql1="source db${i}.sql"
echo $sql1| $tpch_test >db${i}.log || ret=1
stoptime=`date %s%n`
costtime=`echo $stoptime $starttime | awk '{printf "%0.2f\n", ($1 - $2) / 1000000000}'`
echo `date ' [%y-%m-%d %h:%m:%s]'` "end,cost ${costtime}s"
done
- 执行sh tpch.sh命令,该脚本在预热执行期间没有终端日志打印输出,可通过dbgen/queries目录下的db*.log文件是否生成来确定预热执行的进度。正式执行的终端日志打印如下:
[2021-12-15 11:15:55] begin q1
[2021-12-15 11:15:56] end,cost 1.70s
[2021-12-15 11:15:56] begin q2
[2021-12-15 11:15:57] end,cost 0.27s
[2021-12-15 11:15:57] begin q3
[2021-12-15 11:15:58] end,cost 1.52s
[2021-12-15 11:15:58] begin q4
[2021-12-15 11:15:58] end,cost 0.35s
[2021-12-15 11:15:58] begin q5
[2021-12-15 11:16:00] end,cost 1.60s
[2021-12-15 11:16:00] begin q6
[2021-12-15 11:16:01] end,cost 0.83s
[2021-12-15 11:16:01] begin q7
[2021-12-15 11:16:03] end,cost 1.76s
[2021-12-15 11:16:03] begin q8
[2021-12-15 11:16:04] end,cost 1.22s
[2021-12-15 11:16:04] begin q9
[2021-12-15 11:16:07] end,cost 3.30s
[2021-12-15 11:16:07] begin q10
[2021-12-15 11:16:08] end,cost 0.39s
[2021-12-15 11:16:08] begin q11
[2021-12-15 11:16:08] end,cost 0.87s
[2021-12-15 11:16:08] begin q12
[2021-12-15 11:16:09] end,cost 1.04s
[2021-12-15 11:16:09] begin q13
[2021-12-15 11:16:10] end,cost 0.77s
[2021-12-15 11:16:10] begin q14
[2021-12-15 11:16:10] end,cost 0.21s
[2021-12-15 11:16:10] begin q15
[2021-12-15 11:16:11] end,cost 0.55s
[2021-12-15 11:16:11] begin q16
[2021-12-15 11:16:11] end,cost 0.46s
[2021-12-15 11:16:11] begin q17
[2021-12-15 11:16:13] end,cost 1.02s
[2021-12-15 11:16:13] begin q18
[2021-12-15 11:16:14] end,cost 1.10s
[2021-12-15 11:16:14] begin q19
[2021-12-15 11:16:15] end,cost 1.10s
[2021-12-15 11:16:15] begin q20
[2021-12-15 11:16:16] end,cost 1.17s
[2021-12-15 11:16:16] begin q21
[2021-12-15 11:16:18] end,cost 2.22s
[2021-12-15 11:16:18] begin q22
[2021-12-15 11:16:19] end,cost 0.60s
4. 测试结果
4.1. tpc-c测试结果
4.1.1. 并发测试对比
使用ssd硬盘做为oceanbase数据存储,通过修改prop.oceanbase的terminals参数来修改tpc-c的测试并发数,测试结果如下:
并发数 | tpmc total | 事务平均响应时间(ms) | ||||
---|---|---|---|---|---|---|
new_order | payment | order_status | delivery_bg | stock_level | ||
100 | 232859 | 40.4 | 18.1 | 8.7 | 108.2 | 6.4 |
200 | 294535 | 56.6 | 24.4 | 11.5 | 160.0 | 8.7 |
300 | 328866 | 70.1 | 30.9 | 13.4 | 237.4 | 8.6 |
400 | 355739 | 88.8 | 42.6 | 17.2 | 287.9 | 12.0 |
500 | 350429 | 99.3 | 52.8 | 20.2 | 383.4 | 11.8 |
从以上测试数据可以看出,随着测试并发数的增加,由于oceanbase服务器集群资源负荷增大,事务平均响应时间会逐步增加,但总的tpmc会提高;但当测试并发数达到或超过临界点后,oceanbase服务器集群资源超出最大负载,总的tpmc反而会下降。
4.1.2. 硬盘测试对比
分别使用ssd硬盘、sata硬盘做为oceanbase数据存储,100并发测试结果如下:
硬盘类型 | tpmc total | 事务平均响应时间(ms) | ||||
---|---|---|---|---|---|---|
new_order | payment | order_status | delivery_bg | stock_level | ||
ssd | 232859 | 40.4 | 18.1 | 8.7 | 108.2 | 6.4 |
sata | 228226 | 36.7 | 21.1 | 14.9 | 164.2 | 5.7 |
从上表测试数据可以看出,使用ssd硬盘,无论是总的tpmc还是事务的平均响应时间,比起使用sata盘都会有一定的优势,但优势并不是很明显。应该是因为oceanbase使用lsm tree存储架构提高了内存的使用效率,降低了硬盘读写损耗对系统的影响。
4.2. tpc-h测试结果
4.2.1. 预热测试对比
使用ssd硬盘做为oceanbase数据存储,修改tpch.sh脚本,注释掉预热部分代码,在装载数据成功后第一次执行即为非预热执行,第二次执行脚本则为预热后执行,测试结果如下:
执行语句 | 执行时间(s) | |
---|---|---|
没有预热 | 有预热 | |
q1 | 3.72 | 1.70 |
q2 | 0.50 | 0.27 |
q3 | 2.11 | 1.52 |
q4 | 0.51 | 0.35 |
q5 | 1.64 | 1.60 |
q6 | 0.97 | 0.83 |
q7 | 2.21 | 1.76 |
q8 | 1.93 | 1.22 |
q9 | 3.40 | 3.30 |
q10 | 0.47 | 0.39 |
q11 | 0.97 | 0.87 |
q12 | 1.09 | 1.04 |
q13 | 0.80 | 0.77 |
q14 | 0.22 | 0.21 |
q15 | 0.65 | 0.55 |
q16 | 0.46 | 0.46 |
q17 | 1.05 | 1.02 |
q18 | 1.08 | 1.10 |
q19 | 1.15 | 1.10 |
q20 | 1.37 | 1.17 |
q21 | 2.28 | 2.22 |
q22 | 0.56 | 0.60 |
总计 | 29.14 | 24.05 |
从上表测试数据可以看出,预热后tpc-h的测试sql语句执行性能会有一定的提升,是因为sql在解析与执行时命中了执行计划缓存与部分数据缓存所致。
4.2.2. 硬盘测试对比
分别使用ssd硬盘、sata硬盘做为oceanbase数据存储,执行测试结果如下:
执行语句 | 执行时间(s) | |||
---|---|---|---|---|
没有预热 | 有预热 | |||
sata | ssd | sata | ssd | |
q1 | 9.88 | 3.72 | 1.64 | 1.70 |
q2 | 2.88 | 0.50 | 0.48 | 0.27 |
q3 | 4.73 | 2.11 | 1.14 | 1.52 |
q4 | 0.48 | 0.51 | 0.30 | 0.35 |
q5 | 2.52 | 1.64 | 1.60 | 1.60 |
q6 | 0.89 | 0.97 | 0.78 | 0.83 |
q7 | 1.70 | 2.21 | 1.67 | 1.76 |
q8 | 2.57 | 1.93 | 2.15 | 1.22 |
q9 | 4.61 | 3.40 | 4.48 | 3.30 |
q10 | 1.34 | 0.47 | 1.12 | 0.39 |
q11 | 1.05 | 0.97 | 0.84 | 0.87 |
q12 | 1.08 | 1.09 | 1.01 | 1.04 |
q13 | 1.00 | 0.80 | 0.84 | 0.77 |
q14 | 0.62 | 0.22 | 0.24 | 0.21 |
q15 | 1.32 | 0.65 | 0.58 | 0.55 |
q16 | 0.63 | 0.46 | 0.49 | 0.46 |
q17 | 5.05 | 1.05 | 4.01 | 1.02 |
q18 | 1.01 | 1.08 | 1.00 | 1.10 |
q19 | 1.36 | 1.15 | 1.43 | 1.10 |
q20 | 5.76 | 1.37 | 4.75 | 1.17 |
q21 | 2.28 | 2.22 | 3.72 | 1.70 |
q22 | 0.66 | 0.56 | 0.60 | 0.60 |
总计 | 54.87 | 29.14 | 34.77 | 24.05 |
从以上测试数据可以看出,在没有预热的情况下,使用ssd硬盘比使用sata硬盘有较大的性能提升;但在有预热的情况下,使用ssd硬盘比使用sata硬盘的性能提升则不是很明显。应该是因为在预热情况下tpc-h的测试sql语句在执行时命中了部分数据缓存,减少了从硬盘读取数据所带来的损耗。
4.3. 测试小结
- 通过本次对oceanbase开源版v3.1.1三节点集群的压力测试,可以得出以下结论:按照tpc-c标准进行测试,最高可达355739tpmc,最快可以在24.05秒完成整个tpc-h的测试sql执行,说明了oceanbase开源版v3.1.1在oltp与olap场景下都有不俗的表现,并可通过横向扩展满足大部分海量数据高并发业务场景的性能需求。虽然本次测试tpmc比官方网站上公布的性能测试数据要差一些,但可能在服务器硬件配置以及操作系统内核参数优化方面有一定差异,无法直接进行类比。
- 通过ssd硬盘与sata硬盘对比测试发现,在tpc-c测试下提升效果并不明显,而在tpc-h测试下,提升效果会好一些。所以如果以oltp业务为主的话,可以使用sata硬盘来节省成本,在预算充足的情况下,当然还是首选ssd硬盘。