I am seeing fairly high latency in socket communications and was wondering if this was expected?
I modified the "echo" test from tests/sockets (test_sockets_echo_[client|server].c) to send repeatedly rather than stopping after one message. I have compiled the client side for emscripten and the server side as a native linux app. I further modified the client to run the test program's existing main_loop in a separate thread, as fast as possible, and then created an empty dummy_main_loop that is called once per second using emscripten_set_main_loop(dummy_main_loop, 1, 0);
Finally, since the server side is native, I am also using a somewhat modified version of
https://github.com/FWGS/wsproxy as the websocket proxy between them.
All the client code does is just send a message and wait for the response. I would have expected it to run thousands of times per second but I am seeing about 87ms in round trip latency (11-16/sec). Here are some typical numbers, where "rt" is round trip, c->s is client to server, and s->c is server to client, and 's' is time spent in server.
Msg: rt: 87000 c->s: 42282 s->c: 44718 s: 0 (us)
Msg: rt: 86000 c->s: 42199 s->c: 43800 s: 1 (us)
Msg: rt: 87000 c->s: 43230 s->c: 43769 s: 1 (us)
Msg: rt: 91000 c->s: 43242 s->c: 47758 s: 0 (us)
Msg: rt: 87000 c->s: 43234 s->c: 43766 s: 0 (us)
Msg: rt: 87000 c->s: 43201 s->c: 43798 s: 1 (us)
Msg: rt: 88000 c->s: 43227 s->c: 44773 s: 0 (us)
thread avgLoopTime: 24us loops: 40071
The thread average loop time is the amount of time spent calling one iteration of the client's main_loop, and the loop count is the number of iterations in approximately one second.
I have also measured the latency in the websocket proxy to be no more than 15us, and typically below 10.
Without going into any further detail, is this behavior expected? Is there some internal setInterval() or similar, that is used to control the socket functionality, that runs on a ~43ms interval?
Thanks for the help.