-1

I am doing performance testing using jmeter for a spring boot service.

Inside this service, making some rest calls using RestTemplate. I am able to get response time for a spring boot service using JMeter, but I wanna know how much restcalls inside service consuming time, so how do I find out this?

The reason I am asking this bcoz, I should be very confident that actual boot service doesn't take much time, instead its rest call taking too much time to give response (incase if response is very slow)

EDITED: Is there any tool does show me the actual request takes 500ms and rest call took 300ms, any idea? I am really not asking about by keeping something in the code as t1 and t2 and at end t2 - t1, I am not asking this.

Swarit Agarwal
  • 2,520
  • 1
  • 26
  • 33
john
  • 925
  • 1
  • 12
  • 20

4 Answers4

2

Option #1: Add an aspect(around advice) to intercept the restTemplate call, and start timer before making the rest call, end the timer once you receive the response and then calculate the time difference.

Option #2: Instrumentation Library:
For those looking for some existing opensource instrumentation library, you can use brave. Also, if used with zipkin you will get a dashboard as well.
Refer: https://zipkin.io/pages/tracers_instrumentation


Option #3: Commercial Tools

New Relic, Dynatrace

Satish
  • 1,037
  • 1
  • 13
  • 20
  • Is that not possible to find out with some tool? instead of writing some custom code to findout the resposne tme for a rest call? – john Feb 05 '20 at 06:56
  • there are many commercial tools which do that, e.g. Dynatrace, New relic. – Satish Feb 05 '20 at 06:58
  • So how APM tools can help us providing how much rest call took time? any video or link of any specific APM tool? – john Feb 05 '20 at 15:18
  • 1
    @john it instruments your java code and will log time taken by each and every method, db queries, time spent in IO, network etc. You have to enable the level of tracing which you want to use. videos are all over internet, just google out. – Satish Feb 05 '20 at 16:01
0

You can use a simple filter.

@Component
public class LogTimeFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        long startTime = System.currentTimeMillis();
        chain.doFilter(request, response);
        long duration = System.currentTimeMillis() - startTime;
        System.out.println("Request take " + duration + " ms");
    }
}

Reference : here

Satish
  • 1,037
  • 1
  • 13
  • 20
Prog_G
  • 1,539
  • 1
  • 8
  • 22
0

To paraphrase your question, you are asking for the ways to measure the various internal parts of spring boot driven application: - RestTemplate calls in terms of requests amount, requests per second and so forth - Some parts of time consuming internal application logic (for example running some algorithm) - Database calls connection pooling and so forth

For this spring boot provides an integration with Monitoring solution: If you're on spring boot 2.x or 1.5.x you can use Micrometer Otherwise for older spring boot versions use Dropwizard metrics

In a nutshell it allows specifying some "metrics" that can be exposed to monitoring systems like DataDog, Prometheus, and forth. So you can plug them and access the "snapshot numbers" via the actuator or export to the aforementioned systems to see graphs over time, construct queries, maintain dashboards and so forth.

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • I guess Micrometer/Prometheus tool provides us some metrics, but they tell us at what time, overall boot service took time, but it doesnt tell us whether whole service request took time or internal rest call took so much time, right? – john Feb 05 '20 at 15:21
  • They can measure whatever you want - you put the timer and it measures. These libs maintain object in memory per metrics. So you can see the avegrage, sum or any other aggregation. – Mark Bramnik Feb 05 '20 at 15:44
  • BTW, in actuator there is an ability to see last 50 rest requests including the time it took to handle the request if it helps – Mark Bramnik Feb 05 '20 at 15:45
0

From JMeter perspective response time can be split into:

  1. Connect time
  2. Latency or TTFB
  3. TTLB

You can also take additional measures for example JVM heap usage or number of GC using PerfMon or JMXMon plugins


With regards to your application itself you can identify how much time this or that function took, the "slowest" functions, the largest objects, etc. by using a profiler tool like JProfiler or YourKit

Dmitri T
  • 159,985
  • 5
  • 83
  • 133