Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket timing: How to get the exact time when a websocket message arrives to the browser?

I'm writing a web application that use websockets for bidirectional communication between the client and the server. My main concern is user-perceived latency, so, I am measuring and profiling whatever I can. In particular, I'm capturing the current time at the onmessage() event. This is useful, but I also want to know when the event has been pushed into the browser's event loop - which happens before the onmessage event is fired.

In Chrome Developer Tools, I see the times in the "Network->Frames" tab, which, I think, is the time when the event enters the event loop. But I need to capture this programmatically in Javascript. Any idea how to do this?

I did some "console.log"ing and saw in a few cases a difference of approximately 10 milliseconds between the time showing in Developer Tools, and the time I capture in the onmessage event. I want my measurements to show if the difference is always as small as 10 milliseconds, or whether sometimes the difference is much higher, due to rendering or some other thing that happens in the page.

enter image description here

like image 734
Adi Levin Avatar asked Jan 13 '16 07:01

Adi Levin


1 Answers

The browser api for websocket is too restricted to expose the information that you want.

Browsers started to expose timing informations with the Performance interface, but that interface will only tell to you the timing informations of the initial connection to the websocket server, it don't know about websocket frames

like image 167
Nicola Bizzoca Avatar answered Oct 02 '22 14:10

Nicola Bizzoca