there is a task to minimize the time to http request in Java. I use the Unirest library in the project, however, a similar situation occurs with the libraries async-http-client and okhttp

What is the essence: The first post request to the server takes about a second, but all subsequent requests in the main thread are completed in 200ms already, which I consider to be a good result. But I could not achieve the same speed while sending several requests at the same time. If you use the Unirest library functionality for asynchronous requests, then each request will take ~ 700ms, which is much slower than the required 200.

The second option that I tried is to make server requests in different Threads. At first, I still perform the first long request in the main thread, and then I post my requests for threads, in one of which I get 200ms per request, but in the other one I get over 700ms.

Question: Is there a way to perform parallel queries without losing the speed of the query itself?

  • Have you tried to figure out what time it takes? - Alexey Ten
  • Perhaps something the server does this. You may still need to clean the memory after each request - Tsyklop
  • one
    So if the fact is that the server processes your requests for a long time, then these are questions to the server - Roman Danilov
  • @RomanDanilov when testing with successive requests the server is responsible for 200ms. If it’s interesting, then this is an aliexpress server, I don’t think there are any performance problems on their side. The task is to send two requests at once, and that they also occupy 200ms, but this is not yet possible - Valentine
  • one
    I suspect that the first 500ms go to the DNS, the installation of TCP-connection and TLS. Subsequent requests use ready-made connection and they do not have these overhead costs. Is it possible to share the connection between threads in Java, I do not know. - Alexey Ten

0