Experiments with WebSocket Performance (for HTML5 games)
blog.artillerygames.com
blog.artillerygames.com
And if you look at the charts, that seems to be exactly what happens. At low-but-nonzero packet loss rates, the maximum delay is never more than one or two RTTs. With high packet loss rates, you start to see a long tail of longer times due to double-loss events, I suspect.
[1] "By default" becuase it can be turned off. SACK can be used as a DoS vector by forcing the sender of a large transmission to buffer and reprocess essentially all of it repeatedly by pretending it "lost" a packet.
Is that the optimum solution though? Could one, say, have two TCP connections and send the same data on both? This way, maybe when one connection experiences packet loss, the other can carry on. This probably doesn't actually work due to high packet loss correlation or something (I have no idea about networking), so it would be interesting to hear what experts think.
Are there any other relevant parameters to tweak in order to make TCP's performance slightly more like that of UDP? Working on an MMO game myself (for fun), so would be great to know.
The characteristic you want from UDP is out of order sequencing: you want to see the most recent packet as soon as it arrives, even if some got missed before. No version of TCP does that, because TCP is a reliable protocol which presents a stream metaphor. Packet loss will always show up as latency burps, though as I point out generally that burp is one extra RTT.
But when writing a game where people interact in "real time" through their browser via websockets, anything to get TCP latency down is a plus in my book.
While packet loss is bound to cause some latency issues, I just want to minimize the latency hit for packet loss as much as possible. For instance, in a high packet loss situation, to overcome double loss (where a retried packet gets lost, causing 2xRTT of extra latency), perhaps TCP can send multiple retries at once after a single lost packet. For all I know, maybe this is a standard configuration parameter that I just have to set appropriately.
$ sysctl -a net.inet.tcp.sack
net.inet.tcp.sack: 1
It looks like somewhere after 10.4 they implemented it.http://tools.ietf.org/html/draft-ietf-rtcweb-data-channel http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-...
If you're worried about compatibility, check out PubNub or Pusher.
See socket.io for something even better.
Certainly Socket.io is a very simple (surprisingly so, even) implementation of a JSON-based event architecture on top of WebSockets, with integrated fallbacks to other transports on older browsers. But it requires node.js on the server side (though to be fair: it's protocol is very simple and could be reimplemented without too much trouble if you only wanted the client-side fallback stuff).
As will IE10 - http://html5labs.interoperabilitybridges.com/prototypes/webs...
Full matrix at http://caniuse.com/#feat=websockets