0

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?

soulmachine
  • 3,917
  • 4
  • 46
  • 56

1 Answers1

0

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.

ok2c
  • 26,450
  • 5
  • 63
  • 71
  • Thank you, I'll give it a try – soulmachine Aug 23 '15 at 18:45
  • After I read through the source code, I find that this source code can only calculate the total time of `n` requests, it's not able to calculate the time of each single async HTTP request – soulmachine Aug 23 '15 at 21:40
  • Huh? I gave you an answer where to put code to record start time. The example was to demonstrate performance optimizations for micro-benchmarking. You still need to do what you need to do by yourself. – ok2c Aug 24 '15 at 07:55
  • Both the synchronous `HttpClient` and asynchronous `HttpAsyncClient` have three phases, `ConnectRequestTime`, `ConnectTime`, `SocketTime`. All requests will be queued before actually get execution. if you call `long start=System.currentTimeMillis()` in `HttpAsyncRequestProducer.html#generateRequest()`, you just get the start time when the request is sent to the internal queue, so 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, you need to substract `ConnectRequestTime` – soulmachine Aug 25 '15 at 18:12