gpt4 book ai didi

java - jmeter sftp get函数中html结果和下载文件之间的差异

转载 作者:行者123 更新时间:2023-12-01 16:47:07 26 4
gpt4 key购买 nike

我正在尝试使用 jmeter 加载测试我的 sftp get 功能。我有一个在 Linux 机器上运行的 sftp 服务器,而 jmeter 作为在另一台 Linux 服务器上运行的 sftp 客户端。下面是我正在运行的脚本

使用的脚本是:

    <?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文件显示打印日志“SFTP Connection with host is acquire”的次数是1332,打印日志“FileName”的次数是1332。1332 下载的文件大小和内容正确。我不确定为什么仪表板和 nohup 文件显示 2664 数字。

经过多次测试,我刚刚意识到结果是实际下载文件的两倍。

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

我缺少什么吗?

最佳答案

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

您可能想使用User Defined Variables相反,因为您的第一个 JSR223 Sampler 由每个虚拟用户在每次迭代中执行,而仅设置变量一次就足够了。

enter image description here

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

关于java - jmeter sftp get函数中html结果和下载文件之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61751788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com