6

Using the PerformanceResourceTiming, the duration value returned includes the resource scheduling time too.

Here is an example:

Here is the data observed using a Performance Observer: Observer data for the performance entry

The values match with the network panel. But this value corresponds to the total time. This total time has added up the resource scheduling time too.

Network Dev tools request total time

Is there any way to get the duration from the API excluding the resource scheduling time? Usually the API is adding this time into the total duration of the request.

Network Dev tools queueing time

Here is the entry in the network panel table. Network Dev tools Time registered

As you can see in the above photos : 244.13ms is the sum of 240ms (~Resource Inflight Time) + 4ms (~Resource Scheduling Time).

As noted above, the value logged is the sum of stalled time and time logged in the entry of network table. Which means it is not exclusively the in-flight time; I am looking for that.

Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39
  • "resource scheduling time"? You mean the "Waiting for server response" field in your screenshot? From the page you linked to, you have `connect`[Start/End], `domainLookup`, and `response` props that will allow you to build about the same graph. Can't you get what you want from that? – Kaiido Nov 30 '22 at 09:04
  • @Kaiido no I mean the `Resource Scheduling Time`. I want it to not be included when I get the duration from the API – Tushar Shahi Nov 30 '22 at 10:16
  • @TusharShahi did you try The `fetchStart` and `responseEnd` properties to calculate the time? I guess it will give you what you needed – Sanira Nimantha Jan 04 '23 at 03:49

2 Answers2

0

you can calculate that time

 var startTime = performance.now()

 doSomething()   // <---- measured code goes between startTime and endTime

 var endTime = performance.now()

 console.log(`Call to doSomething took ${endTime - startTime} milliseconds`)

and if you want to know the time your request took before the server recieved it, start a "performance.now()" when you send the request and another "performance.now()" at the beginning of the function on the server.

then substract them as shown in the example above now you know the time it took for the server to recieve your request

  • Hi Joseph. This is the manual way to test it and sure even if inconvenient I can add it between all my requests. But once again this is less accurate than the Resource Timing API because this value will be affected by how busy the UI thread is. This value does not strictly include the inflight time as far as i can see. – Tushar Shahi Dec 29 '22 at 07:34
0

This Code gives you total duration with and without latency, as you request excluding the resource scheduling time.

const resourcses =performance.getEntriesByType('resource').reduce((o,entry,i)=>{
    const {name,requestStart,responseStart,
    domainLookupEnd,
    domainLookupStart,
    connectEnd,
    connectStart,
    secureConnectionStart,
    responseEnd} = entry;
    const dnslookup = domainLookupEnd - domainLookupStart;
    const TCPhandshake = connectEnd - connectStart;
    const secureConn = (secureConnectionStart > 0) ? (connectEnd - secureConnectionStart) : 0;
    const wl = (responseEnd-requestStart)+(dnslookup+TCPhandshake+secureConn);
    const whl = (responseStart-requestStart)+(dnslookup+TCPhandshake+secureConn);
    const l = wl-whl;
    o[i] = {
        url:name,
        dnslookup,
        TCPhandshake,
        secureConn,
        withLatency:wl,
        withoutLatency:whl,
        networkLatency:l
    }
    return o;
})

console.dir(resourcses)

enter image description here

Above Image shows the response time without latency of 43.43 (green color) and with latency of 45.26 (sky blue color)

Latency is time required by network to fetch the resource from server to client, it may differ by your network speed.

Yuvaraj M
  • 933
  • 1
  • 4
  • 11
  • Requeststart is definitely missing the time taken for DNS lookup and TCP handshake. Have a look at this image. https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API/resourcetiming-timestamps.jpg. Did you verify the values? – Tushar Shahi Jan 04 '23 at 12:21
  • It does not includes the DNS lookup and TCP handshake duration, only contains server response and latency. Would you please tell which parameters actually you want so i can change the code – Yuvaraj M Jan 04 '23 at 12:55
  • Hi, Tushar Shahi Finally, What i'm included is DNS lookup + TCP handshake + Secure connection + Response Duration with and without latency and I'm tested with our live server. – Yuvaraj M Jan 05 '23 at 04:39