I wonder whether warming up the code by sending unharmful requests for a number of times will reduce the time that we take to receive the response in Java?
Asked
Active
Viewed 364 times
-1
-
Hi David, could you clarify what type of requests (HTTP, FTP) and what framework (if any) you're using? If you could expand your question with more background information because different tools do it differently. – Stefan Zhelyazkov Oct 18 '19 at 20:33
-
Of course not. The time is dominated by the network and the server processing. – user207421 Oct 18 '19 at 20:36
-
Hi Stefan, thank you for your reply! I try to send a post http request by using retrofit2 package – David Oct 18 '19 at 20:37
-
Warming up generally has to do with class loading. So maybe the very first 1 or 2 calls will be faster if you warmed up. But all the subsequent networking calls would have no effect. – Dhruvan Ganesh Oct 18 '19 at 20:39
1 Answers
0
Your assumption is valid, but I would recommend other performance improvement techniques.
HTTPS calls
Creating a new connection is time consuming, but it takes a lot only the first time (during the handshake), subsequent requests being similar with HTTP. So keeping a connection alive or sending a dummy request before the real one will indeed improve the first request.
Java code
A Java app can have a lot of resources which do not load eagerly (reading properties files, static initialisation blocks...) and faking a request which will load those resources will help again, for the first request.
Other
Caching is common, so when you are requesting data, it may be cached for further access. But you need to check this on your particular case.

Horatiu Jeflea
- 7,256
- 6
- 38
- 67
-
Well, I was enumerating some possibilities, not necessarily recommending you to use them :) I would try to improve the actual code which is slow – Horatiu Jeflea Oct 18 '19 at 20:48