"Go" JMeter Getting Started

Source: Internet
Author: User
Tags jconsole

I. Overview of JMeterJMeter is a test Tools, compared to LoadRunnerand other test tools, this tool is free and easy to use, but the premise of course is to install the Java environment; JMeter can do (1) pressure testAnd Performance Testing; (2) Databasetesting, (3) Testing of Java programs, (4) HTTP and FTP testing, (5) Web service testing, and so on; may be used with JMeter the JDK's own test tool JConsole, located in Jdk\bin\jconsole, this tool mainly observes the heap , JVM, CPU usage, the interface is as follows: Second, jmeter installationUnzip it; JMeter plugin: Http://code.google.com/p/jmeter-plugins/downloads/detail?name=JMeterPlugins-0.5.3.zip After download, put the jar file into the Jmeter_home\lib\ext directory; three, JMeter common componentsTest plan: The whole test plan; thread groups: All tasks are based on thread groups, how many threads are open to represent the number of concurrent users; ramp-up Period: Complete the test in so many hours, such as 2 threads, and ramp-up Period 3,  The interval for each thread is 1.5 seconds; Sampler: All test tasks are Sampler, that is, the category of any test task is Sampler, such as an HTTP request, a JDBC request, an FTP request, an assertion that the Sampler test is judged correctly; Listener: The results of Sampler request statistics, display; Common hierarchies are: HTTP requests: Impersonation HTTP requests, view result trees: For each request, you can view HTTP requests and HTTP responses; Graph results: can display the throughput, response time, etc. Report: Overall throughput, response time, 1, Label: Defines the HTTP request name 2, Samples: Indicates how many requests were made in this test. 3, Average: Average response time for access pages 4, min: Minimum response time for access pages 5, Max: Visit Maximum response time of the page 6, error%: Number of Wrong requests/total number of requests 7, throughput: Number of requests completed per second 8, Kb/sec: Amount of data received per second from server side Scenario Description:Set up a server-side, accept the parameters: Name and age, and save the data to DatabaseHttp://localhost:8080/Server/SaveServlet?name=xxx&age=xxx we jmeter it through the pressure testTarget: Open 1000 threads, each thread loops 1 times, all operations are completed in 3 seconds; The result is as follows:

Generally own manual settings JMeter will be more troublesome, if one side of the operation of the page, submit the form, while the ability to automatically generate JMeter script, it is very convenient; BadBoy: Record jmeter script; Donwload url:http:// Www.badboy.com.au/download/add Badboy interface is as follows: We can enter the address in the field you want to visit the page, such as www.baidu.com, and then query Xiazdong, click: Stop Recording, and then click on "File-  Export to JMeter "JMeter script can be generated, open to generate the following structure: we only need to run to simulate just query" Xiazdong "process, of course, we can open 1000 threads at the same time to simulate 1000 users in the query Xiazdong; The results of the graphic result are as follows:

Objective: To JavaProgram to Testfirst, the core steps1. Create a Java project; 2. JMeterThe jar file in the Lib directory is added to the build Path of this project; 3. Create a class and implement the Javasamplerclient interface or inherit abstractjavasamplerclient, and override:
Public Arguments getdefaultparameters (): Set default values for available parameters and public void Setuptest (Javasamplercontext arg0): executed once per thread before testing, Do some initialization work ; public Sampleresult runtest (Javasamplercontext arg0): Starts the test, the parameter value can be obtained from the arg0 parameter; public void Teardowntest (Javasamplercontext arg0): Called at the end of the test; 4. Export to runnable Jar File;
5. Place the jar package in the Jmeter_home\lib\ext directory; 6. Open JMeter as Administrator; 7. Create Thread group, Java Request, result tree, test; Second, examplesUsing JMeter for service Performance Testing, the service is: the input two parameters via IO to the file, 1, write Java code services:
Package test, import Java.io.file;import Java.io.printwriter;public class Outputservice {public static void Output (String filename,int A, int b) throws Exception {PrintWriter out = new PrintWriter (new File); Out.write (A + " : "+b); Out.close ();}}
Test class:
Package Test;import Org.apache.jmeter.config.arguments;import Org.apache.jmeter.protocol.java.sampler.javasamplerclient;import Org.apache.jmeter.protocol.java.sampler.javasamplercontext;import Org.apache.jmeter.samplers.SampleResult; public class Performencetest implements Javasamplerclient {private Sampleresult results;private string A;private string b ;p rivate String filename;//Sets the parameters passed in, you can set more than one, the parameters that have been set are displayed in the JMeter parameter list of public Arguments getdefaultparameters () {Arguments params = new Arguments ();p arams.addargument ("filename", "0");//Set the parameter and give the default value 0params.addargument ("a", "0");//Set parameters, and give the default value 0params.addargument ("B", "0");//Set the parameter and give the default value 0return params;} The initialization method, which is executed only once per thread at runtime, executes public void Setuptest (Javasamplercontext arg0) {results = new Sampleresult () before the test method runs;} The loop body of the test execution, depending on the number of threads and the number of cycles, can be executed multiple times @overridepublic sampleresult runtest (Javasamplercontext arg0) {b = Arg0.getparameter ("b "); Gets the parameter value set in JMeter a = Arg0.getparameter ("a"); Gets the parameter value set in JMeter filename = arg0.getparameter ("filename"); Get in JMeterSet the parameter value Results.samplestart ();//JMeter start statistic response time tag try {outputservice test = new Outputservice (); Test.output (filename, Integer.parseint (a), Integer.parseint (b)); Results.setsuccessful (true);//The object being tested} catch (Throwable e) { Results.setsuccessful (false); E.printstacktrace ();} finally {results.sampleend ();//JMeter End statistic Response time tag}return results;} The end method, which is actually run only once per thread, executes public void Teardowntest (Javasamplercontext arg0) {}public static void Main (string[) after the test method run finishes ] args) {//TODO auto-generated method Stubarguments params = new Arguments ();p arams.addargument ("A", "0");//Set the parameter and give the default value 0 Params.addargument ("B", "0");//Set the parameter and give the default value 0JavaSamplerContext arg0 = new Javasamplercontext (params); Performencetest test = new Performencetest (); Test.setuptest (arg0); Test.runtest (arg0); Test.teardowntest (arg0);}} Export to Runnable Jar File;
2. Set JMeterAfter opening jmeter as an administrator and creating a Java request, the structure looks like this: A new test class was found in Java requests: We found three parameters in the JMeter: we fill in the values of the response: we must be very strange, how there are some things that can not understand,  This is the function that JMeter provides, we can do it because we want to do the performance test, so we need to open multiple threads concurrent testing, so the random number is very important; the commonly used functions are: (1) _random generate random integers, (2) _randomstring generate random strings; Set the number of concurrent threads in the thread group to 10000 and run after saving; the graph results are as follows: Aggregated report: Table View results: Results succeeded, nearly 10,000 files were generated: 3. Problems encountered during 3.1 export to jar file results in Java reques The class name of T cannot be found; 3.2 JMeter Java.lang.OutOfMemoryError:PermGen space problem: modified in Jmeter.bat: Set heap=-xms512m-xmx1024m set NE w=-xx:newsize=128m-xx:maxnewsize=128m Set survivor=-xx:survivorratio=8-xx:targetsurvivorratio=50% Set TENURING=-XX  : maxtenuringthreshold=2 Set rmigc=-dsun.rmi.dgc.client.gcinterval=600000-dsun.rmi.dgc.server.gcinterval=600000 The set perm=-xx:permsize=256m-xx:maxpermsize=512m 3.3 JMeter needs to be opened as an administrator, or else it will appear:

"Go" JMeter Getting Started

Related Article

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.