Package size for low latency websocket html 5 games

I am making an HTML 5 chess game. I am presenting a board with an unsigned 8-bit binary array with a length (size) of 64. Since there are 64 positions on a chess board.

var board = Uint8Array(64); 

each chess piece is represented on the board through an (obviously) 8-bit unsigned integer. Then, on the clients, there is a map linking the binary representation of the part with the text string, for example:

 var pieceMap = { 01: 'BlackKnight', 112: 'WhitePawn', 6: 'BlackRook' ... } 

The data is transmitted through socket.io (suggesting that we are using websockets), TCP, I think? So the question is: Will TCP send my packets as small as the data I submit to it (with TCP overhead), or does TCP have a minimum packet size and send, say, my 200-byte packet as a packet with 1024 bytes ?

why so obsessed with size? I know that it doesn’t matter, but I will use it to study experience, in future games I will use it to reduce latency ... I know that chess should not be low latency.

+4
source share
1 answer

Framed packets as specified in the RFC:

http://tools.ietf.org/html/rfc6455#section-5

Overhead is up to 10 bytes per message or less than a fragment of the PER message. The number of bytes sent per fragment is determined by the length of the payload (part of the framing). However, fragments can be quite large. If you do not send very large messages, I do not think this will be a problem.

According to how framing and fragmentation works, you should not send / receive 1024 bytes of data if the framing data + is only about 100 bytes.

I suppose that some implementations may do this with slight differences, but you should not worry too much about such a detail if you do not start to see voltage problems in our application.

"Premature optimization is the root of all evil" Donald Knuth

Another detail: if you really want to go for a very low latency, you will have to start learning things like using UDP or multicast. The problem is that websockets does not support them. Reducing the size of packets is not the only important thing to work on the network, but only part of it ... and from my experience with socket.io, the processor becomes a bottleneck with small messages up to bandwidth, and RAM can also be severely damaged before bandwidth when messages are in low kilobytes. Of course, it depends entirely on your application, and I'm just talking about empirical experiences.

+3
source

Source: https://habr.com/ru/post/1437924/


All Articles