html 结果与jmeter sftp get 函数中下载的文件的区别

Difference between the html result and files downloaded in jmeter sftp get function

我正在尝试使用 jmeter 加载测试我的 sftp get 功能。我在 linux 盒子上有一个 sftp 服务器 运行,在另一个 linux 服务器上充当 sftp 客户端 运行 的 jmeter。以下是我 运行

的脚本

使用的脚本是:

    <?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <kg.apc.jmeter.threads.UltimateThreadGroup guiclass="kg.apc.jmeter.threads.UltimateThreadGroupGui" testclass="kg.apc.jmeter.threads.UltimateThreadGroup" testname="jp@gc - Ultimate Thread Group" enabled="true">
        <collectionProp name="ultimatethreadgroupdata">
          <collectionProp name="361476282">
            <stringProp name="53">5</stringProp>
            <stringProp name="48">0</stringProp>
            <stringProp name="1572">15</stringProp>
            <stringProp name="50547">300</stringProp>
            <stringProp name="0"></stringProp>
          </collectionProp>
          <collectionProp name="639507566">
            <stringProp name="1567">10</stringProp>
            <stringProp name="1567">10</stringProp>
            <stringProp name="1629">30</stringProp>
            <stringProp name="49865">290</stringProp>
            <stringProp name="0"></stringProp>
          </collectionProp>
          <collectionProp name="1641281649">
            <stringProp name="1572">15</stringProp>
            <stringProp name="1598">20</stringProp>
            <stringProp name="1665">45</stringProp>
            <stringProp name="49834">280</stringProp>
            <stringProp name="0"></stringProp>
          </collectionProp>
          <collectionProp name="545617707">
            <stringProp name="1598">20</stringProp>
            <stringProp name="1629">30</stringProp>
            <stringProp name="1722">60</stringProp>
            <stringProp name="49803">270</stringProp>
            <stringProp name="0"></stringProp>
          </collectionProp>
          <collectionProp name="-1955907446">
            <stringProp name="1603">25</stringProp>
            <stringProp name="1660">40</stringProp>
            <stringProp name="1758">75</stringProp>
            <stringProp name="49772">260</stringProp>
            <stringProp name="0"></stringProp>
          </collectionProp>
        </collectionProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <intProp name="LoopController.loops">-1</intProp>
        </elementProp>
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
      </kg.apc.jmeter.threads.UltimateThreadGroup>
      <hashTree>
        <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true">
          <stringProp name="scriptLanguage">groovy</stringProp>
          <stringProp name="parameters"></stringProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="cacheKey">true</stringProp>
          <stringProp name="script">vars.put(&quot;userName&quot;,&quot;user2&quot;);
vars.put(&quot;hostIP&quot;,&quot;hostip&quot;);
vars.put(&quot;fileToGet&quot;, &quot;test_exact20m.txt&quot;);
vars.put(&quot;fileToName&quot;, &quot;test_exact20m&quot;);</stringProp>
        </JSR223Sampler>
        <hashTree/>
        <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true">
          <stringProp name="cacheKey">true</stringProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <stringProp name="script">import com.jcraft.jsch.*;
import java.io.*;

class Monitor implements SftpProgressMonitor {

    org.apache.jmeter.samplers.SampleResult sampleResult

    public Monitor(org.apache.jmeter.samplers.SampleResult sampleResult) {
        this.sampleResult = sampleResult
    }

    @Override
    void init(int i, String s, String s1, long l) {
    }

    @Override
    boolean count(long l) {
        sampleResult.setBytes(sampleResult.getBytes() + l)
        return true
    }

    @Override
    void end() {
    }
}

def jsch = new JSch()
def session = jsch.getSession(vars.get(&quot;userName&quot;), vars.get(&quot;hostIP&quot;), 4000) 
session.setConfig(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;)
session.setPassword(&quot;user1&quot;)
def sftpSession = session.connect()
def channel = session.openChannel(&quot;sftp&quot;)
channel.connect();
def channelSftp = (ChannelSftp)channel;
log.info(&quot;SFTP Connection with host is acquired&quot; + channelSftp)
def fileName = vars.get(&quot;fileToName&quot;) + Math.random();
channelSftp.get(&quot;/XYZ/&quot; + vars.get(&quot;fileToGet&quot;), &quot;/ABC/&quot; + fileName + &quot;.txt&quot;, new Monitor(SampleResult));
log.info(&quot;FileName &quot; +fileName)
session.disconnect()</stringProp>
          <stringProp name="scriptLanguage">groovy</stringProp>
        </JSR223Sampler>
        <hashTree/>
        <ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Simple Data Writer" enabled="true">
          <boolProp name="ResultCollector.error_logging">false</boolProp>
          <objProp>
            <name>saveConfig</name>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>true</responseData>
              <samplerData>true</samplerData>
              <xml>false</xml>
              <fieldNames>true</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>2</assertionsResultsToSave>
              <bytes>true</bytes>
              <sentBytes>true</sentBytes>
              <url>true</url>
              <threadCounts>true</threadCounts>
              <idleTime>true</idleTime>
              <connectTime>true</connectTime>
            </value>
          </objProp>
          <stringProp name="filename">/DownloadMultiPart_20m_2gbHeap_75Thread_350BBPool.csv</stringProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

jmx 脚本还包括 终极线程组。 运行 在 linux 上面的脚本之后使用下面的命令

nohup sh jmeter.sh -n -t DownloadMultiPart_20m_2gbHeap_75Thread_350BBPool.jmx -l DownloadMultiPart_20m_2gbHeap_75Thread_350BBPool.jtl -e -o /html &

nohup 文件的结果显示 summary = 2664 ,html Dashboard 报告显示 Samples = 2664, 但是/ABC文件夹下下载的文件是1332,jmeter.log文件显示log"SFTP Connection with host is acquired"打印次数是1332,log"FileName "打印次数是1332。 1332 下载的文件大小和内容正确。我不确定为什么仪表板和 nohup 文件显示 2664 号。

我经过多次测试才发现,结果是实际下载文件的两倍。

我的 sftp 服务器端也没有错误。

有什么我遗漏的吗?

您有 2 个 JSR223 采样器,其中一个用于设置变量,另一个用于实际工作。

您可能想改用 User Defined Variables 配置元素,因为您的第一个 JSR223 采样器由每个虚拟用户在每次迭代中执行,而只需设置一次变量就足够了。

如果您想保留当前的测试计划结构(即为了历史结果兼容性),您可以将 SampleResult.setIgnore() 行添加到第一个 JSR223 采样器,它将从指标中排除