zoukankan      html  css  js  c++  java
  • 服务器压力测试系列一:压力测试工具tsung安装

    tsung是用erlang写的一个工具,号称压垮无数服务器。官网地址 http://tsung.erlang-projects.org

    一、安装依赖包

    要安装它首先要安装依赖包。参考官方文档 http://tsung.erlang-projects.org/user_manual.html#htoc18

    我是有选择性的安装了下面东西:

        Erlang/OTP 、 gnuplot and perl5 、Template Toolkit

    1、Erlang/OTP

       也就是erlang的安装。查找官方文档  http://www.erlang.org/doc/installation_guide/INSTALL.html#How-to-Build-and-Install-ErlangOTP

       找到3.5 How to Build and Install Erlang/OTP

       按照文档一步一步来就是。

       ./configure的时候报错,说java模块以及odbc模块未找到。odbc模块的话我是centOS系统,直接yum install  unixODBC unixODBC-devel

        注意我不需要用到java,所以 ./configure --prefix=/usr/local/erlang --without-javac

        然后就是make && make install。make的时候比较慢,大概要等个5、6分钟

    2、gunplot

         这玩意说白了就是一个绘图软件,把数据整成图形。为图简单我直接就是 yum install gunplot

    3、Template Toolkit

         也是个模板,把数据搞成一个html页面。后续会讲到用tsung_stat.pl命令生成reprot.html

         安装挺简单的,查看官方文档 http://www.template-toolkit.org/download/index.html 一步一步来就行

    二、安装tsung

          它的安装也简单,就是三部曲 进入到目录执行 ./configure make && make install

         但是我这里遇到了一点小麻烦,configure的时候报错,找不到erl和erlc。运行下configure --help的时候发现可以指定erlang的安装目录。

        上面我把erlang安装到了/usr/local/erlang,于是 ./configure --with-erlang=/usr/local/erlang/bin

         后面就一路安装成功了

    三、测试tsung

          tsung安装完成后会有配置的demo,默认的demo放在/usr/share/doc/tsung/examples里面,但是我在居然么找到这个目录。

          最后在/usr/local/share/doc/tsung/examples找到了,由于我只用http,所以我就复制了http_simple.xml

          一般情况下安装完tsung会在/root/下生成一个叫.tsung的系统默认目录,但是我居然又没找到,坑爹!!

          于是我在/usr/local下新建了一个tsung目录

          把http_simple.xml 重命名为tsung.xml放到这个目录下。

          测试下能不能运行,tsung start 。报错了。找不到/root/.tsung/tsung.xml。好吧,手动指定,先在/usr/local/tsung下建立一个log目录

          tsung -f /usr/local/tsung/tsung.xml -l /usr/local/tsung/log start 。 ok了运行成功

    四、配置tsung

         好了,剩下的就是配置了

         用vim编辑tsung.xml

    1、client端

         如果是单台机器的话use_controller_vm =true,否则的话tsung过一段时间会重新开一个erlang进程重新压,这个重开的过程其实是降低压力的过程。我理解的大概就是这个意思。官方文档如此说

         arn:Tsung launches a new erlang virtual machine to do the actual injection even when you have only one machine in the injection cluster (unless ’use_controller_vm’ is set to true). This is because it needs to by-pass some limit with the number of open socket from a single process (1024 most of the time). The idea is to have several system processes (Erl beam) that can handle only a small part of the network connection from the given computer. When the maxusers limit (simultaneous) is reach, a new Erlang beam is launched and the newest connection can be handled by the new beam).

         

      <clients>
        <client host="localhost" use_controller_vm="true" maxusers="60000" />
      </clients>

    2、server端

      <servers>
        <server host="tsung所在服务器的ip" port="80" type="tcp"></server>
      </servers>

    3、load

      <arrivalphase phase="1" duration="3" unit="minute">
        <users maxnumber="60000" interarrival="0.01" unit="second"></users>
      </arrivalphase>

          表示压力测试时间持续3分钟,每秒中产生 1/0.01 = 100个用户,一直到产生60000个用户后就不再产生。这个是跟上面的use_controller_vm相对应的

    4、sessions

        增加递增, 用于可能多、快的产生请求,见 http://tsung.erlang-projects.org/user_manual.html#htoc94

       <for from="1" to="5000" var="i">

            request><http url="你要压的地址" method="GET" version="1.1"></request>

       </for>

    五、开始压测

          tsung -f /usr/local/tsung/tsung.xml -l /usr/local/tsung/log start

         一段时间后进入log目录,运行 tsung_stat.pl命令就会生成report.html

         在浏览器打开就能看到相关的数据

    六、后续

          it's just a beginning,由于时间匆匆,官方文档没有仔细研读,好多的配置项没有了解。而且client还可以做成分布式的、多台机器同时压服务器、monit监控、模拟浏览器录制脚本等,这些都留待后续研究。

  • 相关阅读:
    js技巧收集(200多个)
    我的博客开张了,欢迎大家前来做客
    认识ASP.NET配置文件Web.config
    C#纯数学方法递归实现货币数字转换中文
    Asp.Net细节性问题技巧精萃(转载)
    ASP.NET2.0+SQL Server2005构建多层应用
    ASP.NET页面间的传值的几种方法(转载)
    介绍几种 ADO.net 中的数据库连接方式
    hdu 1401
    poj 1338 丑数
  • 原文地址:https://www.cnblogs.com/sky20081816/p/3117255.html
Copyright © 2011-2022 走看看