导入本地的 JMeter 原生脚本,即可快速发起一次压测。
前提条件
压测机所属资源池选择:根据用户权限,展示拥有Master 和Owner 权限的资源池名称。若资源池显示为空,请先购买资源池;
压力机数量:指压力机部署所需的资源,即资源池剩余资源,可满足部署相应数量的压力机数量。例如:容器云平台部署1台压力机表示:2核CPU、2G内存、1个实例,若压力机数量超过资源池剩余资源(CPU、内存、实例),则需要调整数量或者对资源池扩容
JMeter 原生JMX 脚本需要在本地调试成功。
操作步骤
1. 导入 JMeter 脚本
导入 JMeter 脚本,如下为get 请求访问http://10.254.117.84:8080/html 地址 1000次 的Jmeter脚本文件。可拷贝以下脚本,保存为 .jmx 格式,如:testdemo.jmx 。
- 使用限制:
- JMX 脚本文件:文件大小不超过 2MB。可上传多个 JMX 脚本文件,但是压测仅能使用一个 JMX 脚本。发起压测前勾选一个使用。
- 选择 JMeter 版本 和 Java 版本:
JMeter 版本:支持 Apache JMeter 5.0 以上版本。
Java 版本:支持 Java 8。
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.2.1">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="测试计划" 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="用户定义的变量" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="javaserver" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1000</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration">100</stringProp>
<stringProp name="ThreadGroup.delay">1</stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="false">
<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>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename">/Users/ruyan/Documents/Software/apache-jmeter-5.1/logs/编译${__time(YMD)}${__time(HMS)}.jtl </stringProp>
</ResultCollector>
<hashTree/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">10.254.186.252</stringProp>
<stringProp name="HTTPSampler.port">8080</stringProp>
<stringProp name="HTTPSampler.protocol">http</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/html</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>
<hashTree/>
<ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="聚合报告" 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>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ConstantThroughputTimer guiclass="TestBeanGUI" testclass="ConstantThroughputTimer" testname="常数吞吐量定时器" enabled="false">
<intProp name="calcMode">0</intProp>
<doubleProp>
<name>throughput</name>
<value>1000.0</value>
<savedValue>0.0</savedValue>
</doubleProp>
</ConstantThroughputTimer>
<hashTree/>
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="响应断言" enabled="true">
<collectionProp name="Asserion.test_strings">
<stringProp name="49586">200</stringProp>
</collectionProp>
<stringProp name="Assertion.custom_message"></stringProp>
<stringProp name="Assertion.test_field">Assertion.response_code</stringProp>
<boolProp name="Assertion.assume_success">false</boolProp>
<intProp name="Assertion.test_type">8</intProp>
</ResponseAssertion>
<hashTree/>
<ThroughputController guiclass="ThroughputControllerGui" testclass="ThroughputController" testname="吞吐量控制器" enabled="false">
<intProp name="ThroughputController.style">1</intProp>
<boolProp name="ThroughputController.perThread">false</boolProp>
<intProp name="ThroughputController.maxThroughput">1</intProp>
<FloatProperty>
<name>ThroughputController.percentThroughput</name>
<value>1.0</value>
<savedValue>0.0</savedValue>
</FloatProperty>
</ThroughputController>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
2. 施压配置
施压配置,其中:压测机所属资源池选择 和 压力机数量 可参考前提条件。2. 施压配置,其中:压测机所属资源池选择 和 压力机数量 可参考前提条件。
- 配置项说明:
- 工程名称:以小写字母开头,由小写字母,数字,中划线(-)组成,50个字符之内,且不能以中划线(-)结尾。
- 工程类型:自定义 和 Jmeter(当前选择Jmeter)。
- JMeter 文件:文件上传,格式限制 .jmx 。
- 压测机所属资源池选择:展示拥有Master 和Owner 权限的资源池名称。
- 压力机数量:资源池剩余资源,可部署压力机数量,其中:1台压力机需要:2核CPU、2G内存、1个实例 。
3. 添加监控
添加监控(可选):容器云平台提供多种监控,如:主机监控、资源池监控、项目及实例监控;可通过创建告警阈值规则,配置邮件或短信通知方式,实时告警通知。
4. 启动压测
启动压测
5. 查看压测报告
查看压测报告 (当前报告模版为Jmeter 原生的压测报告)
6. 导出压测报告
导出压测报告(可选)
作者:魏巍 创建时间:2019-12-27 14:43
最后编辑:韓胜永 更新时间:2025-04-29 18:46
最后编辑:韓胜永 更新时间:2025-04-29 18:46