High Latency in socket communications?

132 views
Skip to first unread message

code bythepound

unread,
Jan 13, 2019, 7:43:33 PM1/13/19
to emscripten-discuss
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.


code bythepound

unread,
Jan 15, 2019, 8:48:17 PM1/15/19
to emscripten-discuss
Ping?  Any ideas here?

code bythepound

unread,
Jan 16, 2019, 1:58:29 PM1/16/19
to emscripten-discuss
As a test I wrote a separate Javascript-only client that uses websockets to communicate with the same proxy and native server.  It is able to run at thousands of messages per second, whereas the webassembly version gets roughly 16 /sec.  Happy to share the code or entertain any ideas of where to look to solve the issue.  Is anyone else seeing this?

Thanks.

code bythepound

unread,
Jan 16, 2019, 7:02:11 PM1/16/19
to emscripten-discuss
Given the message size, the problem was TCP_NODELAY in server and proxy native code.

Floh

unread,
Jan 17, 2019, 9:01:09 AM1/17/19
to emscripten-discuss
Thank you for keeping us silent lurkers in the loop, it's very much appreciated :D

I've done some socket-stuff in the past with emscripten but haven't actually measured the roundtrip time, so I didn't feel qualified to chime in :)

Cheers!

code bythepound

unread,
Jan 17, 2019, 1:41:36 PM1/17/19
to emscripten-discuss
No problem.  Especially since it was something simple.
Reply all
Reply to author
Forward
0 new messages