Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance measurement for Java based rest api

I have written a Java based rest API project. I want to test the performance for the API.

Here performance can be divided into two.

  1. Request to response time.
  2. Actual code execution time.

I know how to test or measure #1 but I am not sure how to measure #2.

More info for #2

Suppose I have a method which is mapped to rest end point.

I want to know how much time was spent in

  1. Parsing data to method params
  2. Executing the code in the method
  3. Amount of time spent in converting the response back to JSON

Thanks

like image 431
Ashwani K Avatar asked Oct 18 '22 22:10

Ashwani K


2 Answers

For request-response performance testing you can use SoapUI or Jmeter:

http://www.soapui.org/rest-testing/getting-started.html

For code execution time, "profiling" is the best option, because it doesn't require code modification, but it can be difficult for non expert users.

https://visualvm.java.net/

An old fashion way, modifying code is to log (with Log4j or similar) the execution time of the methods:

long startT = System.nanoTime();
//Code you want to measure
long endT = System.nanoTime();

long executionTime = (endT - startT);  //divide by 1000000 to get millisecs.
//Log this in specific category and level, so you can turn it on/off depending on your needs
like image 106
DavoCoder Avatar answered Oct 22 '22 00:10

DavoCoder


For your performance tests I would recommend to use JMeter (http://jmeter.apache.org/) and if you suspect bottlenecks I would recomment to create a java profile using a tool like jprof (http://perfinsp.sourceforge.net/jprof.html)

like image 21
Florian Biesinger Avatar answered Oct 21 '22 22:10

Florian Biesinger