Huge latency when using Websockets?

Hello,

I am developing a webgl game and need to use websockets, but I ran a simple test and I am seeing 2.3x higher latency when using websockets than udp. From all I know the difference should not be that big?

The game is a very simple NGO with UTP project, sending a Vector2 as input and moving a NetworkTransform, plus syncing an ulong every tick. Client in Unity editor, server in a Linux build. For measuring latency I am using NGOs built in method for reading rtt. When using udp the rtt is 33ms, which is also what ping from the client to the server machine shows. But just switching to Websockets, without TLS, the RTT is 75ms.

As an additonal check, I tried a Photon Fusion sample project in exactly the same setup and it shows no difference in rtt at all between udp and websockets.

Any ideas?

I noticed that over udp, I am only seeing rtt that is the same as ping when I let server run maximum fps. When I limit server fps to 60 I get higher rtt but still lower than with websockets, and when I limit the server to 30fps, then I get higher rtt.

When using websockets though, even letting the server run max fps is giving 2-2.5x higher rtt than ping.

well udp is send and forget, websockets is tcp, and so send and acknowledge receipt, this can make a big difference