0
votes

When we make a http request we can set a Connection/Read/Write timeout, currently I am getting below exception:

java.net.SocketTimeoutException: Read timed out

How to figure out of this is because server is taking long time to process the request or because there is a lot of network latency ? Thank You.

1
Did you try googling "keep alive mecahanism"? Wikipedia has an article to get you started. - Code-Apprentice

1 Answers

1
votes

The HTTP request/response protocol expects that the server replies with a response in a relatively short amount of time. At this level, there is no difference between the server taking a long time and network latency. You have a couple of options for handling long running processes on the server:

  1. Use a different protocol that can update the client with the progress of the processing.

  2. Spawn a new process on the server to do the long computation and return an HTTP response immediately. This new server process can notify the HTTP server when the calculations finish, such as by saving them in a file or committing to a database. Then provide another HTTP endpoint that the client can query to check if the process has finished.