性能测试工具nGrinder介绍

作者: python测试开发 | 来源:发表于2018-11-19 22:34 被阅读64次

    安装

    以linux,这里采用的版本是centos 6 64bit,性能测试工具不建议在Windows上部署。

    下载:

    https://github.com/naver/ngrinder/releases/

    选择最后面的war包。

    服务器端启动:

    
    # java -XX:MaxPermSize=200m -jar ngrinder-controller-3.4.war --port 8058
    

    这样nGrinder的管理页面就部署好,你可以简单的把ngrinder-controller的功能理解为性能测试展示和控制,后面会进行详细介绍。

    打开网址:

    http://183.131.22.113:8058

    默认用户名和密码都为admin

    图片.png

    注意:这里的"Remember me"是短暂停留,页面关闭之后还是需要重新登陆的。

    登录后点击右上角的admin,选择"下载代理"

    图片.png

    拷贝下载的文件到agent,现在可以简单理解为agent的功能为执行性能测试,通常不建议与ngrinder-controller部署在同一台,同一台机器也不建议部署多个agent。

    客户端启动:

    
    # nohup ./run_agent.sh  &
    

    快速入门

    • 输入网址
      http://172.30.249.160
    图片.png
    • 配置
    图片.png
    • jython脚本

    点击 REV:HEAD,可以看到jython脚本

    图片.png
    • 运行

    点击"复制并运行"

    图片.png
    • 查看结果
    图片.png

    点击"详细测试结果"

    图片.png

    参考资料

    测试配置

    注意agent RAM up配置是基于进程的,一般每个agent有10个进程。

    脚本

    首先要配置:grinder.properties,通常在用户目录的.ngrinder目录下。

    脚本使用Grinder脚本API,参见:http://grinder.sourceforge.net/g3/script-javadoc/index.html

    脚本中的grinder对象是ScriptContext实例,这样就可以获取上下文信息。

    Hello World

    
    # Hello World
    #
    # A minimal script that tests The Grinder logging facility.
    #
    # This script shows the recommended style for scripts, with a
    # TestRunner class. The script is executed just once by each worker
    # process and defines the TestRunner class. The Grinder creates an
    # instance of TestRunner for each worker thread, and repeatedly calls
    # the instance for each run of that thread.
    
    from net.grinder.script.Grinder import grinder
    from net.grinder.script import Test
    
    # A shorter alias for the grinder.logger.info() method.
    log = grinder.logger.info
    
    # Create a Test with a test number and a description. The test will be
    # automatically registered with The Grinder console if you are using
    # it.
    test1 = Test(1, "Log method")
    
    # Instrument the info() method with our Test.
    test1.record(log)
    
    # A TestRunner instance is created for each thread. It can be used to
    # store thread-specific data.
    class TestRunner:
    
        # This method is called for every run.
        def __call__(self):
            log("Hello World")
    

    Simple HTTP example

    
    # A simple example using the HTTP plugin that shows the retrieval of a
    # single page via HTTP. The resulting page is written to a file.
    #
    # More complex HTTP scripts are best created with the TCPProxy.
     
    from net.grinder.script.Grinder import grinder
    from net.grinder.script import Test
    from net.grinder.plugin.http import HTTPRequest
     
    test1 = Test(1, "Request resource")
    request1 = HTTPRequest()
    test1.record(request1)
     
    class TestRunner:
        def __call__(self):
            result = request1.GET("http://localhost:7001/")
     
            # result is a HTTPClient.HTTPResult. We get the message body
            # using the getText() method.
            writeToFile(result.text)
     
    # Utility method that writes the given string to a uniquely named file.
    def writeToFile(text):
        filename = "%s-page-%d.html" % (grinder.processName, grinder.runNumber)
     
        file = open(filename, "w")
        print >> file, text
        file.close()
    

    更多脚本,参见: http://grinder.sourceforge.net/g3/script-gallery.html

    相关文章

      网友评论

      本文标题:性能测试工具nGrinder介绍

      本文链接:https://www.haomeiwen.com/subject/lzszfqtx.html