OB 運(yùn)維 | 一文講透 OceanBase 單機(jī)版
引言
OceanBase 單機(jī)集中式集群(即單機(jī)版,后文不再稱“單機(jī)集中式集群”)是OceanBase 推出的極簡(jiǎn)數(shù)據(jù)庫架構(gòu),區(qū)別于分布式集群架構(gòu),單機(jī)版無多副本和擴(kuò)縮容能力,適用于開發(fā)測(cè)試環(huán)境及數(shù)據(jù)安全性要求不高的業(yè)務(wù)系統(tǒng)。
OceanBase 社區(qū)版和企業(yè)版都支持單機(jī)版部署,相關(guān)區(qū)別如下。
圖片
- 主備集群: OceanBase v4.1.0 之前,物理備庫的產(chǎn)品形態(tài)為集群級(jí)主備。集群有兩種角色:主集群和備集群。主集群下面所有用戶租戶都是主租戶;備集群下面所有用戶租戶都是備租戶,備集群會(huì)自動(dòng)同步主集群的租戶變更操作。
- 主備租戶: OceanBase v4.1.0 之后,物理備庫的產(chǎn)品形態(tài)變更為租戶級(jí)主備,即主或備的角色信息屬于租戶,分為主租戶和備租戶,集群不再有主備角色的概念,而只是承載租戶的容器。
一、安裝部署
1.1 OceanBase 單機(jī)版部署方式
OceanBase 單機(jī)社區(qū)版部署方式有 3 種,分別是:
- 通過 OBD ALL-IN-ONE 包部署
- 推薦,輕量級(jí)部署,所需資源少(OBD 和 OceanBase 單機(jī)版數(shù)據(jù)庫可復(fù)用1臺(tái)服務(wù)器),方便快速
- 通過命令行方式部署
需純手工命令行操作
通過 OCP 社區(qū)版平臺(tái)部署
適合規(guī)模化部署,需要額外資源部署 OCP 云平臺(tái),運(yùn)維方便
生產(chǎn)環(huán)境推薦
1.2 OceanBase 單機(jī)版最簡(jiǎn)部署
需要提前在 OceanBase 官網(wǎng)上下載 OBD all-in-one 安裝包,下載地址:https://www.oceanbase.com/softwarecenter[1]
1. 通過 all-in-one 安裝包部署 OBD 環(huán)境
su - admin
tar -xzf oceanbase-all-in-one-*.tar.gz
cd oceanbase-all-in-one/bin/
./install.sh
source ~/.oceanbase-all-in-one/bin/env.sh
2. 禁用遠(yuǎn)程倉(cāng)庫
obd mirror disable remote
obd mirror list
# 查看 Type=remote 對(duì)應(yīng)的 Enabled 變成了 False,說明已關(guān)閉遠(yuǎn)程鏡像源
3. 查看本地鏡像中安裝包列表
obd mirror list local
4. 準(zhǔn)備配置文件
cd ~/.oceanbase-all-in-one/obd/usr/obd/example/
cp mini-single-example.yaml mini-single-20240221.yaml
vim mini-single-20240221.yaml
添加如下參數(shù)到配置文件。
user:
username: admin
password: OceanBase_123#
port: 22
oceanbase-ce:
servers:
- 10.186.58.87
global:
home_path: /home/admin/observer
data_dir: /data/1
redo_dir: /data/log1
devname: eth0
mysql_port: 2881
rpc_port: 2882
zone: zone1
cluster_id: 1
memory_limit: 12G
system_memory: 1G
datafile_size: 10G
datafile_next: 2G
datafile_maxsize: 20G
log_disk_size: 20G
cpu_count: 12
production_mode: false
enable_syslog_wf: false
enable_syslog_recycle: true
max_syslog_file_count: 4
root_password: OceanBase_123#
5. 部署 OceanBase 數(shù)據(jù)庫
下述命令創(chuàng)建一個(gè)名字為 obtest 的單節(jié)點(diǎn)集群
obd cluster deploy obtest -c mini-single-20240221.yaml
輸出 obtest deployed 表示該集群創(chuàng)建完成。
6. 配置 lib 環(huán)境變量
通過 OCP 社區(qū)版或 OBD 啟動(dòng)時(shí)不會(huì)有環(huán)境變量問題(啟動(dòng)時(shí)帶了相關(guān)庫),手工啟動(dòng)或執(zhí)行 observer 命令將報(bào)錯(cuò),解決方式如下。
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/observer/lib' >> ~/.bash_profile
source ~/.bash_profile
7. 檢查和啟動(dòng)數(shù)據(jù)庫
確認(rèn) observer 程序在目標(biāo)機(jī)器安裝成功。
/home/admin/observer/bin/observer --version
結(jié)果為 observer (OceanBase_CE 4.2.2.0)。
啟動(dòng) OceanBase 數(shù)據(jù)庫。
obd cluster start obtest
啟動(dòng)完成后,使用 root 登錄數(shù)據(jù)庫(默認(rèn)登錄 sys 租戶)進(jìn)行創(chuàng)建業(yè)務(wù)租戶等操作。
mysql -h10.186.58.87 -P2881 -uroot -p'OceanBase_123#' -Doceanbase -A
show full processlist;
二、主備架構(gòu)
2.1 單機(jī)版主備租戶簡(jiǎn)述
OceanBase 單機(jī)版支持主備租戶架構(gòu),并采用異步方式做數(shù)據(jù)同步。由于 OceanBase 集群支持部署多個(gè)業(yè)務(wù)租戶,所以主備租戶架構(gòu)有三種部署方式:
集群中僅有主租戶或備租戶
典型場(chǎng)景,適用于兩地容災(zāi)等多種業(yè)務(wù)場(chǎng)景
圖片
集群中既有主租戶又有備租戶
適用于兩地多寫(容災(zāi))場(chǎng)景
圖片
主租戶和備租戶在同一個(gè)集群中
適用于業(yè)務(wù)升級(jí)(保留數(shù)據(jù)鏡像)場(chǎng)景
圖片
2.2 單機(jī)版主備租戶部署
本章以經(jīng)典架構(gòu)(集群中僅有主租戶或備租戶)為例進(jìn)行部署,部署方式使用相對(duì)簡(jiǎn)便的 OCP 社區(qū)版云平臺(tái)進(jìn)行部署。
2.2.1 部署 OCP 社區(qū)版
使用 OBD 白屏工具部署 OCP 社區(qū)版,具體步驟略。
- 安裝包下載
https://www.oceanbase.com/softwarecenter
安裝包:ocp-all-in-one-4.2.1-20231208144448.el7.x86_64.tar.gz
- 安裝步驟
參考:https://www.oceanbase.com/docs/common-ocp-1000000000584989[2]
2.2.2 添加主備主機(jī)
OCP 社區(qū)版部署完成后,登錄到 OCP Web 控制臺(tái),添加 2 臺(tái)主備服務(wù)器。
圖片
2.2.3 安裝兩個(gè)集群
上傳需要部署的 OceanBase 數(shù)據(jù)庫安裝包到 OCP 中,需要上傳的包如下(具體版本以實(shí)際為準(zhǔn)):
- oceanbase-ce-utils-4.2.2.0-100000192024011915.el7.x86_64.rpm
- oceanbase-ce-libs-4.2.2.0-100000192024011915.el7.x86_64.rpm
- oceanbase-ce-4.2.2.0-100000192024011915.el7.x86_64.rpm
安裝包上傳完成后,分別創(chuàng)建 2 個(gè)單機(jī)集中式集群。
圖片
圖片
2.2.4 創(chuàng)建主備租戶
第一步,集群 1 中創(chuàng)建示例主租戶 tmysql。
圖片
第二步,集群 2 中創(chuàng)建實(shí)例備租戶 tmysql。
圖片
2.2.5 數(shù)據(jù)同步驗(yàn)證
安裝完成后可通過 OCP - 租戶 - 拓?fù)鋱D 界面驗(yàn)證主備關(guān)系,查看同步延時(shí)。
圖片
業(yè)務(wù)數(shù)據(jù)寫入驗(yàn)證如下:
- 主庫寫入數(shù)據(jù)。
圖片
- 備庫查看數(shù)據(jù)。
圖片
- 備庫同步延時(shí)查看(需要使用備租戶所在集群的 sys 租戶)。
MySQL [oceanbase]> SELECT TENANT_NAME, TENANT_ID, TENANT_ROLE, SCN_TO_TIMESTAMP(SYNC_SCN),NOW() FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'tmysql';
+-------------+-----------+-------------+----------------------------+---------------------+
| TENANT_NAME | TENANT_ID | TENANT_ROLE | SCN_TO_TIMESTAMP(SYNC_SCN) | NOW() |
+-------------+-----------+-------------+----------------------------+---------------------+
| tmysql | 1004 | STANDBY | 2024-02-23 17:07:06.028739 | 2024-02-23 17:07:06 |
+-------------+-----------+-------------+----------------------------+---------------------+
1 row in set (0.02 sec)
2.2.6 故障切換驗(yàn)證
測(cè)試 OceanBase 單機(jī)版主備租戶模式的高可用能力,檢查是否支持故障轉(zhuǎn)移。
- 主庫 kill 前狀態(tài),tmysql 租戶主角色在集群 singlecluster 上。
圖片
- 主庫 kill 后狀態(tài),異步同步鏈路中斷。
圖片
圖片
- 通過手工進(jìn)行容災(zāi)切換的方式進(jìn)行故障轉(zhuǎn)移。
- 手工容災(zāi)切換后,tmysql 租戶主角色切換到集群 singleClusterSlave。
圖片
三、對(duì)比 MySQL 單機(jī)版
校正性能基準(zhǔn)
3.1 測(cè)試命令
本章測(cè)試目的是在獲取測(cè)試服務(wù)器 CPU、磁盤基準(zhǔn)性能的情況下,對(duì) OceanBase 4.2.2 單機(jī)(社區(qū))版和 MySQL 8.0.35 單機(jī)(社區(qū))版數(shù)據(jù)庫性能對(duì)比測(cè)試環(huán)境和命令如下。
注意:為減少不同服務(wù)器之間誤差,本次測(cè)試 MySQL 和 OB 數(shù)據(jù)庫都在同一臺(tái)服務(wù)器上進(jìn)行測(cè)試,測(cè)試交替進(jìn)行,MySQL 測(cè)試完畢后就關(guān)閉 mysqld 服務(wù),啟動(dòng) OB 數(shù)據(jù)庫進(jìn)行測(cè)試。
圖片
3.2 測(cè)試機(jī)基準(zhǔn)測(cè)試
3.2.1 磁盤 FIO 測(cè)試
使用 Fio 工具測(cè)試服務(wù)器的磁盤性能指標(biāo)如下。
- 4K seq read
IOPS: 4975
- 4K seq write
IOPS: 3919
4K rand read
IOPS: 4768
4k rand write
IOPS: 3074
# 4k seq read
[root@10-186-58-85 disktest]# fio -filename=/data/disktest/file -direct=1 -iodepth 1 -thread -ioengine=psync -bs=4k -size=10G -numjobs=30 -runtime=60 -group_reporting -name=iotest4kW -rw=read
fio-3.7
...
iops : min= 3822, max= 5786, avg=4975.06, stdev=262.95, samples=3591
...
# 4K seq write
[root@10-186-58-85 disktest]# fio -filename=/data/disktest/file -direct=1 -iodepth 1 -thread -ioengine=psync -bs=4k -size=10G -numjobs=30 -runtime=60 -group_reporting -name=iotest4kW -rw=write
...
iops : min= 2370, max= 5004, avg=3919.07, stdev=481.46, samples=3577
...
# 4K rand read
[root@10-186-58-85 data]# fio -filename=/data/disktest/file -direct=1 -iodepth 1 -thread -ioengine=psync -bs=4k -size=10G -numjobs=30 -runtime=60 -group_reporting -name=iotest4kW -rw=randread
...
iops : min= 3746, max= 5390, avg=4768.96, stdev=259.29, samples=3583
...
# 4K rand write
[root@10-186-58-85 data]# fio -filename=/data/disktest/file -direct=1 -iodepth 1 -thread -ioengine=psync -bs=4k -size=10G -numjobs=30 -runtime=60 -group_reporting -name=iotest4kW -rw=randwrite
...
iops : min= 784, max= 4416, avg=3074.03, stdev=636.20, samples=3574
...
3.2.2 CPU 測(cè)試
使用 Sysbench 工具測(cè)試服務(wù)器的 CPU 性能指標(biāo)如下。
[root@10-186-58-85 ~]# /root/sysbench-1.0.20/src/sysbench cpu --time=60 --threads=4 --report-interval=2 run
...
CPU speed:
events per second: 16316.69
General statistics:
total time: 60.0011s
total number of events: 979033
Latency (ms):
min: 0.23
avg: 0.24
max: 40.26
95th percentile: 0.25
sum: 239493.26
Threads fairness:
events (avg/stddev): 244758.2500/1500.12
execution time (avg/stddev): 59.8733/0.01
3.3 4c8g 對(duì)比測(cè)試結(jié)果
同一服務(wù)器(配置為 4c8g)下測(cè)試 OB 和 MySQL 單機(jī)版的對(duì)比結(jié)果。
圖片
通過上述測(cè)試,在校準(zhǔn)測(cè)試服務(wù)器性能偏差的情況下,對(duì)比 OceanBase 單機(jī)版和 MySQL 單機(jī)版的測(cè)試結(jié)果結(jié)論如下:
低并發(fā)場(chǎng)景,OB 單機(jī)版性能比 MySQL 單機(jī)版低 50% 左右。
3.4 12c16g 對(duì)比測(cè)試結(jié)果
同一服務(wù)器(擴(kuò)容虛機(jī)配置為 12c16g)下測(cè)試 OB 和 MySQL 單機(jī)版的對(duì)比結(jié)果。
圖片
通過上述測(cè)試,在校準(zhǔn)測(cè)試服務(wù)器性能偏差的情況下,對(duì)比 OceanBase單機(jī)版和 MySQL 單機(jī)版的測(cè)試結(jié)果結(jié)論如下
混合讀寫場(chǎng)景,OB 單機(jī)版性能與 MySQL 單機(jī)版持平(虛擬機(jī)多次測(cè)試結(jié)果上下差 ±2000 左右,所以該場(chǎng)景 OB 與 MySQL 的性能結(jié)果相差不大)。
純寫場(chǎng)景,OB 單機(jī)版性能與 MySQL 單機(jī)版略高 15% 左右。
四、對(duì)比 OBD 自帶測(cè)試工具
OBD test 命令可以一鍵進(jìn)行 sysbench 測(cè)試,原理上還是需要調(diào)用 sysbench 測(cè)試工具的 bin 文件和 LUA Scripts,僅在最外層包裝了一層 Python 腳本進(jìn)行調(diào)用,調(diào)用文件存儲(chǔ)在:/oceanbase-all-in-one/obd/usr/obd/plugins/sysbench/4.0.0.0/run_test.py。
4.1 測(cè)試命令
圖片
4.2 測(cè)試結(jié)果
使用 OBD test sysbench 與 直接使用 sysbench 測(cè)試 OceanBase 單機(jī)版結(jié)果差不多,部分測(cè)試結(jié)果如下:
圖片
五、OB 單機(jī)版資源配置
5.1 單機(jī)版集群配置巡檢
本節(jié)適用于集群做 Sysbench 測(cè)試前,對(duì)單機(jī)版集群的資源規(guī)格和集群配置等做一輪巡檢,已提供更好的性能表現(xiàn)。
在部署 OceanBase 單機(jī)版集群之后,可以使用 obdiag (OceanBase Diagnose )工具對(duì)部署好的集群巡檢,步驟如下。
5.1.1 安裝 obdiag 工具
Obdiag 工具在 OBD ALL-IN-ONE 包中已提供,可直接使用 obd 進(jìn)行安裝。
cd ~/oceanbase-all-in-one/rpms/
obd mirror clone oceanbase-diagnostic-tool-1.6.0-22024020410.el7.x86_64.rpm
obd obdiag deploy
5.1.2 巡檢集群輸出報(bào)告
odb obdiag check <cluster_name>
# 巡檢正常完成,會(huì)有如下提示:Check observer finished. For more details, please run cmd' cat ./check_report//check_report_observer_2024-02-27-14-16-19.table '
- 直接復(fù)制命令,粘貼執(zhí)行即可查看配置建議。
[root@10-186-58-75 oceanbase-diagnostic-tool]# cat ./check_report//check_report_observer_2024-02-27-14-16-19.table
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| fail-tasks-report |
+-------------------------------------------+--------------------------------------------------------------------------------------------------------------+
| task | task_report |
+-------------------------------------------+--------------------------------------------------------------------------------------------------------------+
| sysbench.sysbench_free_test_network_speed | [fail] [remote:10.186.58.86] network_speed is and the type is <class 'str'>, not int or float ordecimal ! |
+-------------------------------------------+--------------------------------------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------------------------------------------------------------+
| critical-tasks-report |
+-------------------------------------------+--------------------------------------------------------------------------------------------+
| task | task_report |
+-------------------------------------------+--------------------------------------------------------------------------------------------+
| sysbench.sysbench_free_test_cpu_count | [critical] [remote:10.186.58.86] cpu_count/os_cpu_count is 8%,is not between 80 and 100 |
| sysbench.sysbench_free_test_memory_limit | [critical] [remote:10.186.58.86] memory_limit/os_memory is 26%,is not between 80 and 100 |
| sysbench.sysbench_test_cluster_parameters | [critical] [cluster:obcluster] cluster's enable_perf_event is true , need to change False |
+-------------------------------------------+--------------------------------------------------------------------------------------------+
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| warning-tasks-report |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| task | task_report |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sysbench.sysbench_free_test_cpu_count | [warning] [cluster:obcluster] cpu_count is 2 , need to calculate the relationship between cpu_count and the number of system CPUs |
| sysbench.sysbench_test_cluster_datafile_size | [warning] [remote:10.186.58.86] When the data disk and log disk are on the same disk, the log disk needs to occupy more than 30% of the disk space. now it is 11% |
| | [warning] [remote:10.186.58.86] When the data disk and log disk are on the same disk, the data disk needs to occupy more than 60% of the disk space. now it is 5% |
| sysbench.sysbench_test_cluster_log_disk_size | [warning] [cluster:obcluster] log_disk_size <20G tenant: trenzy . log_disk_size need >20G |
| sysbench.sysbench_test_tenant_cpu_parameters | [warning] [cluster:obcluster] cpu_count is 2. the min_cpu of tenant should cpu_count/2 ~ cpu_count. tenant: sys,trenzy need check |
| | [warning] [cluster:obcluster] the MAX_IOPS of tenant should max_cpu * 10000 ~ max_cpu * 1000000 . tenant: trenzy need check |
| | [warning] [cluster:obcluster] the MIN_IOPS of tenant should max_cpu * 10000 ~ max_cpu * 1000000 . tenant: trenzy need check |
| | [warning] [cluster:obcluster] cpu_count is 2. the max_cpu of tenant should cpu_count/2 ~ cpu_count. tenant: sys,trenzy need check |
| sysbench.sysbench_test_tenant_log_disk_size | [warning] [cluster:obcluster] log_disk_size <20G tenant: trenzy . log_disk_size need >20G |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| all-tasks-report |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| task | task_report |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sysbench.sysbench_free_test_cpu_count | [critical] [remote:10.186.58.86] cpu_count/os_cpu_count is 8%,is not between 80 and 100 |
| | [warning] [cluster:obcluster] cpu_count is 2 , need to calculate the relationship between cpu_count and the number of system CPUs |
| sysbench.sysbench_free_test_memory_limit | [critical] [remote:10.186.58.86] memory_limit/os_memory is 26%,is not between 80 and 100 |
| sysbench.sysbench_free_test_network_speed | [fail] [remote:10.186.58.86] network_speed is and the type is <class 'str'>, not int or float ordecimal ! |
| sysbench.sysbench_test_cluster_datafile_size | [warning] [remote:10.186.58.86] When the data disk and log disk are on the same disk, the log disk needs to occupy more than 30% of the disk space. now it is 11% |
| | [warning] [remote:10.186.58.86] When the data disk and log disk are on the same disk, the data disk needs to occupy more than 60% of the disk space. now it is 5% |
| sysbench.sysbench_test_cluster_log_disk_size | [warning] [cluster:obcluster] log_disk_size <20G tenant: trenzy . log_disk_size need >20G |
| sysbench.sysbench_test_cluster_parameters | [critical] [cluster:obcluster] cluster's enable_perf_event is true , need to change False |
| sysbench.sysbench_test_cpu_quota_concurrency | all pass |
| sysbench.sysbench_test_log_level | all pass |
| sysbench.sysbench_test_sql_net_thread_count | all pass |
| sysbench.sysbench_test_tenant_cpu_parameters | [warning] [cluster:obcluster] cpu_count is 2. the min_cpu of tenant should cpu_count/2 ~ cpu_count. tenant: sys,trenzy need check |
| | [warning] [cluster:obcluster] the MAX_IOPS of tenant should max_cpu * 10000 ~ max_cpu * 1000000 . tenant: trenzy need check |
| | [warning] [cluster:obcluster] the MIN_IOPS of tenant should max_cpu * 10000 ~ max_cpu * 1000000 . tenant: trenzy need check |
| | [warning] [cluster:obcluster] cpu_count is 2. the max_cpu of tenant should cpu_count/2 ~ cpu_count. tenant: sys,trenzy need check |
| sysbench.sysbench_test_tenant_log_disk_size | [warning] [cluster:obcluster] log_disk_size <20G tenant: trenzy . log_disk_size need >20G |
| sysbench.sysbench_test_tenant_primary_zone | all pass |
+----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5.2 最低穩(wěn)定運(yùn)行環(huán)境
經(jīng)過測(cè)試,OceanBase 單機(jī)版最少資源規(guī)格穩(wěn)定運(yùn)行所需的環(huán)境如下。
- 服務(wù)器規(guī)格
CPU 2C,內(nèi)存 5G(確??捎脙?nèi)存大于 4G),磁盤 100G
- 系統(tǒng)租戶規(guī)格
CPU 1G,內(nèi)存 2G
業(yè)務(wù)租戶規(guī)格
CPU 1G,內(nèi)存 1G
集群配置文件
# cat min-2c4g.yaml
user:
username: admin
password: OceanBase_123#
port: 22
oceanbase-ce:
servers:
- 10.186.56.101
global:
home_path: /home/admin/observer
data_dir: /data/1
redo_dir: /data/log1
devname: eth0
mysql_port: 2881
rpc_port: 2882
zone: zone1
cluster_id: 1
memory_limit: 4G
system_memory: 1G
datafile_size: 10G
datafile_next: 2G
datafile_maxsize: 20G
log_disk_size: 20G
cpu_count: 2
production_mode: false
enable_syslog_wf: false
enable_syslog_recycle: true
max_syslog_file_count: 4
__min_full_resource_pool_memory: 1073741824
root_password: OceanBase_123#
5.2.1 最低運(yùn)行環(huán)境下啟動(dòng) OB
部署的Linux服務(wù)器規(guī)格如下:
[root@10-186-56-101 admin]# grep process /proc/cpuinfo
processor : 0
processor : 1
[root@10-186-56-101 admin]# free -m
total used free shared buff/cache available
Mem: 4797 2624 979 16 1194 1917
Swap: 0 0 0
[root@10-186-56-101 admin]# ps -ef | grep obs
admin 2636 1 29 07:25 ? 00:08:29 /home/admin/observer/bin/observer -r 10.186.56.101:2882:2881 -p 2881 -P 2882 -z zone1 -c 1 -d /data/1 -i eth0 -o __min_full_resource_pool_memory=1073741824,memory_limit=4G,system_memory=1G,datafile_size=10G,datafile_next=2G,datafile_maxsize=20G,log_disk_size=20G,cpu_count=2,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4
5.2.2 最低運(yùn)行環(huán)境下 Sysbench 持續(xù)測(cè)試
[root@10-186-58-75 example]# sysbench /root/sysbench-1.0.20/src/lua/oltp_read_write.lua --tables=5 --table_size=1000 --mysql-host=10.186.56.101 --mysql-port=2881 --mysql-user='root@trenzy' --mysql-password='OceanBase_123#' --mysql-db=sbtest --report-interval=2 --time=3600 --threads=1 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Report intermediate results every 2 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 2s ] thds: 1 tps: 37.42 qps: 749.45 (r/w/o: 524.42/149.69/75.34) lat (ms,95%): 42.61 err/s: 0.00 reconn/s: 0.00
...
[ 342s ] thds: 1 tps: 60.50 qps: 1215.48 (r/w/o: 851.48/243.00/121.00) lat (ms,95%): 24.38 err/s: 0.00 reconn/s: 0.00
[ 344s ] thds: 1 tps: 58.01 qps: 1159.20 (r/w/o: 812.14/231.04/116.02) lat (ms,95%): 23.95 err/s: 0.00 reconn/s: 0.00
注意:
- 業(yè)務(wù)規(guī)格為 1c1g 情況下,持續(xù)寫入很容易打滿內(nèi)存。報(bào)如下錯(cuò)誤,但不影響 observer 運(yùn)行。
- 可以調(diào)整 alter system set memstore\_limit\_percentage=80; 將內(nèi)存適度調(diào)大。
FATAL: mysql_stmt_execute() returned error 4013 (No memory or reach tenant memory limit) for query 'SELECT c FROM sbtest4 WHERE id BETWEEN ? AND ? ORDER BY c'
FATAL: `thread_run' function failed: /usr/local/share/sysbench/oltp_common.lua:432: SQL error, errno = 4013, state = 'HY001': No memory or reach tenant memory limit
FATAL: mysql_stmt_execute() returned error 4013 (No memory or reach tenant memory limit) for query 'SELECT c FROM sbtest2 WHERE id BETWEEN ? AND ? ORDER BY c'
5.3 單機(jī)版推薦參數(shù)配置
結(jié)合 Sysbench 性能壓測(cè),推薦的集群、租戶的參數(shù)或變量設(shè)置如下(適應(yīng)于性能要求較高的測(cè)試環(huán)境)。
- 集群參數(shù)配置
# 默認(rèn) 2G,可創(chuàng)建 unit 的最小內(nèi)存閾值,若不設(shè)置創(chuàng)建 1G 內(nèi)存規(guī)格的 unit 將失敗。
alter system set __min_full_resource_pool_memory=1073741824;
# 默認(rèn) 5s,設(shè)置查詢執(zhí)行時(shí)間的閾值。超過時(shí)間的請(qǐng)求可能被暫停,暫停后自動(dòng)被判斷為大查詢,執(zhí)行大查詢調(diào)度策略
alter system set large_query_threshold='600s';
# 默認(rèn) true,是否開啟審計(jì)日志;開發(fā)或性能要求高的場(chǎng)景可關(guān)閉,生產(chǎn)環(huán)境需開啟
alter system set enable_sql_audit=false;
# 默認(rèn) true,是否開啟信息采集;開發(fā)或性能要求高的場(chǎng)景可關(guān)閉,生產(chǎn)環(huán)境需開啟
alter system set enable_perf_event=false;
# 默認(rèn) true,是否開啟 Trace Log 功能
alter system set enable_record_trace_log=false;
# 默認(rèn) WDIAG,系統(tǒng)日志的日志級(jí)別
alter system set syslog_level='INFO';
- 業(yè)務(wù)租戶參數(shù)配置
# 默認(rèn) false,是否啟用批處理功能的成組執(zhí)行優(yōu)化
alter system set ob_enable_batched_multi_statement=true;
# 默認(rèn) false,用于對(duì)日志傳輸是否使用壓縮,建議開啟減少網(wǎng)卡壓力
alter system set log_transport_compress_all=true;
- 業(yè)務(wù)租戶變量配置
# 默認(rèn) MANUAL,用于設(shè)置并行度選擇策略。
set global parallel_degree_policy=AUTO;
# 默認(rèn) 5,SQL 執(zhí)行的租戶內(nèi)存百分比限制
set global ob_sql_work_area_percentage=20;
# 默認(rèn) 10000000,設(shè)置 SQL 最大執(zhí)行時(shí)間,單位是微秒
set global ob_query_timeout=13888000000;
# 默認(rèn) 16777216,設(shè)置最大網(wǎng)絡(luò)包大小,單位是 Byte
set global max_allowed_packet=41943040;
七、附件
MySQL 配置文件
章節(jié)三對(duì)比測(cè)試中,用到的 MySQL 8.0.35 配置文件如下。
[mysql]
default-character-set = utf8mb4
user = root
password =
[mysqld]
# Basic Settings
server-id = 1019938001
port = 8001
pid-file = mysqld.pid
socket = mysqld.sock
mysqlx_socket = mysqldx.sock
character_set_server = utf8mb4
default_storage_engine = InnoDB
lower_case_table_names = 1
skip_name_resolve = 1
skip_external_locking = 1
skip_slave_start = 1
basedir = /data/mysql/8001/base
datadir = /data/mysql/8001/data
tmpdir = /data/mysql/8001/tmp
# P_S Settings
performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'
# Session Memory Settins
join_buffer_size = 2M
sort_buffer_size = 2M
tmp_table_size = 8M
max_heap_table_size = 8M
max_allowed_packet = 128M
# Global Memory and Cache Settings
temptable_max_ram = 1G
open_files_limit = 65535
max_connections = 1024
table_open_cache = 2048
# InnoDB Settings
innodb_buffer_pool_size = 8G
innodb_data_file_path = ibdata1:12M:autoextend
innodb_buffer_pool_instances = 1
innodb_file_per_table = 1
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_flush_log_at_trx_commit = 1
innodb_io_capacity = 2000
innodb_io_capacity_max = 10000
innodb_flush_method = O_DIRECT
innodb_strict_mode = 1
innodb_flush_neighbors = 1
innodb_page_cleaners = 8
innodb_purge_threads = 8
innodb_log_file_size = 1024M
innodb_log_buffer_size = 16777216
innodb_print_all_deadlocks = 1
innodb_sort_buffer_size = 67108864
# Log Settings
log_error = mysql-error.log
log_bin = mysql-bin.log
slow_query_log_file = mysql-slow.log
relay_log = mysql-relay.log
log_slave_updates = 1
sync_binlog = 1
relay_log_recovery = 1
binlog_format = row
binlog_expire_logs_seconds = 2592000
slow_query_log = 1
long_query_time = 3
log_slow_admin_statements = 1
log_slow_slave_statements = 1
# Replication Settings
slave_skip_errors = ddl_exist_errors
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
binlog_gtid_simple_recovery = 1
binlog_rows_query_log_events = 1
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 8
slave_preserve_commit_order = 1
binlog_group_commit_sync_delay=10000
binlog_group_commit_sync_no_delay_count=32
參考資料
[1]OBD 安裝包: https://www.oceanbase.com/softwarecenter
[2]OBD 部署安裝 OCP 社區(qū)版步驟: https://www.oceanbase.com/docs/common-ocp-1000000000584989
作者:任仲禹,愛可生數(shù)據(jù)庫高級(jí)工程師,擅長(zhǎng)故障分析和性能優(yōu)化。