• JMeter 七:远程测试


    参考:http://jmeter.apache.org/usermanual/remote-test.html

    http://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.pdf

    背景

    如果Jmeter客户端的机器性能不够好,导致不能加压足够的用户数到服务器,或者jmeter客户端机器所在的网络受限,这个时候我们就可以使用单个Jmeter客户端来远程控制多个jmeter服务器。

    通过远程跑Jmeter,我们可以在很多个低端计算机上复制测试,然后对被测服务器产生一个很大的压力。理论上Jmeter客户端可以控制任意数量的远程Jmeter,并通过它们收集所有数据。

    包括如下特点:

    • 保存测试采样数据到本地机器
    • 用单个机器管理多个jmeter引擎
    • 不需要拷贝test plan到每个服务器--客户端会给所有服务器发送test plan

    多个远程服务器会跑相同的test Plan。Jmeter不会在服务器间分配负载,也就是说每一个服务器跑完整的Test Plan。所以假设我们设置了1000个thread,并且我们有6台jmeter服务器,我们最终会注入6000个Thread。

    然而,远程模式会比单独跑相同数量的非GUI测试使用更多的资源。如果使用很多个远程jmeter服务器,可能会导致客户端jmeter过载,或者网络连接发生阻塞。

    需要注意的是,如果我们在应用服务器上执行Jmeter引擎,会加重应用服务器的负担,从而造成测试结果被污染。推荐将应用服务器和Jmeter引擎配置在相同的以太网段内。这样既不会对应用服务器造成性能负担,也可以最小化网络对测试结果的影响。

    工作方式

    使用单个Jmeter客户端来远程控制多个jmeter服务器。

    如上图, 192.168.0.2 就是JMeter客户端(主机器),控制其他的服务器(从机器)。

    可以这么说:

    Master 主机器:跑JMeter的机器,由该机器控制其他测试机器。

    Slave 从机器:被主机器控制的机器,是真正对被测系统产生压力的机器。

    Target 被测系统:被测试的系统所在机器。也就是被压的机器。

    可以看到下图中,一个Master主机器控制多台Slave从机器,由从机器对被测系统施压,进行测试。

    0. 配置节点

    确保所有的节点(主机器和从机器):

    • 使用相同版本的JMeter 以及 Java(使用不同版本的可能会带来问题)
    • 系统关闭防火墙,或者开放特定端口
    • 主机器和所有从机器最好在同一个子网内

    如果测试使用数据文件,注意jmeter主机器不会发送这些数据文件到从机器,所以要确保每台从机器都保存了这些文件,并且路径正确。

    如果有必要,我们可以编辑user.properties以及system.properties,给每台从机器设置不同的属性。当从机器启动,这些属性可能在 Test Plan中被使用,从而影响它的表现。

    不同的从机器可以使用不同的数据文件。比如,如果每台从机器使用独一无二的ID,我们可以以此来使用不同的数据文件。

    1. 启动从机器

    在所有jmeter从机器上执行脚本:

    • JMETER_HOME/bin/jmeter-server (unix环境)
    • JMETER_HOME/bin/jmeter-server.bat (windows环境)

    请注意,每个远程节点上只能有一个Jmeter从机器,除非我们使用不同的RMI端口。

    2. 在主机器属性文件中添加服务器IP地址

    打开主机器的属性文件 JMETER_HOME/bin/jmeter.properties,编辑 remote_hosts属性,添加远程Jmeter从机器的IP地址。多个IP地址之间以逗号分隔。

    # Remote Hosts - comma delimited
    remote_hosts=127.0.0.1
    #remote_hosts=localhost:1099,localhost:2010

    3. GUI方式启动主机器

    启动主机器的jmeter,选好Test Plan,点击 Run –> Remote Start,我们会看到菜单下列出所有配置的远程的从机器的IP。选择

    一个机器就可以在某个从机器上跑 Test Plan 。如果想在所有从机器上跑 Test Plan ,点击 Remote Start All即可。

    image

    4. 以命令行方式启动客户端

    GUI模式适合用来debug,真正测试时最好使用命令行方式。

    所有远程从机器停止运行测试后,命令行就会退出。

    有两种命令行启动方式。

    方式一:

    jmeter -n -t script.jmx -r

    这里直接在 jmeter.properties 中 remote_hosts定义的所有从机器上执行测试。

    方式二:

    jmeter -n -t script.jmx -R server1,server2,…

    这里先定义远程从机器,然后在远程机器上启动测试。

    其他

    1)Jmeter使用的端口号

    Jmeter/RMI需要建立一个从主机器到从机器的连接,默认使用1099端口。

    Jmeter/RMI也需要建立一个从从机器到主机器的连接,目的是从从机器返回测试采样结果给主机器。这个端口一般是一个更高的端口号。这个端口号可以通过 jmeter.properties的 client.rmi.localport 属性来配置, 默认该值是0,表示端口号随机分配。

    # Parameter that controls the RMI port used by the RemoteSampleListenerImpl (The Controler)
    # Default value is 0 which means port is randomly assigned
    # You may need to open Firewall port on the Controller machine
    #client.rmi.localport=0

    如果在主机器和从机器之间有防火墙或者其他的网络过滤器,我们需要保证它们允许上面连接的建立。

    2)更换使用的端口号

    默认情况下,Jmeter使用标准RMI端口号1099。参见 jmeter.properties 中的配置。

    # RMI port to be used by the server (must start rmiregistry with same port)
    #server_port=1099

    如果1099号被占用,想更换一个端口号,分为两步

    步骤一:更新 SERVER_PORT值,然后重新启动 Jmeter从机器。比如更换为1664端口。

    windows

    C:JMETER> SET SERVER_PORT=1664
    C:JMETER> JMETER-SERVER [other options]

    Unix

    $ SERVER_PORT=1664 jmeter-server [other options]

    步骤二:主机器重新设置remote_hosts

    打开主机器 jmeter.properties文件,编辑 remote_hosts 值类似 server:1664

    3)使用其他的采样发送方式

    测试计划中的 Listener 会把它们的结果返回给jmeter主机器,jmeter主机器会将结果写入到特定文件。采样结果产生之后,会同步发送回去。这就会影响服务器测试的最大throughput值。这种情况下我们就可以改变jmeter的采样发送方式。

    打开jmeter.properties,可以看到备选的mode有多种,比如Standard、Hold、DiskStore、Batch等等。

    默认使用的是 StrippedBatch模式。该模式会移除成功的采样返回的responseData,然后使用Batch方式来发送。

    各种模式具体的区别参见:http://jmeter.apache.org/usermanual/remote-test.html#sendermode

    # Since JMeter 2.9, default is MODE_STRIPPED_BATCH, which returns samples in
    # batch mode (every 100 samples or every minute by default)
    # Note also that MODE_STRIPPED_BATCH strips response data from SampleResult, so if you need it change to
    # another mode
    # Hold retains samples until end of test (may need lots of memory)
    # Batch returns samples in batches
    # Statistical returns sample summary statistics
    # hold_samples was originally defined as a separate property,
    # but can now also be defined using mode=Hold
    # mode can also be the class name of an implementation of org.apache.jmeter.samplers.SampleSender
    #mode=Standard
    #mode=Batch
    #mode=Hold
    #mode=Statistical
    #Set to true to key statistical samples on threadName rather than threadGroup
    #key_on_threadname=false
    #mode=Stripped
    #mode=StrippedBatch
    #mode=org.example.load.MySampleSender
    #
    #num_sample_threshold=100
    # Value is in milliseconds
    #time_threshold=60000
    #
    # Asynchronous sender; uses a queue and background worker process to return the samples
    #mode=Asynch
    # default queue size
    #asynch.batch.queue.size=100
    # Same as Asynch but strips response data from SampleResult
    #mode=StrippedAsynch
    #
    # DiskStore: as for Hold mode, but serialises the samples to disk, rather than saving in memory
    #mode=DiskStore
    # Same as DiskStore but strips response data from SampleResult
    #mode=StrippedDiskStore
    # Note: the mode is currently resolved on the client; 
    # other properties (e.g. time_threshold) are resolved on the server.

    4)处理启动失败的节点

    下面有3个属性。

    client.tries :定义新建远程引擎的尝试次数。默认值为1,表示仅尝试一次。

    client.retries_delay :两次尝试之间的延迟时间。单位为 milliseconds。

    client.continue_on_fail:值为 true 表示忽略新建失败的节点,并继续在新建成功的节点上执行测试。默认为false,表示尝试新建之后,只要存在新建失败的节点,测试就会失败。

    # When distributed test is starting, there may be several attempts to initialize
    # remote engines. By default, only single try is made. Increase following property
    # to make it retry for additional times
    #client.tries=1
    
    # If there is initialization retries, following property sets delay between attempts
    #client.retries_delay=5000
    
    # When all initialization tries was made, test will fail if some remote engines are failed
    # Set following property to true to ignore failed nodes and proceed with test 
    #client.continue_on_fail=false
  • 相关阅读:
    【linux之web服务器apache】
    【linux工具之sed实例】
    【linux工具之strace】
    【linux工具之iptables 脚本】
    【linux工具之iptables】
    【Linux抓包工具之tcpdump】
    【抓包工具之wireshark】
    【Linux 基础服务之DNS】
    c语言
    sf
  • 原文地址:https://www.cnblogs.com/miniren/p/6515009.html
Copyright © 2020-2023  润新知