简体   繁体   中英

How to calculate total response time of an HTTP request using AsyncHttpClient library

I am looking into using AsyncHttpClient (AHC) to invoke multiple HTTP requests in parallel and calculate total response time as well as TCP connection time, DNS resolution time, time to first byte etc. of each of these async requests.

AsyncHttpClient is the only Java client I came across which emits events for TCP connection time, DNS resolution time etc.

My question is: What is the correct way to measure the start time for the HTTP request so that I can calculate different performance metrics based on that.

Is "onRequestSend" correct event to consider for start time. I am looking for an event which indicates the start of the HTTP lifecycle phase ie creating a socket on client side to open a connection.

Documentation: https://www.javadoc.io/doc/org.asynchttpclient/async-http-client/latest/org/asynchttpclient/AsyncHandler.html

you can use Kotlin standard library:

    val mark = TimeSource.Monotonic.markNow() // Returned `TimeMark` is inline class
    val elapsedDuration = mark.elapsedNow()

look off-documentation

I would say it is like

long t0=System.currentTimeMilis();

doYourHttpCallAndProvideCallback(response->{
    long total=System.currentTimeMIlis()-t0;
    souf("It took %dms to do the request\n",total);
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM