开篇声明,本文不引战,OB 和 PG 都是很好的数据库产品,个人单纯为了简单测一测看看效果。
文章的主要目的是给大家分享一下如何针对 OceanBase 4.0 单机一体化的单机版本进行压测。我今天选用的压测工具是 sysbench。在本文最后,会简单用 sysbench 压测一下 OceanBase 和 PostgreSQL。
1. 什么是 sysbench
sysbench 是一个基于 LuaJIT 的可编写脚本的多线程基准测试工具,可以执行 CPU、内存、线程、IO 和数据库等方面的性能测试,常用于评估测试各种不同系统参数下的数据库负载情况,不需要修改源码,通过自定义 lua 脚本就可以实现不同业务类型的测试。Sysbench 主要包括以下几种测试:
CPU 性能
磁盘 IO 性能
调度程序性能
内存分配及传输速度
POSIX 线程性能
数据库性能(OLTP 基准测试),可以测试 PostgreSQL/MySQL 兼容生态的数据库
2. 准备工作
2.1 服务器配置
为了保证尽量准确的测试结果,我这里选择 3 台同等配置的服务器,一台安装 PG 15,一台安装 OB 4.0 单机版本,一台作为 sysbench 测试机。服务器都是同等配置。如下:
- 16 core
- 64GB 内存
- 普通 HDD 硬盘,>1TB
2.2 OB 4.0 配置
[admin@dbs06 ~]$ obclient -h172.16.10.128 -P2881 -uroot@sys -pobserver -Doceanbase -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221487963
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:57:18)
Copyright (c) 2000, 2018, OB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [oceanbase]> select * from __all_virtual_server\G
*************************** 1. row ***************************
svr_ip: 172.16.10.128
svr_port: 2882
zone: zone1
sql_port: 2881
cpu_capacity: 16
cpu_capacity_max: 16
cpu_assigned: 1
cpu_assigned_max: 1
mem_capacity: 26843545600
mem_assigned: 6710886400
data_disk_capacity: 6947109601280
data_disk_in_use: 1239416832
data_disk_health_status: NORMAL
data_disk_abnormal_time: 0
log_disk_capacity: 158913789952
log_disk_assigned: 66710886400
log_disk_in_use: 939524096
ssl_cert_expired_time: 0
memory_limit: 52613349376
1 row in set (0.001 sec)
从上面可以看出,内存已经分配出去 6 GB 左右,还有 20 GB 左右可用空间,CPU 已经分配出去 1 core,还有 15 core;所以下面我创建新租户会把这些剩余资源一并分配给该租户。
2)创建新租户
首先创建一个 UNIT 14 core/20000000000b内存,然后创建一个资源池 pool1,最后创建租户 testtenant。
-- OB 创建租户
CREATE RESOURCE UNIT unit1
MAX_CPU 14,
MEMORY_SIZE 20000000000;
CREATE RESOURCE POOL pool1
UNIT unit1,
UNIT_NUM 1,
ZONE_LIST ('zone1');
CREATE TENANT IF NOT EXISTS testtenant
charset='utf8mb4',
comment 'mysql tenant/instance',
primary_zone='RANDOM',
resource_pool_list = ('pool1') set ob_tcp_invited_nodes = '%';
3)修改租户密码
登陆到新租户,并修改 root 密码
[admin@dbs06 ~]$ obclient -h172.16.10.128 -P2881 -uroot@testtenant -pobserver -Doceanbase -A
obclient [oceanbase]> ALTER USER root IDENTIFIED BY 'observer';
至此 OB 配置完毕。
2.3 sysbench 和 PostgreSQL 15 配置
sysbench的安装和使用,大家参考链接 https://github.com/akopytov/sysbench ,这里不单独介绍安装了。我这边 sysbench 配置时,已经提前安装了 pgsql 和 mysql 的库文件,保证编译成功。
sysbench 安装成功后,有两个目录:
- /usr/bin/sysbench - sysbench 执行文件
- /usr/local/share/syabench - sysbench lua 脚本文件
3.执行测试
3.1 配置文件统一
mysql-host=dbs06
mysql-port=2881
mysql-user=root
mysql-password=observer
mysql-db=test
time=60
threads=32
report-interval=10
db-driver=mysql
pgconfig 文件:
pgsql-host=dbs05
pgsql-port=25432
pgsql-user=postgres
pgsql-password=
pgsql-db=sbtest
time=60
threads=32
report-interval=10
db-driver=pgsql
3.2 执行命令统一
执行命令也统一采用下面配置,我把脚本里面的 auto-inc 关掉了,因为 OB 在测的过程中采用这个参数会报错,暂时先关闭处理。
sysbench --config-file=pgconfig oltp_read_only.lua --table-size=1000000 --auto-inc=false prepare
sysbench --config-file=pgconfig oltp_read_only.lua --table-size=1000000 --auto-inc=false run
3.3 运行结果简单对比
下面是运行的简单 oltp_read_only 测试,供大家参考。
OB 4.0 单机结果:
[root@dbm02 sysbench]# sysbench --config-file=obconfig oltp_read_only.lua --table-size=1000000 --auto-inc=false run
sysbench 1.1.0-db9fadc (using bundled LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 32
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 10s ] thds: 32 tps: 3057.51 qps: 48946.49 (r/w/o: 42828.47/0.00/6118.02) lat (ms,95%): 20.74 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 32 tps: 3476.26 qps: 55617.89 (r/w/o: 48665.28/0.00/6952.61) lat (ms,95%): 17.01 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 32 tps: 3367.79 qps: 53883.27 (r/w/o: 47147.90/0.00/6735.37) lat (ms,95%): 17.32 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 32 tps: 3387.30 qps: 54204.48 (r/w/o: 47429.69/0.00/6774.80) lat (ms,95%): 17.32 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 32 tps: 3320.32 qps: 53119.08 (r/w/o: 46478.63/0.00/6640.45) lat (ms,95%): 17.63 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 32 tps: 3358.87 qps: 53744.85 (r/w/o: 47027.02/0.00/6717.83) lat (ms,95%): 17.63 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 2796024
write: 0
other: 399432
total: 3195456
transactions: 199716 (3328.14 per sec.)
queries: 3195456 (53250.25 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
Throughput:
events/s (eps): 3328.1404
time elapsed: 60.0083s
total number of events: 199716
Latency (ms):
min: 3.63
avg: 9.61
max: 67.84
95th percentile: 17.95
sum: 1919774.14
Threads fairness:
events (avg/stddev): 6241.1250/158.27
execution time (avg/stddev): 59.9929/0.00
PG 15 单机结果:
[root@dbm02 sysbench]# sysbench --config-file=pgconfig oltp_read_only.lua --table-size=1000000 --auto-inc=false run
sysbench 1.1.0-db9fadc (using bundled LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 32
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Server Endpoint: gpdbs05
Threads started!
[ 10s ] thds: 32 tps: 4735.79 qps: 75803.49 (r/w/o: 66328.91/0.00/9474.59) lat (ms,95%): 12.75 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 32 tps: 3432.54 qps: 54924.11 (r/w/o: 48059.03/0.00/6865.08) lat (ms,95%): 12.30 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 32 tps: 2901.80 qps: 46431.47 (r/w/o: 40627.67/0.00/5803.80) lat (ms,95%): 9.22 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 32 tps: 2894.61 qps: 46311.80 (r/w/o: 40522.59/0.00/5789.21) lat (ms,95%): 9.22 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 32 tps: 2898.80 qps: 46380.69 (r/w/o: 40583.19/0.00/5797.50) lat (ms,95%): 9.22 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 32 tps: 2899.77 qps: 46399.19 (r/w/o: 40599.64/0.00/5799.55) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 2767436
write: 0
other: 395348
total: 3162784
transactions: 197674 (3288.78 per sec.)
queries: 3162784 (52620.56 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
Throughput:
events/s (eps): 3288.7848
time elapsed: 60.1055s
total number of events: 197674
Latency (ms):
min: 2.11
avg: 9.72
max: 627.51
95th percentile: 11.87
sum: 1921736.89
Threads fairness:
events (avg/stddev): 6177.3125/331.83
execution time (avg/stddev): 60.0543/0.04
- OB - transactions: 199716 (3328.14 per sec.) queries: 3195456 (53250.25 per sec.)
- PG - transactions: 197674 (3288.78 per sec.) queries: 3162784 (52620.56 per sec.)
从上面的简单对比可以看出,OB 4.0 单机部署版本在 oltp_read_only 测试下,性能和 PG 15 差不多,OB 4.0 表现略好一点。当然双方都没做什么调优操作,真正的性能对比还值得更深入的去测试。
4. 总结
本文的主要目的是简要介绍一下如何使用 sysbench 对 OceanBase 4.0 进行压测。OB 的生态可以说是已经很完善了,因为对 MySQL 协议提供很好的兼容,所以直接使用 MySQL OLTP 性能测试工具就能进行测试。sysbench 测试整个过程也不复杂:编译安装 sysbench、安装 OB 并创建测试租户、执行测试脚本,三步即可完成 OB 测试。另外在最后进行了 PG 的简单对比测试,也能看出 OB 4.0 在单机可用易用上做了很多工作,值得期待。