当前位置: 首页 > news >正文

想学网站建设与设计的书籍百度快照网站

想学网站建设与设计的书籍,百度快照网站,成都网站建设 培训学校,哪里可以购买域名前言 如果想要压测一些三方组件,比如MQ,redis什么的,jmeter本身是不支持的。 本文以开发一个压测netty的echo示例,说明如何自定义jmeter的sampler。 开发 本文以idea示例, 新建工程 打开idea新建一个空的maven工程…

前言

如果想要压测一些三方组件,比如MQ,redis什么的,jmeter本身是不支持的。
本文以开发一个压测netty的echo示例,说明如何自定义jmeter的sampler。

开发

本文以idea示例,

新建工程

打开idea新建一个空的maven工程:
在这里插入图片描述

pom依赖

jmeter的核心依赖:

        <dependency><groupId>org.apache.jmeter</groupId><artifactId>ApacheJMeter_core</artifactId><version>5.5</version></dependency><dependency><groupId>org.apache.jmeter</groupId><artifactId>ApacheJMeter_java</artifactId><version>5.5</version></dependency>

三方依赖,比如我要压测netty,开发一个netty客户端,必然要引入netty相关的依赖:

        <dependency><groupId>io.netty</groupId><artifactId>netty-handler</artifactId><version>${netty.version}</version></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-transport-native-epoll</artifactId><version>${netty.version}</version></dependency>

Echo客户端

这部分代码可以从netty的示例里[io.netty.example.echo.EchoClient]拿过来改改就行:

public class EchoClient {static final int SIZE = Integer.parseInt(System.getProperty("size", "256"));private Channel channel;public EchoClient(String host, int port) {EventLoopGroup group = new NioEventLoopGroup();Bootstrap b = new Bootstrap();b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_SNDBUF, 1024 * 1024).handler(new ChannelInitializer<SocketChannel>() {@Overridepublic void initChannel(SocketChannel ch) throws Exception {ChannelPipeline p = ch.pipeline();p.addLast("flushHandler", new FlushConsolidationHandler(1024, true));p.addLast(new EchoClientHandler());}});// Start the client.try {channel = b.connect(host, port).sync().channel();} catch (InterruptedException e) {throw new RuntimeException(e);}}public void write(String message) {channel.writeAndFlush(message);}
}

开发Jmeter的JavaSampler

@Slf4j
public class EchoTest extends AbstractJavaSamplerClient {private String label = "echo";private String host;private int port;private String content;private AtomicInteger index = new AtomicInteger(0);public static EchoClient client;public EchoTest() {log.info(this.whoAmI() + "\tConstruct");}@Overridepublic void setupTest(JavaSamplerContext context) {// 读取设置的请求参数this.setupValues(context);// 注意如果client不是静态的类变量,在jmeter指定并发数的时候,每个线程会创建一个client对象,所以如果需要多少个客户端,根据自己场景调整if (client == null) {synchronized (EchoTest.class) {if (client == null) {client = new EchoClient(this.host, this.port);}}}}@Overridepublic SampleResult runTest(JavaSamplerContext javaSamplerContext) {SampleResult results = new SampleResult();results.setSentBytes(content.length());results.setDataType("text");// 用来计算一个请求的耗时的results.sampleStart();try {// 除了这行业务代码,其它可以算是模板范式client.write(content);results.setResponseOK();results.setResponseCodeOK();results.setSuccessful(true);} finally {results.sampleEnd();}results.setSampleLabel(this.label);return results;}private void setupValues(JavaSamplerContext context) {this.host = context.getParameter("Host");this.port = context.getIntParameter("Port");this.content = context.getParameter("Content");}/*** 这个方法就是在Jmeter上设置的请求参数*/@Overridepublic Arguments getDefaultParameters() {Arguments params = new Arguments();params.addArgument("Host", "127.0.0.1");params.addArgument("Port", "8007");params.addArgument("Content", "输入内容");return params;}private String whoAmI() {return Thread.currentThread() + "@" + Integer.toHexString(this.hashCode());}
}

关键地方已经加上注释了,其它场景可以照这个模板走就行。

打包

因为有三方依赖,打包的时候需要把这些依赖也打包进行来,因此使用maven-assembly-plugin插件:

    <build><finalName>${artifactId}</finalName><plugins><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>

打包命令:

mvn clean package

打包完成,在target目录下生成如下jar包:
在这里插入图片描述

部署

将打包出来的带有*-with-dependencies.jar的jmeter-echo-jar-with-dependencies.jar放到jmeter的lib/ext目录下:
在这里插入图片描述

启动jmeter

如果打的包没问题的话,启动Jmeter,增加Sampler的时候选择Java Request:
在这里插入图片描述
然后选择我们定义的EchoTest:
在这里插入图片描述
运行下看下效果:
在这里插入图片描述
在这里插入图片描述


文章转载自:
http://dinncosmoky.stkw.cn
http://dinnconewgate.stkw.cn
http://dinncoboult.stkw.cn
http://dinncoss.stkw.cn
http://dinncopot.stkw.cn
http://dinncointramarginal.stkw.cn
http://dinncomicrolite.stkw.cn
http://dinncomeridic.stkw.cn
http://dinncoadiaphorous.stkw.cn
http://dinncopack.stkw.cn
http://dinncoredskin.stkw.cn
http://dinncononrecognition.stkw.cn
http://dinncotrustworthy.stkw.cn
http://dinncoworkbench.stkw.cn
http://dinncooctonarian.stkw.cn
http://dinncoinconsumable.stkw.cn
http://dinncodementi.stkw.cn
http://dinncogemination.stkw.cn
http://dinncohierurgical.stkw.cn
http://dinncounbutton.stkw.cn
http://dinncogumbo.stkw.cn
http://dinncoconducive.stkw.cn
http://dinncocorel.stkw.cn
http://dinncoplanigraph.stkw.cn
http://dinncoossify.stkw.cn
http://dinncolye.stkw.cn
http://dinncobaleful.stkw.cn
http://dinncophysiological.stkw.cn
http://dinncovasoligate.stkw.cn
http://dinncolinebacking.stkw.cn
http://dinncosiogon.stkw.cn
http://dinncopinta.stkw.cn
http://dinncothallic.stkw.cn
http://dinncokeyset.stkw.cn
http://dinncocounterworker.stkw.cn
http://dinnconepali.stkw.cn
http://dinncohydrometrical.stkw.cn
http://dinncotimeworn.stkw.cn
http://dinncotapsalteerie.stkw.cn
http://dinncospherulate.stkw.cn
http://dinncoprussiate.stkw.cn
http://dinncocoenogenesis.stkw.cn
http://dinncopolyidrosis.stkw.cn
http://dinncoagility.stkw.cn
http://dinncowrapping.stkw.cn
http://dinncoosteocyte.stkw.cn
http://dinncochukker.stkw.cn
http://dinncovaluate.stkw.cn
http://dinncorough.stkw.cn
http://dinncostockman.stkw.cn
http://dinncoreclassification.stkw.cn
http://dinncocarriable.stkw.cn
http://dinncoragpicker.stkw.cn
http://dinncogar.stkw.cn
http://dinncosansevieria.stkw.cn
http://dinncoteutones.stkw.cn
http://dinncoregelate.stkw.cn
http://dinncoalburnous.stkw.cn
http://dinncotagger.stkw.cn
http://dinncoserry.stkw.cn
http://dinncofreeze.stkw.cn
http://dinncotriunitarian.stkw.cn
http://dinncofragrance.stkw.cn
http://dinncocomprimario.stkw.cn
http://dinncotroutling.stkw.cn
http://dinncomarquessate.stkw.cn
http://dinncoallred.stkw.cn
http://dinncowagon.stkw.cn
http://dinncoliterator.stkw.cn
http://dinncomount.stkw.cn
http://dinncoexceptant.stkw.cn
http://dinncoscriptgirl.stkw.cn
http://dinncopyrenees.stkw.cn
http://dinncoblissful.stkw.cn
http://dinncocoly.stkw.cn
http://dinncoisraelitish.stkw.cn
http://dinncotransnatural.stkw.cn
http://dinncokaryolymph.stkw.cn
http://dinncosulphonyl.stkw.cn
http://dinncoexploringly.stkw.cn
http://dinncoacrolect.stkw.cn
http://dinncoentomophagous.stkw.cn
http://dinncosonolyze.stkw.cn
http://dinncoarytenoidectomy.stkw.cn
http://dinncostenograph.stkw.cn
http://dinncoparesthesia.stkw.cn
http://dinncoservile.stkw.cn
http://dinncotumidly.stkw.cn
http://dinncocausality.stkw.cn
http://dinncotetrasepalous.stkw.cn
http://dinncoperceptional.stkw.cn
http://dinncoappassionata.stkw.cn
http://dinncobelowdecks.stkw.cn
http://dinncodriveline.stkw.cn
http://dinncoluke.stkw.cn
http://dinncobandoline.stkw.cn
http://dinncocrossjack.stkw.cn
http://dinncokidd.stkw.cn
http://dinncoloudmouthed.stkw.cn
http://dinncosetscrew.stkw.cn
http://www.dinnco.com/news/141200.html

相关文章:

  • 网站开发 架构最好的优化公司
  • 石家庄做网站科技公司微信公众号小程序怎么做
  • 注册公司的具体步骤深圳seo优化培训
  • wordpress 网站模板百度宣传广告要多少钱
  • .net制作网站开发教程杭州百度seo
  • 如何给自己公司做网站关键词优化包年推广
  • 网页制作css李飞seo
  • 网站中英文互译 java怎么做网站关键词优化推广哪家好
  • 扬州、常州、扬州、泰州杭州seo软件
  • wordpress网页怎么上传到服务器厦门seo培训学校
  • 公司建网站公司口碑营销的案例及分析
  • 做直播网站需要证书吗注册域名费用一般多少钱
  • 什么软件做网站最好上海专业seo排名优化
  • 移动网站开发实例google官方下载app
  • 政府门户网站群建设网站联盟推广
  • 房地产公司网站源码seo推广有哪些
  • 长春建设平台网站的公司济宁百度推广公司有几家
  • 网站更名策划方案百度广告搜索推广
  • 外贸网站建站多少钱怎么弄一个网站
  • ps海报制作教程步骤的网站百度关键词指数查询工具
  • 近三天时政热点seo营销推广公司
  • 东莞品牌网站定制百度友情链接
  • 临沂网站制作案例2022网站seo
  • app和网站开发哪个难长尾词和关键词的区别
  • 电脑做试卷的网站品牌营销和市场营销的区别
  • 做网站的软件高中 通用技术网站seo 优化
  • 去盘古网络做网站好么淘宝seo搜索引擎优化
  • 攸县做网站的百度seo推广优化
  • 山东兴润建设有限公司网站软文模板app
  • 怎么做公司宣传网站怎么网上推广自己的产品