当前位置:网站首页>使用JMeter对WebService进行压力测试
使用JMeter对WebService进行压力测试
2022-07-03 15:04:00 【星哥玩云】
现实项目中我们使用了JMeter对WebService进行了压力测试,ApacheJMeter是Apache组织开发的基于Java的压力测试工具。用于对软件做压力测试。
一、JMeter的作用
1.能够对HTTP和FTP服务器进行压力和性能测试, 也可以对任何数据库进行同样的测试(通过JDBC)。
2.完全的可移植性和100% 纯java。
3.完全 Swing 和轻量组件支持(预编译的JAR使用 javax.swing.*)包。
4.完全多线程 框架允许通过多个线程并发取样和 通过单独的线程组对不同的功能同时取样。
5.精心的GUI设计允许快速操作和更精确的计时。
6.缓存和离线分析/回放测试结果。
二、关于Jmeter的相关环境变量的配置类似于Java的配置,参考网上资料
三、Jmeter针对Http协议的webservice测试实例。
1:首先在测试计划中新建一个线程组
其中,线程属性中线程数和循环次数表示一次执行测试的时候真正运行的次数,也即访问webservice的次数.
2:线程组下面新建一个HTTP请求(关于访问接口服务的相关地址配置和一些参数的配置)和HTTP信息管理器(发送webservice服务时候的公共请求头),聚合报告(测试报告).
四、配置好一切之后,点击启动执行测试
=============we test webservice by http head start=========== name=clark =============we test webservice by http head end===========
备注====================================以下为关于webservice服务的配置集成到spring中
applicationContext_webservice.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <import resource="classpath:META-INF/cxf/cxf.xml" />
<jaxrs:server id="restContainer" address="/"> <jaxrs:serviceBeans><!-- 这里配置你的webservice bean定义。参考 org.iboxpay.payment.merchant.ws.MerchantWebService --> <!-- <ref bean="orderWebService" /> <ref bean="merchantWebService" /> --> <ref bean="clearUserWebService" /> <ref bean="merchantWebService"/> <!-- <ref bean="balanceWebService" /> --> </jaxrs:serviceBeans> <jaxrs:extensionMappings> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </jaxrs:extensionMappings> <jaxrs:providers> <!-- <ref bean="jsonExMapper" /> --> <ref bean="jaxbProvider" /> <ref bean="jsonProvider" /> </jaxrs:providers>
</jaxrs:server> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /> <!-- ********************使用jackson作为序列化器*********************** --> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</beans>
web.xml文件中CXF插件配置webservice <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
Java中web service服务的配置 package com.iboxpay.clear.webservice;
import javax.annotation.Resource; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Service;
import com.iboxpay.clear.service.SysResourceService;
@Path("/clearPro") @Service("clearUserWebService") public class ClearWebService { @Resource private SysResourceService sysResourceService; @Path("/dispath") @POST @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public String dispath(String jsonStr) { System.out.println("=============we test webservice by http head start==========="); System.out.println(jsonStr); System.out.println("=============we test webservice by http head end==========="); return "can you"; }
}
如果需要查看执行测试之后在Jmeter中的返回结果,我们需要在线程组下面新建一个察看结果树(右键线程组>添加>监听器>察看结果树),在响应数据一栏即可以看到响应返回的结果
注意:在Jmeter发送JSON字符串的格式进行测试的时候,我们传递JSON参数的时候不能给参数名称,而应该直接给值既可以。否则传到后台的时候会包含一系列的非字符串样式--导致其乱码。无法正确解析为我们需要的对象。 {"name":"zhangsan","description":"its"}既可以,而无需jsonStr = {"name":"zhangsan","description":"its"}其传过来的json参数我们只需要解析为我们后台对应的对象即可。 /** * 将JSON字符串 转换为对象 * * @author weiyuanhua * @date 2010-11-18 下午02:52:13 * @param jsonStr * JSON字符串 * @param beanClass * 泛型对象 * @param field * 对象中需要忽略的属性 * @return */ public static Object jsonToObject(String jsonStr, Class<?> beanClass,String... field) { JsonConfig jsonConfig = getJSONConfig(field); JSONObject jsonObject = JSONObject.fromObject(jsonStr, jsonConfig); return JSONObject.toBean(jsonObject, beanClass); }
private static JsonConfig getJSONConfig(String... field) { JsonConfig jsonConfig = new JsonConfig(); if (field != null) { jsonConfig = new JsonConfig(); String[] exclu = new String[field.length]; for (int i = 0; i < field.length; i++) { exclu[i] = field[i]; } jsonConfig.setExcludes(exclu); } return jsonConfig; }
边栏推荐
- Bucket sorting in C language
- Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
- Dllexport and dllimport
- Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
- Joomla! CMS 3.0~3.4.6 RCE
- The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
- Class part2
- Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Tencent internship interview sorting
猜你喜欢

Qt—绘制其他东西

Talking about part of data storage in C language
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding

Troubleshooting method of CPU surge

High quality workplace human beings must use software to recommend, and you certainly don't know the last one
![[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University](/img/83/922efb4f88843f1b7feaccf2b515b9.jpg)
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University

Composite type (custom type)

链表有环,快慢指针走3步可以吗

Bucket sorting in C language
随机推荐
NOI OPENJUDGE 1.3(06)
Byte practice plane longitude 2
[pytorch learning notes] transforms
Remote server background hangs nohup
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
C string format (decimal point retention / decimal conversion, etc.)
Class part2
There are links in the linked list. Can you walk three steps faster or slower
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
C language DUP function
Zzuli:1057 prime number determination
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
Yolov5 advanced nine target tracking example 1
406. Reconstruct the queue according to height
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
mmdetection 学习率与batch_size关系
Besides lying flat, what else can a 27 year old do in life?
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
C language fcntl function
C language to realize mine sweeping