暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

实战OceanBase社区版性能测试探索- sysbench篇之物理建模优化

原创 大数据模型 2022-04-24
1133

前言

紧接上文实战-OceanBase3.1.2数据库性能测试探索,我搭建了 一个1-1-1结构的OceanBase3.1.2版本,准备进行性能探索测试。在正式测试之前,先定义清楚影响数据库性能的相关因素,首先我通过简单的dd命令生成文件,查看硬盘的IO性能,然后三个节点互通文件,查看网络带宽能达到多少速度。一个分布式集群,节点之间互相通讯传输信号和数据,取决于网络带宽和硬盘IO,其中一个节点慢会令集群性能大打折扣。

除了硬件,数据库的关键核心参数也与性能调优,笔者从缓存、不可变性、有序的sstable把官方的调优参数归类了一下。后面根据自己的经验还找了副本分布和详细数据分布、索引分区因素,围绕OceanBase找了调优的核心指标。

但是我发现我做的这一切是无用的,本人的1-1-1架构硬件配置如下

image.png

而默认安装的OceanBase的sys租户就占了5个CPU,2G内存,sys租户对集群可以使用的资源是15个CPU和6G 内存。 但是我要进行测试必须创建一个新的租户,这个新的租户最多只能使用1个CPU, 4G内存,集群可以使用的资源是3个CPU和12G 内存,这么小的资源能够做什么?

image.png

抱着这样的好奇心,我进行了sysbench测试,目标是测出影响sysbench性能数据的最关键因素。当前测试没有采用官方推荐的sysbench优化参数,因为笔者看了OceanBase的默认参数,感觉还算温和,不算太坑。

测试环境

image.png

测试思路

image.png

由于实际租户使用的资源是3个CPU和12G 内存,所以优化思路是从表结构入手,凡事有轻重缓急优先顺序,我 理解单就sysbench这个业务场景,bloom filter启用以及blocksize大小这个很重要,另外一招是接入层上面,通过外置一个haproxy,分发三个obproxy。

先了解sysbench

sysbench的/root/sysbench-1.0/src/lua 路径下有四个文件,分别是
oltp_read_write.lua oltp_write_only.lua oltp_read_only.lua oltp_point_select.lua,这四个是数据库操作的业务逻辑程序,这四个程序都会调用oltp_common,oltp_common.lua可以修改表结构,基本表结构如下。

CREATE TABLE sbtest%d(
  id %s,
  k INTEGER DEFAULT '0' NOT NULL,
  c CHAR(120) DEFAULT '' NOT NULL,
  pad CHAR(60) DEFAULT '' NOT NULL,
  %s (id)
) %s %s]],
      table_num, id_def, id_index_def, engine_def, extra_table_options)

可以看出表结构没有分区,我对OceanBase社区版性能调优的计划是通过修改oltp_common.lua增加分区,增加bloom_filter,增加block_size对比原来的表结构看是否能提高性能处理能力。

测试一开始就遇上一个与硬件性能的问题,returned error 4030 (Over tenant memory limits),这个故障是租户内存不足的报错,主要原因是内存转储到硬盘的时候,由于数据太多,内存无法满足转储能力报错。我试过修改其它参数提高转储能力,但是无效,最终还是要提高租户内存,现在我把能打给新租户的内存调到最高。

MySQL [oceanbase]> SELECT unit_config_id,name,max_cpu,min_cpu,max_memory,min_memory,max_disk_size FROM __all_unit_config;
+----------------+-----------------+---------+---------+------------+------------+---------------+
| unit_config_id | name            | max_cpu | min_cpu | max_memory | min_memory | max_disk_size |
+----------------+-----------------+---------+---------+------------+------------+---------------+
|              1 | sys_unit_config |       5 |     2.5 | 2576980377 | 2147483648 |   16875782144 |
|           1005 | unittpcc        |       1 |       1 | 4294967296 | 4294967296 |   53687091200 |
+----------------+-----------------+---------+---------+------------+------------+---------------+
2 rows in set (0.006 sec)

我目标数据集是100万,但是100万的数据总是报错error 4030 ,我折腾了好久没有搞定,最后折半改成50万数据。

以50万数据为基础,展开三段测试 ,第一段以默认的表结构测试,第二段第三段将会修改表结构,一个是增加partition,一个增加bloom filter,并提高blocksize。具体操作如下

  1. 生成新的表结构文件 cp oltp_common.lua oltp_common_read.lua
  2. oltp_common_read.lua更改表结构,增加分区如下, 这个是网上看某位哥的建议
CREATE TABLE sbtest%d(
  id %s,
  k INTEGER DEFAULT '0' NOT NULL,
  c CHAR(120) DEFAULT '' NOT NULL,
  pad CHAR(60) DEFAULT '' NOT NULL,
  %s (id,k))
) partition by hash(k) %s %s ]],

关于blocksize的数值设置,个人的经验认为blocksize设的值越大越好,

CREATE TABLE sbtest%d(
  id %s,
  k INTEGER DEFAULT '0' NOT NULL,
  c CHAR(120) DEFAULT '' NOT NULL,
  pad CHAR(60) DEFAULT '' NOT NULL,
  %s (id)
) USE_BLOOM_FILTER = TRUE   BLOCK_SIZE =  1048576 %s %s ]],

3.编辑oltp_read_only.lua,调用修改后的lua文件,把require(“oltp_common”)改为oltp_common_read

运行以下脚本,生成50万数据,由于我的资源太低,只能用1个线程,

/root/sysbench-1.0/src/sysbench  oltp_read_only.lua 
--mysql-host=XXX --mysql-port=2883
 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster 
--mysql-password=henley    --table-size=500000 --tables=30  
--threads=1  --report-interval=10 --time=60  --db-ps-mode=disable   prepare

正式测试

进入OceanBase,通过show create table 表名,查看表结构是否已经更改,这样第一步prepare生成的表自动生成分区或者自带bloom参数,随即运行runsysbench.sh

#!/bin/sh /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XXX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=32 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XXX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=64 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=128 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XXX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=256 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=512 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_point_select.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=1024 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=32 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=64 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=128 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=256 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=512 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=1024 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=32 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=64 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=128 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=256 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=512 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_write_only.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=1024 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=32 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=64 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=128 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=256 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=512 --report-interval=10 --time=60 --db-ps-mode=disable run /root/sysbench-1.0/src/sysbench oltp_read_write.lua --mysql-host=XX --mysql-port=2883 --mysql-db=sysbench --mysql-user=henley@tenanttpcc#obcluster --mysql-password=henley --table-size=500000 --tables=30 --threads=1024 --report-interval=10 --time=60 --db-ps-mode=disable run

运行脚本过程中,通过securecrt自带的LOG Session记录运行日志,共采集3段日志,整理信息数据如下。

image.png

三段数据比较,居然50万数据带partition,设置bloom filter性能还不如原来的表结构,3个节点通过dstat -cmndst和htop查看硬件,发现CPU一直没有打满,即使插入数据最多使用率是50左右,其中NODE1会比NODE2、NODE3繁忙一点,网络和硬盘也比较空闲,内存接近11G,但是不得而知内存中的对象工作状态。

初步判断是与数据量有关系,还是想把数据提升到100万,但是内存太少工作很不稳定,总是报错error 4030 ,但是有时候又能通过,我改了几个参数都没有生效,折腾了好久,后来我终于发现奥秘。

OceanBase的租户内存的监测程序一直在运行中,会对使用的内存进行监测,在系统的prepare运行中插入数据的时候,不停在三个节点上运行 echo 3 > /proc/sys/vm/drop_caches,通过把Page Cache的内存回收,保持物理内存稳定,这样OceanBase识别租户内存还是有冗余的,成功导入100万数据。

image.png

马上运行了run_Sysbench.sh,对100万的原始表结构的 sysbech性能记录了Log Session,
然后在Oceanbase把表结构设置成为bloom_filter设置成为true,BLOCK_SIZE 设置成为163840,如下

ALTER TABLE sbtest1 SET use_bloom_filter=true; ALTER TABLE sbtest2 SET use_bloom_filter=true; ALTER TABLE sbtest3 SET use_bloom_filter=true; ALTER TABLE sbtest4 SET use_bloom_filter=true; ALTER TABLE sbtest5 SET use_bloom_filter=true; ALTER TABLE sbtest6 SET use_bloom_filter=true; ALTER TABLE sbtest7 SET use_bloom_filter=true; ALTER TABLE sbtest8 SET use_bloom_filter=true; ALTER TABLE sbtest9 SET use_bloom_filter=true; ALTER TABLE sbtest10 SET use_bloom_filter=true; ALTER TABLE sbtest11 SET use_bloom_filter=true; ALTER TABLE sbtest12 SET use_bloom_filter=true; ALTER TABLE sbtest13 SET use_bloom_filter=true; ALTER TABLE sbtest14 SET use_bloom_filter=true; ALTER TABLE sbtest15 SET use_bloom_filter=true; ALTER TABLE sbtest16 SET use_bloom_filter=true; ALTER TABLE sbtest17 SET use_bloom_filter=true; ALTER TABLE sbtest18 SET use_bloom_filter=true; ALTER TABLE sbtest19 SET use_bloom_filter=true; ALTER TABLE sbtest20 SET use_bloom_filter=true; ALTER TABLE sbtest21 SET use_bloom_filter=true; ALTER TABLE sbtest22 SET use_bloom_filter=true; ALTER TABLE sbtest23 SET use_bloom_filter=true; ALTER TABLE sbtest24 SET use_bloom_filter=true; ALTER TABLE sbtest25 SET use_bloom_filter=true; ALTER TABLE sbtest26 SET use_bloom_filter=true; ALTER TABLE sbtest27 SET use_bloom_filter=true; ALTER TABLE sbtest28 SET use_bloom_filter=true; ALTER TABLE sbtest29 SET use_bloom_filter=true; ALTER TABLE sbtest30 SET use_bloom_filter=true; ALTER TABLE sbtest1 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest2 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest3 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest4 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest5 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest6 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest7 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest8 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest9 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest10 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest11 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest12 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest13 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest14 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest15 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest16 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest17 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest18 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest19 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest20 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest21 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest22 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest23 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest24 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest25 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest26 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest27 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest28 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest29 SET BLOCK_SIZE = 163840; ALTER TABLE sbtest30 SET BLOCK_SIZE = 163840;

对比100万原始表结构,这次终于看到性能上的提升了,QPS、延迟数、总数、吞吐量相对于旧值有一定的提升,见下图摘录QPS和95的延迟均值。
image.png

但是在运行状态中,查看三个节点的CPU状态,依然是有很空闲,网络和硬盘IO也没有打满,内存也没有绷紧,这个说明还有提升的空间。我还有什么招去提升性能?

问题总结

  • 为什么会有error 4030 (Over tenant memory limits) ?我猜 这与OceanBase的存储机制有关,OceanBase是100%自我研发,它没有使用rocksDB这么稳健强劲的单机引擎做为数据存储。侧面说明obkv的消息队列和高速缓存等功能有待完善加强。
  • 为什么50万的原数据表结构会比 有partition、有bloom filter的快,可能性原因是数据量不够,bloom机制与partition的开启额外要花更多的时间,因为partition发而发生了不该有的分布式事务,而且数据太小还有一些进行了网络查找。当数据量去到100万,bloom和blocksize的设置选项效果才发挥出来。

优化总结

  • sstable设置以及blocksize设置与partition与OceanBase有强关系,要适当的使用
  • sysbench测试性能还有提升的空间,CPU没有使用100%,网络负荷也没有达到100M以上,硬盘 也没有饱满。
  • 三个节点每个节点8C、16核的配置,OceanBase的初始化设置不好,创建的租户只占用了集群3个核 ,12G内存,如果在初始化这方面琢磨或者想法设法降低sys也是优化的一个手段。
  • 测试由头到尾用的是OceanBase的默认参数配置,没有使用官网的配置参数,笔者认为表结构的优化最大的调优。

其它提升性能的方法

  • 引入haproxy或者lvs等软件负载均衡,在其它两个节点也安装obproxy,通过haproxy挂接三个obproxy,展开sysbench测试。
  • 引入官方推荐的sysbench相关调优参数
  • 引入CPU绑核

有时间的话我还会做一下haproxy连带三个的测试,全文 完。

最后修改时间:2022-04-28 11:33:10
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论