|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
系统管理相关命令:df、top、free、quota、at、lp、adduser、groupaddkill、crontab、tar、unzip、gunzip、last
前些天发明XEN假造机上的Nginx服务器存在一个成绩:软中止太高,并且年夜部分都会合在统一个CPU,一旦体系忙碌,此CPU就会成为木桶的短板。
<p>
在成绩服务器上运转「top」命令能够很分明看到「si」存在异常,年夜部分软中止都会合在1号CPU上,别的的CPU完整使不上劲儿:- shell>topCpu0:11.3%us,4.7%sy,0.0%ni,82.5%id,...0.8%si,0.8%stCpu1:21.3%us,7.4%sy,0.0%ni,51.5%id,...17.8%si,2.0%stCpu2:16.6%us,4.5%sy,0.0%ni,77.7%id,...0.8%si,0.4%stCpu3:15.9%us,3.6%sy,0.0%ni,79.3%id,...0.8%si,0.4%stCpu4:17.7%us,4.9%sy,0.0%ni,75.3%id,...1.2%si,0.8%stCpu5:23.6%us,6.6%sy,0.0%ni,68.1%id,...0.9%si,0.9%stCpu6:18.1%us,4.9%sy,0.0%ni,75.7%id,...0.4%si,0.8%stCpu7:21.1%us,5.8%sy,0.0%ni,71.4%id,...1.2%si,0.4%st
复制代码 查询一下软中止相干数据,发明次要会合在NET_RX上,推测是网卡成绩:- shell>watch-d-n1cat/proc/softirqsCPU0CPU1CPU2...CPU7HI:000...0TIMER:369256628436929600893692546970...3693032995NET_TX:130800410652649368154773818...308945843NET_RX:4436274923802219918792341500...2546517156BLOCK:000...0BLOCK_IOPOLL:000...0TASKLET:000...0SCHED:15187162953356295211520873304...1444792018HRTIMER:1601351131...196RCU:420129201939827611514184401659...4039269755
复制代码 增补:有一个检察中止(Interrupt)的top作风小工具itop。
确认一下宿主机上的网卡信息,发明其运转在单行列形式下:- shell>grep-A10-inetwork/var/log/dmesgInitalizingnetworkdropmonitorserviceIntel(R)GigabitEthernetNetworkDriver-version3.0.19igb0000:05:00.0:Intel(R)GigabitEthernetNetworkConnectionigb0000:05:00.0:eth0:(PCIe:2.5GT/s:Widthx4)00:1b:21:bf:b3:2cigb0000:05:00.0:eth0:PBANo:G18758-002igb0000:05:00.0:UsingMSI-X...1rxqueue(s),1txqueue(s)igb0000:05:00.1:Intel(R)GigabitEthernetNetworkConnectionigb0000:05:00.1:eth1:(PCIe:2.5GT/s:Widthx4)00:1b:21:bf:b3:2digb0000:05:00.1:eth1:PBANo:G18758-002igb0000:05:00.1:UsingMSI-X...1rxqueue(s),1txqueue(s)
复制代码 接着确认一下网卡的中止号,由于是单行列,以是只要一其中断号45:- shell>grepeth/proc/interrupts|awk{print$1,$NF}45:eth0
复制代码 晓得了网卡的中止号,就能够查询个中断亲缘性设置「smp_affinity」:- shell>cat/proc/irq/45/smp_affinity02
复制代码 这里的02实践上是十六进制,暗示1号CPU,盘算办法以下(参考材料):- BinaryHexCPU000011CPU100102CPU201004+CPU310008-----------------------both1111f
复制代码 申明:假如4个CPU都介入中止处置,那末设为f;同理8个CPU的就设置成ff:- shell>echoff>/proc/irq/45/smp_affinity
复制代码 别的另有一个相似的设置「smp_affinity_list」:- shell>cat/proc/irq/45/smp_affinity_list1
复制代码 两个设置是相通的,修正了一个,另外一个会随着变。不外「smp_affinity_list」利用的是十进制,比拟较「smp_affinity」的十六进制,可读性更好些。
懂得了这些基础常识,我们能够实验换一个CPU碰运气会产生甚么:- echo7>/proc/irq/45/smp_affinity_list
复制代码 再经由过程「top」命令察看,会发明处置软中止的CPU酿成了7号CPU。
申明:假如但愿多个CPU介入中止处置的话,可使用相似上面的语法:- echo3,5>/proc/irq/45/smp_affinity_listecho0-7>/proc/irq/45/smp_affinity_list
复制代码 坏动静是对单行列网卡而言,「smp_affinity」和「smp_affinity_list」设置多CPU有效。
好动静是Linux撑持RPS,普通点来讲就是在软件层面摹拟完成硬件的多行列网卡功效。
起首看看怎样设置RPS,假如CPU个数是8个的话,能够设置成ff:- shell>watch-d-n1cat/proc/softirqsCPU0CPU1CPU2...CPU7HI:000...0TIMER:369256628436929600893692546970...3693032995NET_TX:130800410652649368154773818...308945843NET_RX:4436274923802219918792341500...2546517156BLOCK:000...0BLOCK_IOPOLL:000...0TASKLET:000...0SCHED:15187162953356295211520873304...1444792018HRTIMER:1601351131...196RCU:420129201939827611514184401659...40392697550
复制代码 接着设置内核参数rps_sock_flow_entries(官方文档保举设置:32768):- shell>watch-d-n1cat/proc/softirqsCPU0CPU1CPU2...CPU7HI:000...0TIMER:369256628436929600893692546970...3693032995NET_TX:130800410652649368154773818...308945843NET_RX:4436274923802219918792341500...2546517156BLOCK:000...0BLOCK_IOPOLL:000...0TASKLET:000...0SCHED:15187162953356295211520873304...1444792018HRTIMER:1601351131...196RCU:420129201939827611514184401659...40392697551
复制代码 最初设置rps_flow_cnt,单行列网卡的话设置成rps_sock_flow_entries便可:- shell>watch-d-n1cat/proc/softirqsCPU0CPU1CPU2...CPU7HI:000...0TIMER:369256628436929600893692546970...3693032995NET_TX:130800410652649368154773818...308945843NET_RX:4436274923802219918792341500...2546517156BLOCK:000...0BLOCK_IOPOLL:000...0TASKLET:000...0SCHED:15187162953356295211520873304...1444792018HRTIMER:1601351131...196RCU:420129201939827611514184401659...40392697552
复制代码 申明:假如是多行列网卡,那末就依照行列数目设置成rps_sock_flow_entries/N。
做了如上的优化后,我们再运转「top」命令能够看到软中止已分离到了两个CPU:
如果你学不好的话,你在linux中开发的机会就很少,或者说几乎没有,它的优势就消失了,然后随着时间的流逝,你就会全部忘记她; |
|