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

MogDB性能测试中如何对网卡和数据库绑核

正常情况下可以使用bind_net_irq.sh进行绑核。但是脚本毕竟只是针对通常情况,有时候网卡、CPU等的配置不是很标准的情况下,就需要进行手动绑核。

本文仅供内部使用,请勿外传。

1,考虑用多少个核给网卡

按照目前的经验,大概1/20的CPU个数,向上取numa的倍数

  • 查看CPU数、numa数
lscpu [root@Host1 run]# lscpu Architecture: aarch64 CPU op-mode(s): 64-bit Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Thread(s) per core: 1 Core(s) per socket: 64 Socket(s): 2 NUMA node(s): 3 Vendor ID: HiSilicon
  • 设定CPU核

根据numa分布,均匀取N个核,多数取1/20左右,手动即可,目前mogdb/opengauss在优化中默认取每个numa里的最后几个

lscpu -e=cpu,node CPU NODE 0 0 1 0 2 0 3 0 4 0 5 0 62 0 63 0 64 1 65 1 66 1 93 1 94 1 95 1 96 2 97 2 98 2 125 2 126 2 127 2

本例建议 8个核给网卡。
分别是 60 61 62 63 94 95 126 127
存入变量

net_cpus=(60 61 62 63 94 95 126 127)

2,确定哪个网卡

  • 通常建议万兆以上
ip link | grep LOWER_UP 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 2: enp125s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 10: enp129s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 5500 qdisc mq state UP mode DEFAULT group default qlen 1000 11: enp129s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 5500 qdisc mq state UP mode DEFAULT group default qlen 1000 12: enp130s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 14: enp129s0f0.2@enp129s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 5500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 15: enp129s0f1.2@enp129s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 5500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 * ip a | grep 内网IP(前3位就可以) [root@Host1 run]# ip a | grep 31.31.31 inet 31.31.31.1/16 brd 31.31.255.255 scope global noprefixroute enp130s0f0

可以获取当前所用的网卡,本例enp130s0f0

  • ethtool 网卡名
ethtool enp130s0f0 ethtool enp130s0f0|grep Speed [root@Host1 run]# ethtool enp130s0f0 Settings for enp130s0f0: Supported ports: [ FIBRE ] Supported link modes: 1000baseKX/Full 10000baseKR/Full 25000baseCR/Full 25000baseKR/Full 25000baseSR/Full Supported pause frame use: Symmetric Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 1000baseKX/Full 10000baseKR/Full 25000baseCR/Full 25000baseKR/Full 25000baseSR/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 25000Mb/s Duplex: Full Port: FIBRE PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: d Wake-on: d Current message level: 0x00000004 (4) link Link detected: yes [root@Host1 run]# ethtool enp130s0f0|grep Speed Speed: 25000Mb/s

可以获取当前速度,当前是25000Mb/s,符合要求,如果不是万兆或以上,可以看看有没有其他符合条件的网卡,配上IP

3, 获取网卡 irq列表,设置网卡特性

  • 设置网卡特性
net_dev=网卡名 ethtool -K $net_dev tso on ethtool -K $net_dev lro on ethtool -K $net_dev gro on ethtool -K $net_dev gso on
  • 设置网卡irq数(不一定成功)
ethtool -L $net_dev combined 《第一步确定的核数》
  • 获取网卡bus
ethtool -i $net_dev | grep bus-info [root@Host1 run]# ethtool -i $net_dev | grep bus-info bus-info: 0000:82:00.0 bus=`ethtool -i $net_dev | awk '/bus-info/{print $2}'`
  • 获取irq列表
egrep "$net_dev|$bus" /proc/interupt |awk -F: '{print $1}' [root@Host1 run]# egrep "$net_dev|$bus" /proc/interrupts |awk -F: '{print $1}' 1243 1244 1245 1247 1248 1249 1250 1251 1252 1253 1254 1255

如果设置网卡irq数成功,出来的长度和核数,如果不成功,也没办法,除非升级网卡驱动,不过问题也不大

  • 把irq存入变量
net_irqs=(`egrep "$net_dev|$bus" /proc/interrupts |awk -F: '{print $1}'`) echo ${net_irqs[*]}

4, 进行绑核

绑核的操作其实是设置

/proc/irq/<irq号>/smp_affinity_list echo cpu号 > /proc/irq/<irq号>/smp_affinity_list

前面两个变量 net_irqs net_cpus匹配放进去即可

cpuid=0 cpucnt=${#net_cpus[*]} for irq in ${net_irqs[*]} ; do echo ${net_cpus[$cpuid]} > /proc/irq/$irq/smp_affinity_list ((cpuid=cpuid+1)) ((cpuid=cpuid%cpucnt)) done

5, 检查绑核效果

for irq in ${net_irqs[*]} ; do echo $irq: `cat /proc/irq/$irq/smp_affinity_list` done | sort -k 2 -n

6 设定数据库绑核

可用于数据库的CPU核,就是所有CPU去掉0号给walwriter, 以及分配给网络部分
并发个数,正常情况下,最佳性能出现在3倍可用CPU核上

walwriter_cpu_bind=0
thread_pool_attr = '并发数,numa数,(cpubind:去除号给walwriter, 以及分配给网络部分)'

比如本例,核数128, 0号给walwriter, 8个给网络,就是

128-1-8=119
119*3=357
net_cpus=(60 61 62 63 94 95 126 127) walwriter_cpu_bind=0 thread_pool_attr = '357,3,(cpubind:1-59,64-93,96-125)'

7,手动数据库进程绑核

有些时候,不想使用thread_pool,或者thread_pool有问题没法正常绑核,也可以通过手动的方式进行绑核

  • 获取数据库线程
top -H -b -n 1 -p `pidof -S , mogdb`

其中 -H是展开线程, -b是顺序显示而不是传统top的单屏幕刷新, -n 1是只显示1次, -p 是指定进程号
当然,如果机器上不止一个mogdb,可以手动寻找一下,替换进去

top -H -b -n 1 -p 4083279 [root@node156 ~]# top -H -b -n 1 -p `pidof -S , mogdb` top - 10:38:58 up 91 days, 17:09, 2 users, load average: 0.05, 0.07, 0.08 Threads: 64 total, 0 running, 64 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 127768.5 total, 47920.1 free, 4010.0 used, 75838.5 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 78785.1 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4083279 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 6,45 mogdb 4083282 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.00 jemalloc_bg_thd 4083294 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.00 mogdb 4083295 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:06.78 syslogger 4083296 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.00 jemalloc_bg_thd 4083297 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 1:38.80 alarm 4083298 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.57 reaper 4083299 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.00 jemalloc_bg_thd 4083300 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.00 jemalloc_bg_thd 4083306 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 1:16.95 checkpointer 4083307 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.09 Spbgwriter 4083308 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 8:00.47 pagewriter 4083309 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:14.26 pagewriter 4083310 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:04.39 pagewriter 4083311 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:06.16 pagewriter 4083312 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:04.92 pagewriter 4083313 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 59:25.78 WALwriter 4083314 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:00.26 WALwriteraux 4083315 eal4 20 0 12.0g 2.8g 2.2g S 0.0 2.2 0:10.21 AVClauncher
  • 生成可用cpu核列表.
    可以通过多个seq生成
db_cpus=(`seq 1 59;seq 64 93;seq 96 125`)
  • 进行手动绑核
    手动绑核的关键语句在于taskset命令
    taskset -p 是显示线程/进程CPU亲和性列表
    taskset -pc <CPU核> 是设置PU亲和性,也就是绑核

如果没使用线程池,需要等会话都连上才可以生效

  • 完整脚本:
db_cpus=(`seq 1 59;seq 64 93;seq 96 125`) cpuid=0 db_cpus_cnt=${#db_cpus[*]} top -H -b -n 1 -p `pidof -S , mogdb` | grep -i WalWri | while read pid dummy; do echo taskset -pc 0 $pid done top -H -b -n 1 -p `pidof -S , mogdb` | grep -i worker | while read pid dummy; do echo taskset -pc ${db_cpus[$cpuid]} $pid ((cpuid=cpuid+1)) ((cpuid=cpuid%db_cpus_cnt)) done

综合脚本

脚本1,获取可用网卡信息

ip link | egrep -v "veth|lo:" | awk -F: '/LOWER_UP/{print $2}' | while read eth ; do eth=`echo $eth` speed=`ethtool $eth|awk '/Speed/{print $2}'` ip=`ip addr show dev $eth|awk '/inet /{print $2}'` printf "dev: %-20s speed: %-20s ip: %s\n" $eth $speed $ip done

脚本2,网卡优化及绑核

#手动设置两个参数 net_cpus=(54 55 110 111 174 175 238 239) net_dev=enP72p1s0f0 cpucnt=${#net_cpus[*]} ethtool -K $net_dev tso on ethtool -K $net_dev lro on ethtool -K $net_dev gro on ethtool -K $net_dev gso on ethtool -L combined $cpucnt combined_ret=$({ ethtool -L $net_dev combined $net_cores > error.txt; } 2>&1) #获取eth bus bus=`ethtool -i $net_dev | awk '/bus-info/{print $2}'` #获取net_irqs net_irqs=(`egrep "$net_dev|$bus" /proc/interrupts |awk -F: '{print $1}'`) cpuid=0 #绑核 for irq in ${net_irqs[*]} ; do echo ${net_cpus[$cpuid]} > /proc/irq/$irq/smp_affinity_list ((cpuid=cpuid+1)) ((cpuid=cpuid%cpucnt)) done #绑核结果 for irq in ${net_irqs[*]} ; do echo $irq: `cat /proc/irq/$irq/smp_affinity_list` done | sort -k 2 -n

脚本3,手动绑定进程(非必要)

#手动设置可用CPU db_cpus=(`seq 1 53;seq 56 109;seq 112 173;seq 176 237`) #WALWriter绑核 top -H -b -n 1 -p `pidof -S , mogdb` | grep -i WalWri | while read pid dummy; do echo taskset -pc 0 $pid done #worker进程绑核(包括TPLWorker/普通Worker) cpuid=0 db_cpus_cnt=${#db_cpus[*]} top -H -b -n 1 -p `pidof -S , mogdb` |sort -nr -k 1| grep -i worker | while read pid dummy; do taskset -pc ${db_cpus[$cpuid]} $pid ((cpuid=cpuid+1)) ((cpuid=cpuid%db_cpus_cnt)) done
最后修改时间:2023-11-17 17:49:45
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论