Performance testing of RPC single interface (Dubbo interface, etc.) using Jmeter+java

Source: Internet
Author: User

Build a Java Project

Build a MAVEN project to add the jar dependencies required for jmeter.

Pom.xml join as follows:

<Dependency><Groupid>org.apache.jmeter</Groupid><Artifactid>apachejmeter_core</Artifactid><version>3.2</Version></Dependency><!--https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_components--<Dependency><Groupid>org.apache.jmeter</Groupid><Artifactid>apachejmeter_components</Artifactid><version>3.2</Version></Dependency><!--Https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java--<Dependency><Groupid>org.apache.jmeter</Groupid><Artifactid>apachejmeter_java</Artifactid><version>3.2</version></dependency><!-- https:// Mvnrepository.com/artifact/org.apache.jmeter/jorphan -->< dependency><groupId> Org.apache.jmeter</groupid><< Span class= "Hljs-title" >artifactid>jorphan</artifactId ><version>3.2</version></DEPENDENCY>    

Implementing the Javasamplerclient Interface
/*** JMeter Test class * *@authorHEJB 2017.09.04 **/ Public classAppforjmeterImplementsjavasamplerclient {/*** Set default values for available parameters and*/ PublicArguments getdefaultparameters () {System.out.println ("I ' m start");return NULL;}/*** Start test, the parameter value can be obtained from the arg0 parameter;*/ Publicsampleresult runtest (Javasamplercontext arg0) {Sampleresult SR=NewSampleresult (); Sr.samplestart ();//jmeter Start statistic response time stampSr.setresponsedata ("Test",NULL); Sr.setdatatype (Sampleresult.text); Sr.setsuccessful (true); Sr.sampleend ();//JMeter End statistic response time stampreturnSR;}/*** Each thread is executed once before testing, doing some initialization work*/ Public voidsetuptest (Javasamplercontext arg0) {System.out.println ("Set up Test");}/*** Called at the end of the test;*/ Public voidteardowntest (Javasamplercontext arg0) {System.out.println ("Down ...");} Public Static voidMain (string[] args) {System.out.println ("Test in Main");}}

PS: Remember to add the Main method

Export JAR Package

Export the project's JAR package

Add a Jar Package

\apache-jmeter-3.2\lib\ext

Add a thread group

Join the Java Request configuration

You can find the Java class just now.

Add View results Tree

Add a look at the results tree and run it to see what's in the Java output

Join the aggregation Report

Incoming java Accept parameter parameters

Pass in parameters and get processed

String message = "test";/** * 设置可用参数及的默认值 */public Arguments getDefaultParameters() {Arguments arguments = new Arguments();arguments.addArgument("message", "hello world!");return arguments;}

To get a value in run

/** * start test, parameter values can be obtained from the arg0 parameter; */ public sampleresult runtest (javasamplercontext arg0) {message = Arg0.getparameter ( "message"); Sampleresult sr = new sampleresult (); Sr.samplestart ();  JMeter start statistic Response time tag sr.setresponsedata ( "test:" + message, null ); Sr.setdatatype (Sampleresult.text); Sr.setsuccessful (true); 10);} catch (interruptedexception e) {//TODO Auto-generated catch Blocke.printstacktrace ();} Sr.sampleend (); //jmeter end Statistic response time tag return sr;}      

Remember to re-export the jar package every time you modify it, put it under EXT, and restart Jemeter to see the parameter settings

Receive parameters

Performance reports,

This allows the use of Java to test the RPC interface, (such as the Dubbo interface of the pressure measurement, long-connected pressure measurement, etc.)

Keep a record, lest we have to re-search the next time.

Performance testing of RPC single interface (Dubbo interface, etc.) using Jmeter+java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.