日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取redis实例绑定cpu的情况

發(fā)布時間:2024/1/17 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取redis实例绑定cpu的情况 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

redis是一個單線模型的nosql類型的數(shù)據(jù)庫,而目前接觸到的服務(wù)器大都是多核的,比如8c,16c,32c,64c等等。為了充分利用主機(jī),在一臺主機(jī)上必然會部署多個redis實(shí)例,默認(rèn)情況cpu會隨機(jī)選擇,但經(jīng)過觀察自動選擇的時候很大情況下會選擇同一邏輯cpu,這樣導(dǎo)致cpu使用不均衡,撐得死了,餓的餓死了,怎么破。

?

其實(shí)可以對指定的進(jìn)程id進(jìn)行cpu綁定,綁定前的情況如下:

?

27001 instance bind on cpu 0-7 27002 instance bind on cpu 0-7 27003 instance bind on cpu 0-7 27004 instance bind on cpu 0-7 27005 instance bind on cpu 0-7 27007 instance bind on cpu 0-7 27008 instance bind on cpu 0-7

?

生成綁定的命令

ps aux|grep redis-server |grep -v grep |awk 'BEGIN {i=0}{i++}{print "taskset -pc " i, $2}'

  

綁定后的情況如下:

27001 instance bind on cpu 1 27002 instance bind on cpu 2 27003 instance bind on cpu 3 27004 instance bind on cpu 4 27005 instance bind on cpu 5 27007 instance bind on cpu 6 27008 instance bind on cpu 7

?

綁定后獲取cpu綁定情況的確認(rèn)腳本如下:

ps -ef |grep redis-server |grep -v grep | awk '$NF~/cluster/{print $2,$(NF-1);next}{print $2,$NF}' > pid_instancecat pid_instance | while read line dopid=$(echo $line | awk '{print $1}')port=$(echo $line | awk -F':' '{print $2}')echo "$port instance bind on cpu `taskset -pc $pid | awk -F':' '{print $2}'`" done rm -rf pid_instance

?

如果有很多臺redis實(shí)例,可以通過ansible分發(fā)該腳本到對應(yīng)的主機(jī)上,然后跑一下sh redis_cpu.sh xxx腳本,xxx文件中是以all為分組的redis主機(jī)列表,例如:

cat >redis_cpu.sh <<EOF #!/bin/bashansible -i $1 all -m copy -s -a "src=./get_redis_bind_cpu.sh dest=/tmp/get_redis_bind_cpu.sh" ansible -i $1 all -m shell -s -a "sh get_redis_bind_cpu.sh" EOFcat >get_redis_bind_cpu.sh <<EOF #!/bin/bashps -ef |grep redis-server |grep -v grep | awk '$NF~/cluster/{print $2,$(NF-1);next}{print $2,$NF}' > pid_instancecat pid_instance | while read line dopid=$(echo $line | awk '{print $1}')port=$(echo $line | awk -F':' '{print $2}')echo "$port instance bind on cpu `taskset -pc $pid | awk -F':' '{print $2}'`" done rm -rf pid_instance EOF

 

添加一下輸出優(yōu)化,直觀看出來是不是綁定了cpu

ps -ef |grep redis-server |grep -v grep | awk '$NF~/cluster/{print $2,$(NF-1);next}{print $2,$NF}' > pid_instancecat pid_instance | while read line dopid=$(echo $line | awk '{print $1}')port=$(echo $line | awk -F':' '{print $2}')bind_current=$(taskset -pc $pid | awk -F':' '{print $2}')total=$(cat /proc/cpuinfo |grep processor |wc -l)start=0let end=total-1bind_default="$start-$end"if [[ $bind_current -ne $bind_default ]];thenecho "$port instance bind on cpu $bind_current ok"elseecho "$port instance not set bind cpu default $bind_default,please check!!!"fi done rm -rf pid_instance

?

如果沒有綁定:

[root@testdb1 ~]# sh c.sh 6379 instance not set bind cpu default 0-23,please check!!! 29009 instance not set bind cpu default 0-23,please check!!! 29095 instance not set bind cpu default 0-23,please check!!! 27000 instance not set bind cpu default 0-23,please check!!! 27001 instance not set bind cpu default 0-23,please check!!! 29001 instance not set bind cpu default 0-23,please check!!! 29002 instance not set bind cpu default 0-23,please check!!! 29003 instance not set bind cpu default 0-23,please check!!! 29004 instance not set bind cpu default 0-23,please check!!! 29005 instance not set bind cpu default 0-23,please check!!! 29006 instance not set bind cpu default 0-23,please check!!! 29007 instance not set bind cpu default 0-23,please check!!! 29008 instance not set bind cpu default 0-23,please check!!! 29000 instance not set bind cpu default 0-23,please check!!!

?

如果有綁定

27183 instance bind on cpu 1 ok 27184 instance bind on cpu 2 ok 27185 instance bind on cpu 3 ok 27186 instance bind on cpu 4 ok 27187 instance bind on cpu 5 ok 27188 instance bind on cpu 6 ok 27189 instance bind on cpu 7 ok 27190 instance bind on cpu 8 ok 27191 instance bind on cpu 9 ok 27192 instance bind on cpu 10 ok 27193 instance bind on cpu 11 ok 27194 instance bind on cpu 11 ok 27195 instance bind on cpu 10 ok 27196 instance bind on cpu 9 ok 27197 instance bind on cpu 8 ok

?

@20190509

cat >get_redis_bind_cpu.sh <<EOF #!/bin/bashps -ef |grep redis-server |grep -v grep | awk '\$NF~/cluster/{print \$2,\$(NF-1);next}{print \$2,\$NF}' > pid_instancecat pid_instance | while read line dopid=\$(echo \$line | awk '{print \$1}')port=\$(echo \$line | awk -F':' '{print \$2}')bind_current=\$(taskset -pc \$pid | awk -F':' '{print \$2}')total=\$(cat /proc/cpuinfo |grep processor |wc -l)start=0let end=total-1bind_default="\$start-\$end"if [[ \$bind_current -ne \$bind_default ]];thenecho "\$port instance bind on cpu \$bind_current ok"elseecho "\$port instance not set bind cpu default \$bind_default,please check!!!" >> no_bind.logfi done rm -rf pid_instance EOFcat >redis_cpu.sh <<EOF #!/bin/bashansible -i \$1 all -m copy -s -a "src=./get_redis_bind_cpu.sh dest=/tmp/get_redis_bind_cpu.sh" > /dev/null ansible -i \$1 all -m shell -s -a "cd /tmp;sh get_redis_bind_cpu.sh" > /dev/null ansible -i \$1 all -m shell -s -a "ls -l /tmp/no_bind.log 2>/dev/null"EOFPS: 1.執(zhí)行前確保ansible到目標(biāo)所有redis實(shí)例的機(jī)器可以跑通。 2.執(zhí)行sh redis_cpu.sh redis_host |grep -v FAILED 3.有輸出的即是對應(yīng)主機(jī)上redis實(shí)例存在沒有綁定cpu的,具體實(shí)例端口在對應(yīng)機(jī)器的/tmp/no_bind.log

  

轉(zhuǎn)載于:https://www.cnblogs.com/imdba/p/10820068.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的获取redis实例绑定cpu的情况的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。