Edited to clarify my intent: (based on initial answers)
I have a web app. The server consists of a set of Java POJOs and I’m using Jersey to expose these as REST APIs. The browser calls these APIs, using jquery ajax, and does stuff.
I want to log the duration that my ajax queries take, and I want a break down by
- How long it took to send the query from browser to server (into my Java POJO)
- How long it took for the Java POJO to process the request
- How long it took for response to be transmitted to browser (from POJO exit point to onComplete: entry point in javascript)
I’m also looking for a code based solution that I can apply systematically across my app.
So, 2 on its own is trivial, and timing the whole sequence is trivial. But I’m not sure about getting the breakdown for 1 & 3. I was initially going to pass the system time as a GET param, and compare to currentTimeMillis on the server – but this relies on the browser system time being in sync with the server system time. Unlikely to be reliable.
Are there any other suggestions?
See “How do you determine exactly when, accounting for network latency, a HTTP request was sent?“, the answer explains how you can “calibrate” the client-side time with the server-side time. Note that this calibration will not be exact. Hope this helps.