When use synchronous HttpClient
, it's very easy to get the time of one request, just put System.currentTimeMillis()
before and after the execute()
method.
But when it comes to HttpAsyncClient
, the execute()
is asynchronous , which will just put the task into the queue. So I don't know how to get the start time of a connection.
The end time of a connection is easy, just call System.currentTimeMillis()
in the OnComplete()
method of the class instance FutureCallback<HttpResponse>
Both the synchronous HttpClient
and asynchronous HttpAsyncClient
have three phases, ConnectRequestTime
, ConnectTime
, SocketTime
. All requests will be queued before actually get execution. if we call long start=System.currentTimeMillis()
in HttpAsyncRequestProducer.html#generateRequest()
, we just take a note of the start time when the request is sent to the internal queue, so at last what you get is ConnectRequestTime
+ConnectTime
+SocketTime
, when you do a benchmark to test a batch requests, it's fine, but to test each single request, we need to substract ConnectRequestTime
.
So my real question is how to get the time of ConnectRequestTime
?
HttpAsyncRequestProducer.html#generateRequest() should be the right place.
You might also want to have a look at this as an example of how to squeeze maximum performance out of Apache HttpAsyncClient when doing micro benchmarking.