my backend Java Spring Boot application is calling a 3rd party web server via restTemplate. I have observed slowness when I switched from std JDK SimpleClientHttpRequestFactory
to Apache http client HttpComponentsClientHttpRequestFactory
. I have tried implementing custom http connection pooling with some random 'good enough' number of PoolingHttpClientConnectionManager
's setMaxTotal
and setDefaultMaxPerRoute
(I only have a few routes) and timeouts.
But, I wanted to cleanly and correctly come up with a number of maxPool and default connections per route. I tried to setup both of those numbers to 100 and saw SocketTimeouts, which I think means that the TCP connection is established but my app is waiting for the web server to send back data. So the underlying web server supports much lower number of concurrent requests on a connection.
Whats the correct way in knowing the downstream web servers capabilities? Should I look at the Connection, Keep-alive
headers in a trial run and configure my application like so?
Also, I want the actual time for all apis. Which means a breakdown of-
- TCP connection establishment(optional),
- Time of waiting when http request is sent out(app now will send the bytes out) and response is received(server starts sending the bytes), considering the connection pool as well.
- Total time of the api(Addition of api processing time + TCP time + waiting for socket data transfer time)
I have a custom Logging interceptor
which is logging all the headers, but from the trace level logs, I saw that the pooling manager connection lease mechanism is after the interceptors, so I cannot really know when the request is actually fired just from looking at the time of the interceptor level log. I need the time when the bytes were actually sent out.
Is there a good way to know when the request was actually fired and response first byte?
I was looking at DEBUG .apache.http.wire
level logs, but I do not need such verbose logs, as it will easily overwhelm my apps log rate.
Whats the best way to get that time of request out and response in?