Why Spring RESTful web services take different time to complete each time

Thanos M :

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

@RequestMapping(value = "/heartbeat", method = RequestMethod.GET)
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 in bigger web services this difference is bigger, sometimes even some seconds.

I suppose this is normal but what is causing this?

Shariq :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=69783&siteId=1