欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 5882|回复: 3
收起左侧

DNS压力测试脚本说明(版本2)

[复制链接]
wushen 发表于 2016-2-22 15:27 | 显示全部楼层 |阅读模式
本帖最后由 wushen 于 2016-2-23 17:50 编辑

[tex=md]# DNS压力测试脚本说明(版本2)
##版本2中的新功能
* 提高了统计效率
* 更改逻辑结构,现在可以统计多种数据了
* 可以统计的数据有:发送总数、成功数、失败数和速率
* 删除脚本queryperf_parallel,并收录进脚本queryperf_parallels
* 更改了脚本的运行方式,使其更加统一

##简要说明
压力脚本的核心是并行运行多个queryperf进程,发出大量的DNS请求包,以查看其处理性能  
文件清单  

脚本名|功能|使用说明
-----|-----|-----
queryperf_polling|以轮询的方式运行|./queryperf_polling t n (t表示每轮运行时间,n表示queryperf轮询最大数量)
queryperf_parallels|可自定义并发数运行|./queryperf_parallels t n1 n2...         (t表示每轮运行时间,n1、n2...表示queryperf轮询数量)
runallstress.sh|启动压力|被以上脚本所调用
stopallstress.sh|停止压力进程|同上(偶尔会出现类似提示`./kill.sh: line 9: kill: (31683) - No such process`不影响测试)
analysis_results.sh|分析日志|同上
extract_persec.sh|分析日志|同上
countsum.sh|分类求和|同上
statistics.sh| 统计求和信息|同上
test_dns.sh|指定目标测试机|更改脚本内的ip地址,来更改目标测试机
killallstress.sh|还原测试环境|./killallstress.sh 如果压力测试被中断,请运行该脚本
*.com.test|域名文件|测试所用到域名,都放在这里


##queryperf_polling
该脚本可以逐步增加queryperf的并行数量,通过比较运行结果来探寻最合适的压力数量  
> 比方说运行./queryperf_polling 100 3   
> 代表一共运行3轮,每轮运行100秒  
第一轮运行1个queryperf,运行100秒后统计分析数据,并将统计结果打印在屏幕上  
第二轮运行2个queryperf,运行100秒后统计分析数据,并将统计结果打印在屏幕上  
第三轮运行3个queryperf,运行100秒后统计分析数据,并将统计结果打印在屏幕上  
运行结束后会将总统计结果打印在屏幕上

逻辑图:
![](http://7xr4e0.com1.z0.glb.clouddn.com/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95%E6%B5%81%E7%A8%8B%E5%89%AF%E6%9C%AC-20.png)

##queryperf_parallels
可以单独定义每轮测试所使用的queryperf并发数
> 比如运行./queryperf_parallels 100 3 4  
> 代表一共运行2轮,每轮运行100秒  
第一轮运行3个queryperf,运行100秒后统计分析数据,并将统计结果打印在屏幕上  
第二轮运行4个queryperf,运行100秒后统计分析数据,并将统计结果打印在屏幕上   
运行结束后会将总统计结果打印在屏幕上  

逻辑图:

![](http://7xr4e0.com1.z0.glb.clouddn.com/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95%E6%B5%81%E7%A8%8B%E5%89%AF%E6%9C%AC-4.png)

##运行样例
> 注:实际测试时,不会只用10秒

````
[root@EnlinkDNS test-shell]# ./queryperf_polling 10 2
*---------------------------------------*
*                                       *
*    SDNS Stress Test Program Start!    *
*                                       *
*---------------------------------------*
queryperf1_163_sent =  75692
queryperf1_qq_sent =  0
queryperf1_ganji_sent =  16560
queryperf1_baidu_sent =  35568
queryperf1_taobao_sent =  53800
queryperf1_youku_sent =  44128
queryperf1_sina_sent =  30000
queryperf1_163_completed =  75692
queryperf1_qq_completed =  0
queryperf1_ganji_completed =  16560
queryperf1_baidu_completed =  35568
queryperf1_taobao_completed =  53800
queryperf1_youku_completed =  44128
queryperf1_sina_completed =  30000
queryperf1_163_lost =  0
queryperf1_qq_lost =  0
queryperf1_ganji_lost =  0
queryperf1_baidu_lost =  0
queryperf1_taobao_lost =  0
queryperf1_youku_lost =  0
queryperf1_sina_lost =  0
queryperf1_163_persec =  12112
queryperf1_qq_persec =  0
queryperf1_ganji_persec =  10825.7
queryperf1_baidu_persec =  10409.8
queryperf1_taobao_persec =  12225.9
queryperf1_youku_persec =  12037.5
queryperf1_sina_persec =  10586.1
=========================================
queryperf1_163_sent =  77216
queryperf1_qq_sent =  7238
queryperf1_ganji_sent =  22080
queryperf1_baidu_sent =  23598
queryperf1_taobao_sent =  75858
queryperf1_youku_sent =  44128
queryperf1_sina_sent =  33625
queryperf1_163_completed =  77216
queryperf1_qq_completed =  7238
queryperf1_ganji_completed =  22080
queryperf1_baidu_completed =  23598
queryperf1_taobao_completed =  75858
queryperf1_youku_completed =  44128
queryperf1_sina_completed =  33625
queryperf1_163_lost =  0
queryperf1_qq_lost =  0
queryperf1_ganji_lost =  0
queryperf1_baidu_lost =  0
queryperf1_taobao_lost =  0
queryperf1_youku_lost =  0
queryperf1_sina_lost =  0
queryperf1_163_persec =  10783.4
queryperf1_qq_persec =  901.448
queryperf1_ganji_persec =  8063.31
queryperf1_baidu_persec =  7968.39
queryperf1_taobao_persec =  10591.8
queryperf1_youku_persec =  9725.34
queryperf1_sina_persec =  7880.42
queryperf2_163_sent =  77216
queryperf2_qq_sent =  517
queryperf2_ganji_sent =  31440
queryperf2_baidu_sent =  16530
queryperf2_taobao_sent =  40888
queryperf2_youku_sent =  4728
queryperf2_sina_sent =  32250
queryperf2_163_completed =  77216
queryperf2_qq_completed =  517
queryperf2_ganji_completed =  31440
queryperf2_baidu_completed =  16530
queryperf2_taobao_completed =  40888
queryperf2_youku_completed =  4728
queryperf2_sina_completed =  32250
queryperf2_163_lost =  0
queryperf2_qq_lost =  0
queryperf2_ganji_lost =  0
queryperf2_baidu_lost =  0
queryperf2_taobao_lost =  0
queryperf2_youku_lost =  0
queryperf2_sina_lost =  0
queryperf2_163_persec =  10667
queryperf2_qq_persec =  51.2323
queryperf2_ganji_persec =  8138.35
queryperf2_baidu_persec =  8359.92
queryperf2_taobao_persec =  10452
queryperf2_youku_persec =  7556.7
queryperf2_sina_persec =  7884.31
=========================================
Mission Complete!
round1_total_sent: 255748
round1_total_completed: 255748
round1_total_lost: 0
round1_total_persec: 68197
round2_total_sent: 487312
round2_total_completed: 487312
round2_total_lost: 0
round2_total_persec: 109024
````

###统计
轮数|总发出量|成功数|失败数|速率(次/秒)
:----:|:--------:|:----:|:----:|:----:
第一轮|255748|255748|0|68197
第二轮|487312|487312|0|109024

##脚本
**queryperf_polling**

````
#! /bin/bash
echo   "*---------------------------------------*"
echo   "*                                       *"
echo   "*    SDNS Stress Test Program Start!    *"
echo   "*                                       *"
echo   "*---------------------------------------*"
rm -rf /root/queryperf.*
idx1=1
while [ $idx1 -lt `expr $2 + 1` ]
do
cp -r /root/queryperf /root/queryperf.$idx1
idx1=$(expr $idx1 + 1)
done
idx2=1
while [ $idx2 -lt `expr $2 + 1` ]
do
./runallstress.sh $idx2
sleep $1
./stopallstress.sh
sleep 10
./analysis_results.sh $idx2
./countsum.sh $idx2
./statistics.sh $idx2
idx2=$(expr $idx2 + 1)
echo =========================================
done
echo Mission Complete!
idx3=1
while [ $idx3 -lt `expr $2 + 1` ]
do
cat ./record/$idx3.total.sent
cat ./record/$idx3.total.completed
cat ./record/$idx3.total.lost
cat ./record/$idx3.total.persec
idx3=$(expr $idx3 + 1)
done
rm -rf /root/queryperf.*
````

**queryperf_parallels**

````
#! /bin/bash
flag=1
for var in $*
do
if [ $flag -ne 1 ]
then
echo   "*---------------------------------------*"
echo   "*                                       *"
echo   "*    SDNS Stress Test Program Start!    *"
echo   "*                                       *"
echo   "*---------------------------------------*"
rm -rf /root/queryperf.*
idx1=1
while [ $idx1 -lt `expr $var + 1` ]
do
cp -r /root/queryperf /root/queryperf.$idx1
idx1=$(expr $idx1 + 1)
done
./runallstress.sh $var
sleep $1
./stopallstress.sh
sleep 10
./analysis_results.sh $var
./countsum.sh $var
./statistics.sh $var
echo =========================================
echo Mission Complete!
cat ./record/$var.total.sent
cat ./record/$var.total.completed
cat ./record/$var.total.lost
cat ./record/$var.total.persec
rm -rf /root/queryperf.*
fi
let flag=$flag+1
done
````
**runallstress.sh**

```
#! /bin/bash
idx=1
while [ $idx -lt `expr $1 + 1` ]
do
cd /root/queryperf.$idx/test-shell/nohup
rm -f nohup.*
cd /root/queryperf.$idx/test-shell/sent
rm -f sent.*
cd /root/queryperf.$idx/test-shell/completed
rm -f completed.*
cd /root/queryperf.$idx/test-shell/lost
rm -f lost.*
cd /root/queryperf.$idx/test-shell/persec
rm -f persec.*
cd /root/queryperf.$idx/test-shell
nohup ./test_dns.sh 163.com.test >./nohup/nohup.163 2>&1 &
nohup ./test_dns.sh qq.com.test >./nohup/nohup.qq 2>&1 &
nohup ./test_dns.sh ganji.com.test >./nohup/nohup.ganji 2>&1 &
nohup ./test_dns.sh baidu.com.test >./nohup/nohup.baidu 2>&1 &
nohup ./test_dns.sh taobao.com.test >./nohup/nohup.taobao 2>&1 &
nohup ./test_dns.sh youku.com.test >./nohup/nohup.youku 2>&1 &
nohup ./test_dns.sh sina.com.test >./nohup/nohup.sina 2>&1 &
idx=$(expr $idx + 1)
done
```
**test_dns.sh**

```
#/bin/bash

while [ 1==1 ]
do
        ../queryperf -d $1 -s 192.168.5.140
done
```

**stopallstress.sh**

```
#! /bin/bash
ps -ef | grep test | grep -v quer | grep -v grep | awk '{print $2}' > ps
echo "#! /bin/bash" > kill.sh
cat ps | while read line
do
pstest=$(echo $line |awk '{print $1}')
echo "kill -9 $pstest" >> kill.sh
done
./kill.sh
sleep 2
ps -ef | grep test | grep -v grep | awk '{print $2}' > killquery
echo "#! /bin/bash" > kill.sh
cat killquery | while read myline
do
query=$(echo $myline |awk '{print $1}')
echo "kill -9 $query" >> kill.sh
done
./kill.sh
```

**analysis_results.sh**

```
#! /bin/bash
idx=1
while [ $idx -lt `expr $1 + 1` ]
do
cd /root/queryperf.$idx/test-shell/
./extract_persec.sh 163
./extract_persec.sh qq
./extract_persec.sh ganji
./extract_persec.sh baidu
./extract_persec.sh taobao
./extract_persec.sh youku
./extract_persec.sh sina
idx=$(expr $idx + 1)
done
```

**extract_persec.sh**

```
#! /bin/bash
t1=$(cat ./nohup/nohup.${1} | grep 'Queries sent' | awk '{print $3}')
echo "$t1" >> ./sent/sent.${1}
t2=$(cat ./nohup/nohup.${1} | grep 'Queries completed' | awk '{print $3}')
echo "$t2" >> ./completed/completed.${1}
t3=$(cat ./nohup/nohup.${1} | grep 'Queries lost' | awk '{print $3}')
echo "$t3" >> ./lost/lost.${1}
t4=$(cat ./nohup/nohup.${1} | grep 'Queries per second' | awk '{print $4}')
echo "$t4" >> ./persec/persec.${1}
```

**countsum.sh**

```
#!/bin/bash
idx=1
str=(163 qq ganji baidu taobao youku sina)
while [ $idx -lt `expr $1 + 1` ]
do
cd /root/queryperf.$idx/test-shell/sent
for var in ${str
  • }
    do
    cat sent.$var |awk '{sum+=$1} END {print "queryperf'$idx'_'$var'_sent = ", sum}'
    done
    cd /root/queryperf.$idx/test-shell/completed
    for var in ${str
  • }
    do
    cat completed.$var |awk '{sum+=$1} END {print "queryperf'$idx'_'$var'_completed = ", sum}'
    done
    cd /root/queryperf.$idx/test-shell/lost
    for var in ${str
  • }
    do
    cat lost.$var |awk '{sum+=$1} END {print "queryperf'$idx'_'$var'_lost = ", sum}'
    done
    cd /root/queryperf.$idx/test-shell/persec
    for var in ${str
  • }
    do
    cat persec.$var |awk '{sum+=$1} END {print "queryperf'$idx'_'$var'_persec = ", sum/NR}'
    done
    idx=$(expr $idx + 1)
    done
    ```

    **statistics.sh**

    ```
    #! /bin/bash
    echo `./countsum.sh $1 | grep sent | awk '{print $3}'` >./record/sent.$1
    cat ./record/sent.$1 | awk '{for(i=1;i<=NF;i++)sum[NR]+=$i;print  "round'$1'_total_sent:",sum[NR]}' > ./record/$1.total.sent
    echo `./countsum.sh $1 | grep completed | awk '{print $3}'` >./record/completed.$1
    cat ./record/completed.$1 | awk '{for(i=1;i<=NF;i++)sum[NR]+=$i;print  "round'$1'_total_completed:",sum[NR]}' > ./record/$1.total.completed
    echo `./countsum.sh $1 | grep lost | awk '{print $3}'` >./record/lost.$1
    cat ./record/lost.$1 | awk '{for(i=1;i<=NF;i++)sum[NR]+=$i;print  "round'$1'_total_lost:",sum[NR]}' > ./record/$1.total.lost
    echo `./countsum.sh $1 | grep persec | awk '{print $3}'` >./record/persec.$1
    cat ./record/persec.$1 | awk '{for(i=1;i<=NF;i++)sum[NR]+=$i;print  "round'$1'_total_persec:",sum[NR]}' > ./record/$1.total.persec
    ```

    **killallstress.sh**

    ```
    #! /bin/bash
    ./stopallstress.sh
    killall -9 queryperf_*
    rm -rf /root/queryperf.*
    ```

    ***.com.test**

    本人收集了很多域名,其中有部分是暴力算出来的
    包括163、baidu、ganji、qq、taobao、youku、sina
    ******
    cat 163.com.test
    ```
    a.163.com A
    _xiaohan.blog.163.com A
    _zhong_wen_.blog.163.com A
    0.01wa.blog.163.com A
    0.395.blog.163.com A
    0_world.blog.163.com A
    ....
    ```

    参考格式

    ```
    blog.host.com A
    host.com NS
    host.com MX
    ftp.host.com TXT
    nice.host.com CNAME
    1-host.com ANY
    1.0-127.35.195.200.in-addr.arpa PTR
    ```[/tex]
  •  楼主| wushen 发表于 2016-2-24 12:07 | 显示全部楼层
    [tex=md][tex=md]#轮训测试
    ##功能
    发送指定数量的dns查询包,并统计第一行返回值
    ##使用方法
    使用方法 ./polling.sh n domain   n代表总次数,domain为需要测试的域名  
    注:根据实际测试环境,需对脚本中的内容进行微调   
    ##脚本

    ```
    [root@EnlinkDNS ~]# cat polling.sh
    #! /bin/bash
    TMP_FILE="mktemp /tmp/polling.XXXXXXXX"
    polling=`$TMP_FILE`
    idx=0
    while [ $idx -lt $1 ]
    do
    dig -t A $2 @192.168.5.140  +noall +answer | awk 'NR==4{print}' |awk '{print $5}' >> $polling
    idx=$(expr $idx + 1)
    done
    echo total: $1
    sort $polling | uniq -c | awk '{print $2 " appear times: " $1}'
    rm -f $polling

    ````
    ##运行结果

    ```
    [root@EnlinkDNS ~]# ./polling.sh 100 www.eee.com
    total: 100
    1.1.1.1 appear times: 30
    2.2.2.2 appear times: 38
    3.3.3.3 appear times: 32

    ```

    [/tex][/tex]
     楼主| wushen 发表于 2016-2-24 12:08 | 显示全部楼层
    [tex=md]#轮训测试
    ##功能
    发送指定数量的dns查询包,并统计第一行返回值
    ##使用方法
    使用方法 ./polling.sh n domain   n代表总次数,domain为需要测试的域名  
    注:根据实际测试环境,需对脚本中的内容进行微调   
    ##脚本

    ```
    [root@EnlinkDNS ~]# cat polling.sh
    #! /bin/bash
    TMP_FILE="mktemp /tmp/polling.XXXXXXXX"
    polling=`$TMP_FILE`
    idx=0
    while [ $idx -lt $1 ]
    do
    dig -t A $2 @192.168.5.140  +noall +answer | awk 'NR==4{print}' |awk '{print $5}' >> $polling
    idx=$(expr $idx + 1)
    done
    echo total: $1
    sort $polling | uniq -c | awk '{print $2 " appear times: " $1}'
    rm -f $polling

    ````
    ##运行结果

    ```
    [root@EnlinkDNS ~]# ./polling.sh 100 www.eee.com
    total: 100
    1.1.1.1 appear times: 30
    2.2.2.2 appear times: 38
    3.3.3.3 appear times: 32

    ```

    [/tex]






     楼主| wushen 发表于 2016-2-24 12:09 | 显示全部楼层
    [tex=md]#轮训测试
    ##功能
    发送指定数量的dns查询包,并统计第一行返回值
    ##使用方法
    使用方法 ./polling.sh n domain   n代表总次数,domain为需要测试的域名  
    注:根据实际测试环境,需对脚本中的内容进行微调   
    ##脚本

    ```
    [root@EnlinkDNS ~]# cat polling.sh
    #! /bin/bash
    TMP_FILE="mktemp /tmp/polling.XXXXXXXX"
    polling=`$TMP_FILE`
    idx=0
    while [ $idx -lt $1 ]
    do
    dig -t A $2 @192.168.5.140  +noall +answer | awk 'NR==4{print}' |awk '{print $5}' >> $polling
    idx=$(expr $idx + 1)
    done
    echo total: $1
    sort $polling | uniq -c | awk '{print $2 " appear times: " $1}'
    rm -f $polling

    ````
    ##运行结果

    ```
    [root@EnlinkDNS ~]# ./polling.sh 100 www.eee.com
    total: 100
    1.1.1.1 appear times: 30
    2.2.2.2 appear times: 38
    3.3.3.3 appear times: 32

    ```[/tex]
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

    GMT+8, 2024-11-25 13:13 , Processed in 0.061058 second(s), 10 queries , Redis On.

    Powered by Discuz! X3.4

    Copyright © 2001-2023, Tencent Cloud.

    快速回复 返回顶部 返回列表