java - html结果和jmeter sftp get函数中下载的文件的区别
问题描述
我正在尝试使用 jmeter 对我的 sftp 获取功能进行负载测试。我有一个在 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("userName","user2");
vars.put("hostIP","hostip");
vars.put("fileToGet", "test_exact20m.txt");
vars.put("fileToName", "test_exact20m");</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("userName"), vars.get("hostIP"), 4000)
session.setConfig("StrictHostKeyChecking", "no")
session.setPassword("user1")
def sftpSession = session.connect()
def channel = session.openChannel("sftp")
channel.connect();
def channelSftp = (ChannelSftp)channel;
log.info("SFTP Connection with host is acquired" + channelSftp)
def fileName = vars.get("fileToName") + Math.random();
channelSftp.get("/XYZ/" + vars.get("fileToGet"), "/ABC/" + fileName + ".txt", new Monitor(SampleResult));
log.info("FileName " +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 脚本还包括Ultimate Thread Group。使用以下命令在 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获取”的次数打印的是 1332,打印的日志“FileName”是 1332。 1332 下载的文件大小和内容都合适。我不确定为什么仪表板和 nohup 文件显示 2664 号。
经过多次测试,我才意识到结果是实际下载文件的两倍。
我的 sftp 服务器端也没有错误。
有什么我想念的吗?
解决方案
您有 2 个 JSR223 采样器,其中一个用于设置变量,另一个用于实际工作。
您可能希望使用User Defined Variables配置元素,因为您的第一个 JSR223 Sampler 在每次迭代中由每个虚拟用户执行,而只设置一次变量就足够了。
如果您想保留当前的测试计划结构(即为了历史结果兼容性),您可以SampleResult.setIgnore()
在第一个 JSR223 采样器中添加行,它将被排除在指标之外
推荐阅读
- c++ - C 和 C++ 中布尔值的 sizeof 运算符的输出差异
- java - 基于 Java 的 Azure 函数 - 异常:ClassCastException:无法强制转换类 jdk.internal.loader.ClassLoaders$AppClassLoader
- spring-boot - 不从表中删除记录
- flutter - 捕获流中引发的错误侦听
- angular - 动作守卫/中间件 - 如何检查条件?
- c++ - 不再支持命名返回值错误
- git - 使用 IntelliJ IDE 强制推送 Git
- c# - 从 WPF 中的另一个线程更新文本框
- arrays - bash 中的匿名管道列表
- php - 在 .txt 更改时自动刷新页面