1、概述
本文主要形貌了在4路鲲鹏服务器上,通过软硬件协同优化设置达到openGauss数据库的极致性能的方法。
主要包括软硬件要求、BIOS设置、网卡设置、磁盘设置、服务器参数设置、数据库参数设置、绑核以及TPCC模型脚本优化等内容。
1.1 硬件规格
- 服务器: TaiShan 200(Model 2480)
- CPU: Kunpeng-920 ARM aarch64(4 Sockets * 64 Cores)
- 内存: 1TB
- 网卡: 万兆网卡Hi1822 Family(4*25GE),时延 < 0.1ms
- 磁盘: NVME * 4,Model Number:HWE56P433T2M005N(V5 NVME卡)、HWE36P43016M000N(V3 NVME卡),其中V5 NVME卡 1MB顺序写带宽达到2600MB以上
1.2 软件规格
- 操纵体系: openEuler 20.03 (LTS)
- 数据库软件: openGauss 5.0.0 或其他更高Release版
- 压测软件: BenchmarkSQL-5.0
2、服务器优化设置
2.1 BIOS设置
登录服务器管理体系,进入BIOS,举行以下设置,保存后重启:
设置项保举值菜单路径阐明Support SmmuDisabledAdvanced > MISC Config > Support SmmuSystem Memory Management UnitCPU Prefetching ConfigurationDisabledAdvanced > MISC Config > CPU Prefetching ConfigurationCPU预取,保举关闭Die InterleavingDisabledAdvanced > Memory Config > Die Interleaving控制是否使用DIE交织,保举关闭Max Payload Size512BAdvanced > PCIe Config > CPU X PCIe - Port X > Max Payload Size每次传输数据的最大单位,值越大带宽使用率越高。
其中X为具体的CPU编号 2.2 磁盘设置
本次调优中,需要用到4个 NVME 存储卡。分别用于存放 datanode 本身、xlog、2个比力大的表空间。其中用于存放 xlog 的为V5的NVME存储卡,容量3TB以上,其余为V3的NVME存储卡,容量1TB以上。
在4p单机环境下,CPU更多,并发更大,单位时间内产生的数据量更大,IO很容易成为制约性能的瓶颈,以是在条件答应的环境下,应只管使用V5的存储卡,V5的存储卡优先用于存放xlog文件。
2.2.1 格式化文件体系
查看 nvme 的文件体系类型,确认块大小是否为8KB(bsize=8192)。
- # 如查看挂载在 /data4 路径下硬盘信息
- xfs_info /data4
复制代码
假如不是,则将其格式化为8KB(格式化前注意数据备份)。
- umount /data4
- mkfs.xfs -b size=8192 /dev/nvme3n1 -f
- mount /dev/nvme3n1 /data4
复制代码 操纵完成后再次用 xfs_info 确认是否实行成功。
2.2.2 设置磁盘IO队列调治机制
- echo none > /sys/block/nvme0n1/queue/scheduler
- echo none > /sys/block/nvme1n1/queue/scheduler
- echo none > /sys/block/nvme2n1/queue/scheduler
- echo none > /sys/block/nvme3n1/queue/scheduler
复制代码 2.3 网络设置
进入华为官网 ,选择对应的版本及补丁号,如 IN500 solution 5.1.0.SPC401 ,下载 IN500_solution_5.1.0.SPC401.zip
安装hinicadm工具。
以管理员身份实行以下命令:
- mkdir IN500_solution_5.1.0
- export IN500_HOME=$(pwd)/IN500_solution_5.1.0
- unzip IN500_solution_5.1.0.SPC401.zip -d IN500_solution_5.1.0
- cd $IN500_HOME/tools/linux_arm/nic/
- rpm -ivh hinicadm-2.4.1.0-1.aarch64.rpm
复制代码
通过 ifconfig
命令查看使用的网络接口卡。
根据设置的ip确认网络接口卡名:enp71s0
查看Hi1822设备信息:
可以看到小网口 enp71s0 对应的物理网卡设备名为 hinic0。
设置环境参数,以方便后续使用:
- export CARD_NAME=enp71s0
- export HARD_DEV=hinic0
复制代码 2.3.1 更换网卡固件
firmware-version 为 2.4.1.0,则无需修改。否则假如是2.5.0.0,发起更换为2.4.1.0。
- (2)更换固件。
- # 命令格式为:
- hinicadm updatefw -i <物理网卡设备名> -f <固件文件路径>
- # 例如:
- hinicadm updatefw -i $HARD_DEV -f $IN500_HOME/firmware/update_bin/cfg_data_nic_prd_1h_4x25G/Hi1822_nic_prd_1h_4x25G.bin
复制代码 - (3)重启服务器,确认firmware-version 是否为 2.4.1.0。
2.3.2 设置停止队列
- (1)查看当前网卡的停止队列设置
IN500_solution_5.1.0支持设置最大停止数为16或64,在4P单机调优场景下,我们需要将停止数设置为24,以是需要将最大停止数设置为64。
通过以下命令查看当前的设置:
上图中第一个Combined值为网卡支持的最大停止数,第二个Combined值为当前网卡设置的停止数24。
若设置已准确,则无需实行下列步调,否则实行下列步调举行修改。
- (2)修改最大设置
- # 命令格式:
- $IN500_HOME/tools/linux_arm/nic/config/hinicconfig <物理网卡设备名> -f <多中断队列配置文件>
- # 例如:
- cd $IN500_HOME/tools/linux_arm/nic/config/
- ./hinicconfig $HARD_DEV -f ./std_sh_4x25ge_dpdk_cfg_template0.ini # 64中断,本文场景下执行此命令
- # ./hinicconfig $HARD_DEV -f ./std_sh_4x25ge_dpdk_cfg_template0.ini # 16中断
复制代码 - (3)修改当前设置
- ethtool -L $CARD_NAME combined 24
复制代码 - (4)再次实行步调(1)举行设置确认。
2.3.3 网络停止绑核
在4路鲲鹏服务器中,共有8个NUMA节点、256核。将每个节点的末了3个核,共24个核用作网络停止,会有比力好的优化结果。
使用以下命令查看CPU与node环境:
停止绑核脚本如下:
- export CARD_NAME=enp71s0
- irq_list=`cat /proc/interrupts | grep $CARD_NAME | awk {'print $1'} | tr -d ":"`
- irq_array_net=($irq_list)
- cpu_array_irq=(29 30 31 61 62 63 93 94 95 125 126 127 157 158 159 189 190 191 221 222 223 253 254 255)
- for (( i=0;i<24;i++ ))
- do
- echo "${cpu_array_irq[$i]}" > /proc/irq/${irq_array_net[$i]}/smp_affinity_list
- done
- for j in ${irq_array_net[@]}
- do
- cat /proc/irq/$j/smp_affinity_list
- done
复制代码 将CARD_NAME改为实际值,保存为sh脚本bind_irq.sh 并实行完成停止绑定。
2.3.4 修改网卡参数
- ifconfig
- $CARD_NAME mtu 1500# 设置读写缓冲区ethtool -G $CARD_NAME rx 1024 tx 1024# 将网络分片offloading到网卡上ethtool –K $CARD_NAME tso onethtool –K $CARD_NAME lro onethtool –K $CARD_NAME gro onethtool –K $CARD_NAME gso on
复制代码 2.4 其他操纵体系设置
- 关闭不必要的服务
- service sysmonitor stop
- service irqbalance stop
- service rsyslog stop
- service firewalld stop
复制代码 - 关闭透明大页
- echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
- echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
复制代码 - 取消CPU平衡
- echo 0 > /proc/sys/kernel/numa_balancing
复制代码 - 调解内存脏页回收战略
- echo 3000 > /proc/sys/vm/dirty_expire_centisecs
- echo 500 > /proc/sys/vm/dirty_writeback_centisecs
- echo 60 > /proc/sys/vm/dirty_ratio
- echo 5 > /proc/sys/vm/dirty_background_ratio
复制代码 3、openGauss数据库设置
3.1 数据库安装与环境变量设置
(1)切换到数据库运行用户下(非root用户)。
(2)创建文件:
设置如下环境变量(env.txt):
- export GAUSSHOME=/home/my_user/package # openGauss 的安装目录
- export LD_LIBRARY_PATH=$GAUSSHOME/lib
- export PATH=$GAUSSHOME/bin:$PATH
- export DATA_NODE=/xxx/data # 数据库节点路径
- export XLOG=xxx/pg_xlog # 存放xlog的路径
- export TABLESPACE2=xxx/tablespace2 # 表空间路径2
- export TABLESPACE3=xxx/tablespace3 # 表空间路径3
- export DATA_BACK=xxx/data_back # 数据备份路径
复制代码 实行命令使环境变量生效
注意:
- DATA_NODE、XLOG、TABLESPACE2、TABLESPACE3 分别放到4个差异的 nvme 盘。
- XLOG发起放到最好的 nvme 盘。
- 以上路径不要同时存放其他数据,避免后续恢复数据时被删除。
(3)安装数据库
从 openGauss官网 下载安装包,按官网文档举行安装到 $GAUSSHOME 路径。
安装好后,初始化数据库节点到 $DATA_NODE 路径下。
3.1 修改pg_hpa.conf
在文件末尾增加以下内容,
- host tpcc1000 tpcc_bot xxx.xxx.xxx.xxx/32 sha256
复制代码 其中,
- tpcc1000 为后面创建的数据库名。
- tpcc_bot 为后面创建的数据库用户名。
- xxx.xxx.xxx.xxx 改为benchmark压测服务器的IP。
3.2 修改postgersql.conf
本节列举openGauss的主要GUC参数设置。主要注意事项如下:
- 在极限性能场景下,关闭用于调试等的无关功能。
- 打开 synchronous_commit、fsync参数保障数据安全落盘。
- 开启线程池,使用绑核设置。绑核编号中除去用于网络停止的核以及用于处理xlog的核。
enable_thread_pool = on thread_pool_attr = '696,8,(cpubind:1-28,32-60,64-92,96-124,128-156,160-188,192-220,224-252)'
- xlog落盘压力较大,干系线程单独绑核。
- xlog天生速率非常大,调解回收干系参数加快回收速率。
- 打开autovacuum。
- listen_addresses、port需要根据实际环境举行修改。
- wal_file_init_num 在天生数据阶段使用30,在跑TPCC阶段改为60000。
参考设置如下,参数具体含义可以在openGauss官网查阅:
3.3 创建压测数据库
(1)用绑核方式启动
-C参数指定绑核列表,参数与openGauss的线程池绑定参数一致。
- numactl -C 1-28,32-60,64-92,96-124,128-156,160-188,192-220,224-252 gs_ctl start -D $datadir -Z single_node
复制代码 (2)创建数据库
登录数据库,创建用于压测的用户及数据库。
注意与前面在pg_hba.conf设置的参数保持一致。
- create user tpcc_bot with sysadmin identified by 'my_password@123';
- create database tpcc1000 encoding='UTF-8' owner=tpcc_bot;
复制代码 完成后退出登录。
4、Benchmark设置
4.1 Benchmark 运行环境
用于运行Benchmark压测的服务器不需要很高的设置,只要包管不会成为瓶颈点即可。
本文所使用的客户端服务器设置为2Taishan 200服务器,CPU为Kunpeng-920 ARM aarch64(2socket*64core),内存765GB。
体系设置部分可以参考第二节《服务器优化设置》举行设置,其中停止设置保举为:最大停止数设置为64,使用停止数设置为48。
Benchmark-sql-5.0软件的安装可以参考 此文 ,本文不再赘述。
4.2 修改数据天生脚本
安装好Benchmark-sql-5.0后,进入运行路径 benchmarksql-5.0/run。
- (1)修改 sql.common/tableCreates.sql,组要修改如下:
- 增加2个表空间,bmsql_customer分配到 example2,bmsql_stock分配到 example3。
- 删除无用序列 bmsql_hist_id_seq。
- 修改表创建语句,给主要的表增加 FACTOR属性。
- 增加分区设置。
具体如下:
- CREATE TABLESPACE example2 relative location 'tablespace2';
- CREATE TABLESPACE example3 relative location 'tablespace3';
- create table bmsql_config (
- cfg_name varchar(30),
- cfg_value varchar(50)
- );
- create table bmsql_warehouse (
- w_id integer not null,
- w_ytd decimal(20,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)
- ) WITH (FILLFACTOR=80);
- create table bmsql_district (
- d_w_id integer not null,
- d_id integer not null,
- d_ytd decimal(20,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)
- ) WITH (FILLFACTOR=80);
- 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)
- ) WITH (FILLFACTOR=80) tablespace example2;
- -- 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)
- ) WITH (FILLFACTOR=80);
- create table bmsql_new_order (
- no_w_id integer not null,
- no_d_id integer not null,
- no_o_id integer not null
- ) WITH (FILLFACTOR=80);
- 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
- ) WITH (FILLFACTOR=80);
- 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)
- ) WITH (FILLFACTOR=80) tablespace example2
- partition by RANGE(ol_w_id)
- (
- partition bmsql_order_line_p1 values less than (126),
- partition bmsql_order_line_p2 values less than (251),
- partition bmsql_order_line_p3 values less than (376),
- partition bmsql_order_line_p4 values less than (501),
- partition bmsql_order_line_p5 values less than (626),
- partition bmsql_order_line_p6 values less than (751),
- partition bmsql_order_line_p7 values less than (876),
- partition bmsql_order_line_p8 values less than (1001)
- );
- 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)
- ) WITH (FILLFACTOR=80) tablespace example3
- partition by RANGE(s_w_id)
- (
- partition bmsql_stock_p1 values less than (126),
- partition bmsql_stock_p2 values less than (251),
- partition bmsql_stock_p3 values less than (376),
- partition bmsql_stock_p4 values less than (501),
- partition bmsql_stock_p5 values less than (626),
- partition bmsql_stock_p6 values less than (751),
- partition bmsql_stock_p7 values less than (876),
- partition bmsql_stock_p8 values less than (1001)
- );
复制代码
- (2)修改 sql.common/indexCreates.sql,改为如下:
- alter table bmsql_warehouse add constraint bmsql_warehouse_pkey
- primary key (w_id);
- alter table bmsql_district add constraint bmsql_district_pkey
- primary key (d_w_id, d_id);
- alter table bmsql_customer add constraint bmsql_customer_pkey
- primary key (c_w_id, c_d_id, c_id);
- create index bmsql_customer_idx1
- on bmsql_customer (c_w_id, c_d_id, c_last, c_first);
- alter table bmsql_oorder add constraint bmsql_oorder_pkey
- primary key (o_w_id, o_d_id, o_id);
- create index bmsql_oorder_idx1
- on bmsql_oorder (o_w_id, o_d_id, o_c_id);
- alter table bmsql_new_order add constraint bmsql_new_order_pkey
- primary key (no_w_id, no_d_id, no_o_id) using index tablespace example2;
- alter table bmsql_order_line add constraint bmsql_order_line_pkey
- primary key (ol_w_id, ol_d_id, ol_o_id, ol_number);
- alter table bmsql_stock add constraint bmsql_stock_pkey
- primary key (s_w_id, s_i_id);
- alter table bmsql_item add constraint bmsql_item_pkey
- primary key (i_id);
复制代码 - (3)修改数据天生脚本 runDatabaseBuild.sh,具体如下:
- #!/bin/sh
- Cwd=`cd $(dirname $0);pwd`
- if [ $# -lt 1 ] ; then
- echo "usage: $(basename $0) PROPS [OPT VAL [...]]" >&2
- exit 2
- fi
- PROPS="$1"
- shift
- if [ ! -f "${PROPS}" ] ; then
- echo "${PROPS}: no such file or directory" >&2
- exit 1
- fi
- DB="$(grep '^db=' $PROPS | sed -e 's/^db=//')"
- BEFORE_LOAD="tableCreates_4p"
- #AFTER_LOAD="indexCreates foreignKeys extraHistID buildFinish"
- AFTER_LOAD="indexCreates buildFinish"
- for step in ${BEFORE_LOAD} ; do
- $Cwd/runSQL.sh "${PROPS}" $step
- done
- $Cwd/runLoader.sh "${PROPS}" $*
- for step in ${AFTER_LOAD} ; do
- $Cwd/runSQL.sh "${PROPS}" $step
- done
复制代码 4.3 运行参数设置
进入路径 benchmarksql-5.0/run,复制一份设置文件并修改props_4p_5min.og,作为预热5分钟时使用。
- cp props.pg props_4p_5min.og
- vim props_4p_5min.og
复制代码 props_4p_5min.og:将ip、port、my_db_user_name、my_db_user_name改为实际值。
- db=postgres
- driver=org.postgresql.Driver
- conn=jdbc:postgresql://ip:port/tpcc1000?prepareThreshold=1&batchMode=on&fetchsize=10&loggerLevel=OFF
- user=my_db_user_name
- password=my_db_user_name
- warehouses=1000
- loadWorkers=80
- terminals=812
- //To run specified transactions per terminal- runMins must equal zero
- runTxnsPerTerminal=0
- //To run for specified minutes- runTxnsPerTerminal must equal zero
- runMins=5
- //Number of total transactions per minute
- limitTxnsPerMin=0
- //Set to true to run in 4.x compatible mode. Set to false to use the
- //entire configured database evenly.
- terminalWarehouseFixed=false
- //The following five values must add up to 100
- //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
- newOrderWeight=45
- paymentWeight=43
- orderStatusWeight=4
- deliveryWeight=4
- stockLevelWeight=4
复制代码 修改完成后保存,再复制一份为 props_4p_60min.og,并将 runMins 的值改为60,作为跑1小时TPCC使用。
- cp props_4p_5min.og props_4p_60min.og
- vim props_4p_60min.og
复制代码- db=postgres
- driver=org.postgresql.Driver
- conn=jdbc:postgresql://ip:port/tpcc1000?prepareThreshold=1&batchMode=on&fetchsize=10&loggerLevel=OFF
- user=my_db_user_name
- password=my_db_user_name
- warehouses=1000
- loadWorkers=80
- terminals=812
- //To run specified transactions per terminal- runMins must equal zero
- runTxnsPerTerminal=0
- //To run for specified minutes- runTxnsPerTerminal must equal zero
- runMins=60
- //Number of total transactions per minute
- limitTxnsPerMin=0
- //Set to true to run in 4.x compatible mode. Set to false to use the
- //entire configured database evenly.
- terminalWarehouseFixed=false
- //The following five values must add up to 100
- //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
- newOrderWeight=45
- paymentWeight=43
- orderStatusWeight=4
- deliveryWeight=4
- stockLevelWeight=4
复制代码 5、压测
5.1 数据天生
进入benchmark的run目次下,实行以下命令天生数据:
- numactl -C 0-19,32-51,64-83,96-115 ./runDatabaseBuild.sh props_4p_5min.og
复制代码 任务竣事后,待数据全部落盘,stop数据库。
将postgresql.conf 的 wal_file_init_num 参数改为 60000。
- echo "wal_file_init_num = 60000" >> $DATA_NODE/postgresql.conf
复制代码 5.2 数据备份
- cp -r $DATA_NODE $DATA_BACK
复制代码 5.3 数据分盘
- mv $DATA_NODE/pg_xlog $XLOG
- mv $DATA_NODE/pg_location/tablespace2 $TABLESPACE2
- mv $DATA_NODE/pg_location/tablespace3 $TABLESPACE3
- ln -svf $XLOG $DATA_NODE/pg_xlog
- ln -svf $TABLESPACE2 $DATA_NODE/pg_location/tablespace2
- ln -svf $TABLESPACE3 $DATA_NODE/pg_location/tablespace3
复制代码 5.4 以preferred方式绑核启动
(1)查看xlog盘对应的NUMA节点
比方 xlog 对应nvme0,则使用如下命令查看:
- cat /sys/class/nvme/nvme0/device/numa_node
复制代码
如上图所示,结果为0,阐明xlog盘对应的NUMA节点为0节点。
(2)绑核启动
通过以下命令启动openGauss数据库。
- numactl -C 1-28,32-60,64-92,96-124,128-156,160-188,192-220,224-252 --preferred=0 gs_ctl start -D $datadir -Z single_node
复制代码 其中,
- -C参数为绑核参数,参数与openGauss的线程池绑定列表一致。
- -p或--preferred参数为设置内存分配优先分配到 node 0 节点。
数据库启动成功后,通过以下命令查看numa的节点内存分配,将可以看到,node 0 剩余的内存是比其他节点要少的,阐明preferred参数设置生效,否则没有生效,可能会导致在差异的测试次数中大幅波动。
5.5 预热
在压测端实行以下命令举行5分钟预热:
- numactl -C 0-19,32-51,64-83,96-115 ./runBenchmark.sh props_4p_5min.og
复制代码 通过htop命令查看CPU环境,前面几分钟如下则正常,后面几分钟由于在初始化xlog文件,会降落到60%左右,属于正常现象。
预热5分钟 TPCC约为185万。
5.6正式压测
预热5分钟竣事再过10分钟,实行以下命令正式压测,终极TPCC达到230万以上。
- numactl -C 0-19,32-51,64-83,96-115 ./runBenchmark.sh props_4p_60min.og
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |