top of page

How to Load Test Java Code Using Performator

  • Writer: Josef Mayrhofer
    Josef Mayrhofer
  • 1 day ago
  • 2 min read

The flexibility to measure any Java code execution while running it as a load test is one of the key features of Performator. Many other tools either require plugins to support what you want to achieve, need a cumbersome workaround, or not function at all.


As its underlying reporting framework, Performator uses the Hierarchical Statistics Report (HSR), allowing it to report various types of metrics and giving users control over when to start and end a measurement.


In this blog post, we will discuss how to use the HSR interface to measure any Java code during a load test executed with Performator.


The HSR.start() and HSR.end() method


HSR.start*() and HSR.end() are the two basic methods that you can use to measure your code execution. You provide a metric name to the start-method and complete the time measurement with the end-method. This will create a metric of type “Step” in the report.


public class UsecaseExampleHSR extends PFRUsecase {
	@Override
	public void execute() throws Throwable {
		HSR.start("000_Open_Homepage");
			Thread.sleep(HSR.Random.integer(50, 200)); // your code here
		HSR.end();
    }
}

The end-method can also take multiple parameters to set the state of the measurement. For example, you can provide a Boolean that sets the measurement to either successful or failed. This is useful to separate the time measurements of successful and failed measures, as the failed ones tend to distort the measured times, either lower(e.g., aborted on error) or higher(e.g., interrupted on timeout).


HSR.start("040_SometimesFails");
    Thread.sleep(HSR.Random.integer(50, 100));
    boolean isSuccess = HSR.Random.bool();
HSR.end(isSuccess);

To group multiple measurements into one, you can create groups using the startGroup()-method:


HSR.startGroup("015_MyGroup");
    HSR.start("000_Open_Homepage");
      Thread.sleep(HSR.Random.integer(50, 200)); // your code here
	HSR.end();
HSR.end();

Aside from simply measuring execution times, Performator allows you to report other options: messages, exceptions, gauges, counts, and others:


HSR.addErrorMessage("Exception Occured: Figure it out!");
HSR.addException(new Exception("This is an exception."));
HSR.addGauge("SessionCount", HSR.Random.bigDecimal(80, 250));
HSR.addCount("TiramisusEaten", HSR.Random.bigDecimal(0, 100));

All created metrics, along with the reports, will be displayed in the statistics engine. Here is an example of these metrics shown with count and duration charts:



Conclusion


Performator provides an easy way to execute Java Code and measure it with custom start and end methods, as well as adding other information to the report.


If Performator is a tool you would consider utilizing, you can find more information on our official Performator Website. If any concerns arise, we at Performetriks are always happy to assist. Contact us today!

Happy Performance Engineering!

Comments


bottom of page