Using TCP for real-time commands: the Nagle algorithm causes huge delays, what should I do?

I am writing a socket server and a flash game client. The game requires real-time teams, such as movement and rotation. It is important that these commands are sent by the server to the client as soon as possible, because other clients would otherwise synchronize repeatedly with the move / rotate client.

This is an example of a problem caused by Nagle arithmetic:

Note : see the table of commands below if you want to understand what these commands mean.

The first is the ship that I moved (moved forward + right, forward was received, but the right is not)

Client Submission Commands:

84796: Sending data: 2#4
84796: Sending data: 2#2
84904: Sending data: 2#3
84904: Sending data: 2#0
86187: Sending data: 2#4
86188: Sending data: 2#2
86374: Sending data: 2#3
86404: Sending data: 2#0

Client receiving commands:

79244: Raw receive: 3#3#4$
79244: New command: 3#3#4
79398: Raw receive: 3#3#2$3#3#3$3#3#0$
79399: New command: 3#3#2
79399: New command: 3#3#3
79399: New command: 3#3#0
80635: Raw receive: 3#3#4$
80635: New command: 3#3#4
80908: Raw receive: 3#3#2$3#3#3$3#3#0$
80908: New command: 3#3#2
80908: New command: 3#3#3
80908: New command: 3#3#0

"" - , , , ,

  • A (: 0), B (: 0)

  • A (: 0), B (: 155)

  • A (: 108), B (: 0)

  • A (: 0), B (: 0)

  • A (: 1283), B (: 1236)

  • A (: 1), B (: 273)

  • A (: 186), B (: 0)

  • A (: 30), B (: 0)

, :

- >

2# (movement info)
0) now not turning
1) now turning left
2) now turning right
3) now not moving
4) now moving forward

- >

3# (movement info)
[shipId]#
0) now not turning
1) now turning left
2) now turning right
3) now not moving
4) now moving forward

, , - "Nagle". , , .

, TCP-. Nagle. , googled ( , tcp , ) , Nagle.

, Nagle ? ()?

. -

+3
5

TCP_NODELAY, nagle . , , , , , , .

setsockopt (TCP_NODELAY)

+4

, UDP.

, TCP , UDP .

, , , / .

TCP, TCP__NODELAY . , TCP TCP_NODELAY.

RFC1006 TCP.

+2

, , , - swithcgear.... .. . , .

RTP ( UDP) .

+1

, , . , , A :

  • 100

B 100 . - .

- :

  • ( X1, Y1 Z1)
  • ( X2, Y2 Z2) Stop Turning

.

+1

Note that Windows implements a delayed ACK as well as Nagle. This can give you an additional 200 ms delay for individual TCP messages. As far as I know, you cannot change this on Windows except using the registry key (and hotpatch to enable the registry key in some cases).

+1
source

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


All Articles