Skip to main content

Performance Monitoring using JMeter

Posted by gijugeorge on December 9, 2008 at 7:14 PM PST

Apache JMeter is an open source tool that can be used to measure the performance of Java applications. The JMeter can be used to test a wide range of Java applications like web, EJB, web services etc. I am not going to elaborate more on this, and you can get more information about this from the Apache JMeter website at http://jakarta.apache.org/jmeter/

The JMeter can also be extended, to create your own test plans. In this section I will explain the steps needed to create a custom JavaRequest sampler, and run it using JMeter.

To write the code you need to add the ApacheJMeter jar files to your classpath. The below code describes the simple JavaSampler:


package com.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;

/**
 *
 * @author ggeorge
 */
public class MyTestJavaSampler implements JavaSamplerClient {

    public void setupTest(JavaSamplerContext arg0) {
        
    }

    public SampleResult runTest(JavaSamplerContext arg0) {
        
        SampleResult sr = new SampleResult();
        sr.sampleStart();
        sr.setResponseMessage("This is my first message");
        sr.sampleEnd();
        sr.setSuccessful(true);
        return sr;
    }

    public void teardownTest(JavaSamplerContext arg0) {
    }

    public Arguments getDefaultParameters() {
        Arguments args = new Arguments();
        args.addArgument("Name", "");
        args.addArgument("Password", "");
        return args;
    }
}

  • Create a jar file for this code, and place in under the /lib/ext directory.
  • Start JMeter and when you try to create a new JavaRequest sampler, you should be able to select the new class that you created.

You can customize this class for whatever performance test you want to run.

jmeter.jpg

Related Topics >>

Comments

When i add apache jmeter jar in my build path it does not ...

When i add apache jmeter jar in my build path it does not resolve the errors

can any one please help?

which version of apcahejmeter jar we have to use

You need not only apache-jmeter.jar but everything from ...

You need not only apache-jmeter.jar but everything from lib/ext and in some cases /lib folders in order to compile Java Request extension.

Depending on your use case you might consider another options of JMeter scripting

  • Beanshell - for something very light
  • JSR223 + Groovy - gives almost the same performance as Java native code
  • Java Request/Java Sampler - the fastest and the most efficient way, but you'll have to develop code, build it into jar and drop it to /lib/ext folder.

See Beanshell vs JSR223 vs Java JMeter Scripting guide for details on different approaches performance.