4

I have a simple spring boot application and a controller class. A simple method inside my controller :

@GetMapping("/heartbeat")
public ResponseEntity<String> heartbeat() {
    return new ResponseEntity<>("success", HttpStatus.OK)
}

I am calling this method from Postman, I can see the time it takes to complete this method is different in every call.

For example 28ms, 70ms, 15ms ...

It is ok if we talk about milliseconds but I have noticed that the more complex the web service is, the bigger the difference. Sometimes the difference is even seconds.

I suppose this is normal but what is causing this?

Thanos M
  • 604
  • 6
  • 21
  • Not sure in what context you mean bigger web server but it will vary based on where the server is deployed and from where you are accessing it and many more .. More detail here https://stackoverflow.com/questions/4814514/http-request-life-cycle – MyTwoCents Mar 06 '19 at 11:37
  • By bigger web service i mean a web service with more complex code inside it. For example a web service that performs a search inside a database is more complex than a simple heartbeat webservice. – Thanos M Mar 06 '19 at 11:40

1 Answers1

3

There are many factors which may cause this behavior. And most of the times it is explainable.

Assuming you are testing the web service on a local setup, following could be some scenarios:

Other background tasks

Background tasks running on your computer may spike on the resources they are using and this affects the execution of your webservice too.

Network status

It may be possible that the network is used by different applications and hence you may get a slightly delayed response.

Delay from WS client

The client, like Postman may itself take some processing to send request, or accept response. This gets credited to the overall response time, too.

Shariq
  • 513
  • 4
  • 14