• nginx的压力测试


    #-----------http_load讲解------------------------------------#
       Web服务器压力测试工具常见的有http_load、webbench、ab和Siege,
    我今天主要跟大家分享一下,我在工作中对http_load使用的总结。

    一、下载http_load
        下载地址:http://www.acme.com/software/http_load/http_load-12mar2006.tar.gz
    二、安装http_load
        tar zxvf http_load-12mar2006.tar.gz
        cd http_load-12mar2006
        make && make install
    三、使用http_load
        命令格式:http_load  -p 并发访问进程数  -s 访问时间  需要访问的URL文件
        比如:http_load -p 5 -s 60   url.tx
        或者  http_load -parallel 5 -seconds 60 url.txt
    四、参数讲解
        -parallel 简写-p :含义是并发的用户进程数。
        -fetches 简写-f :含义是总计的访问次数
        -rate    简写-p :含义是每秒的访问频率
        -seconds简写-s :含义是总计的访问时间
    五、URL文件格式
        URL文件:url.txt,文件格式是每行一个URL,URL最好超过50-100个测试效果比较好.文件格式
        如下:
        http.www.bdkyr.com/5k.html
        http.www.bdkyr.com/10k.html
        http.www.bdkyr.com/15k.html
        http.www.bdkyr.com/20k.html
    六、使用范例
        例如:
       [root@node2 http_load]# ./http_load -p 2 -s 10  url.txt
       49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds 
       5916 mean bytes/connection
       4.89274 fetches/sec, 28945.5 bytes/sec
       msecs/connect 28.8932 mean, 44.243 max, 24.488 min
       msecs/first-response 63.5362 mean, 81.624 max, 57.803 minHTTP response codes code 200 — 49 

    结果分析:
    1.49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
       说明在上面的测试中运行了49个请求,最大的并发进程数是2,总计传输
       的数据是289884bytes,运行的时间是10.0148秒

    2.5916 mean bytes/connection
       说明每一连接平均传输的数据量28988449=5916

    3.4.89274 fetches/sec, 28945.5 bytes/sec
       说明每秒的响应请求为4.89274,每秒传递的数据为28945.5 bytessec

    4.msecs/connect 28.8932 mean, 44.243 max, 24.488 min
       说明每连接的平均响应时间是28.8932 msecs,最大的响应时
       间44.243 msecs,最小的响应时间24.488 msecs

    5.msecs/first-response 63.5362 mean, 81.624 max, 57.803 min

    6、HTTP response codes code 200 — 49     
       说明打开响应页面的类型,如果403的类型过多,那可能
       要注意是否系统遇到了瓶颈。

    七、特殊说明:
           测试结果中主要的指标是 fetchessec、msecs/connect 这个选项,即服
       务器每秒能够响应的查询次数,用这个指标来衡量性能。似乎比 apache的ab准
       确率要高一些,也更有说服力一些。

           Qpt-每秒响应用户数和response time,每连接响应用户时间。
       测试的结果主要也是看这两个值。当然仅有这两个指标并不能完成对性能的分析,
       我们还需要对服务器的cpu、men进行分析,才能得出结论

    httpload的用法

    官方网站http://www.acme.com/software/http_load/
    一、安装
    $ wget http://acme.com/software/http_load/http_load-12mar2006.tar.gz
    $ tar zxvf http_load-12mar2006.tar.gz
    $ cd http_load-12mar2006/

    $ make

    $ sudo make install

    安装到/usr/local/bin

    可以通过man http_load查看使用说明(前提将http_load.1文件拷贝到man得查找路径中)

    1错误信息:byte count wrong

    http_load在处理时会去关注每次访问同一个URL返回结果(即字节数)是否一致,若不一致就会抛出byte count wrong

    所以动态页面可以忽略这个错误信息。

    或者可以对代码做修改http_load.c

    【原来的】
    “stderr, "%s: byte count wrong ", urls[url_num].url_str );”
    【修改的】
    “stderr, "%s: byte count wrong: first=%ld,cur=%ld ", urls[url_num].url_str,urls[url_num].bytes,connections[cnum].bytes );”

    2报错:too many open files
    系统限制的open files太小,ulimit -n 修改open files值即可;

    3无法发送大请求 (请求长度>600个字符)
    默认接受请求的buf大小 http_load.c

    912 static void
    913 handle_connect( int cnum, struct timeval* nowP, int double_check )
    914 {
    915 int url_num;
    916 char buf[600]; //
    根据需要修改,如:char buf[4096]
    917 int bytes, r;

    4Cannot assign requested address
    客户端频繁的连服务器,由于每次连接都在很短的时间内结束,导致很多的TIME_WAIT,以至于用光了可用的端口号,所以新的连接没办法绑定端口,所以要改客户端机器的配置,
    sysctl.conf里加:
    net.ipv4.tcp_tw_reuse = 1 
    表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
    net.ipv4.tcp_timestamps=1 
    开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用
    net.ipv4.tcp_tw_recycle=1 
    表示开启TCP连接中TIME-WAIT sockets的快速回收

     客户端频繁的连服务器,由于每次连接都在很短的时间内结束,导致很多的TIME_WAIT,以至于用光了可用的端 口号,所以新的连接没办法绑定端口,即“Cannot assign requested address”。是客户端的问题不是服务器端的问题。通过netstat,的确看到很多TIME_WAIT状态的连接。
    从网上找了解决办法:
    执行命令修改如下2个内核参数  

    sysctl -w net.ipv4.tcp_timestamps=1  开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用

    sysctl -w net.ipv4.tcp_tw_recycle=1  表示开启TCP连接中TIME-WAIT sockets的快速回收

    使用方式:

    http_load -parallel 100 -fetches 10000

    #100个并发执行10000

    http_load -parallel 100 -seconds 3600

    #100个并发执行1小时

    http_load -rate 100 -fetches 10000

    #每秒100个请求频率,请求10000

    http_load -rate 100 -seconds 3600

    #每秒100个请求频率执行1小时

    测试报告

    209 fetches, 10 max parallel, 6.9004e+06 bytes, in 30 seconds

    33016.3 mean bytes/connection

    6.96667 fetches/sec, 230013 bytes/sec

    msecs/connect: 31.8767 mean, 34.121 max, 31.304 min

    msecs/first-response: 274.644 mean, 3228.69 max, 127.399 min

    208 bad byte counts

    HTTP response codes:

    code 200 -- 209

  • 相关阅读:
    pycharm过期后,修改hosts文件?
    三种格式化方式
    virtualenv安装及使用
    二分查找以及单例模式
    目录总览
    SQLAlchemy
    Redis
    linux 安装虚拟机
    shell基本命令
    Linux 命令大全
  • 原文地址:https://www.cnblogs.com/xiatian1071/p/3630075.html
Copyright © 2020-2023  润新知