Tencent Cloud Community


Author: Yu Guoliang, senior architect of Tencent Cloud game industry

Why do MOBA and Chicken games have high network latency requirements?

As we know, different types of games have different requirements for network latency due to different gameplay and competitive levels, different synchronization algorithms. For example, MOBA games mostly use frame synchronization as the main synchronization algorithm, which is also highly competitive. In terms of fluency and fairness, they have the highest requirement on response delay. According to industry experience, when the network delay between client and server exceeds 150ms, the lag will start to appear. Will have a big impact on the player’s operation, the game can not be played fairly. Similarly, “Eat Chicken” games (such as PUBG) have very high requirements on the synchronization of player coordinates and actions. Data inconsistency caused by a slightly larger delay will have a great impact on the experience, and its real-time requirements are close to MOBA games. For traditional mmorpg, use the state synchronization algorithm, as the focus, with the property form and equipment also have certain competitive, requirements for the game flow, to delay also to have certain requirements, synchronization algorithm optimization degree is different, the requirement is different also, normally carried on in order to ensure the normal game, The response latency needs to be kept below 300ms. For blast furnace, by contrast, legends, doudizhu, fantasy westward journey turn-based game, at the same time there is only one player in the operating data, countless according to competition, and the time granularity coarser, even through special effects cover delay, so the requirement of network delay is not high, even if the delay of 500 ~ 1000 ms, ms can normal game. Here, we will not elaborate on the synchronization algorithm, but focus on the protocol.

Transport layer protocols and latency

Different transport layer protocols have differences in reliability, traffic control, and other technical details that can affect latency. TCP pursues complete reliability and sequence. After packet loss, it will continue to retransmit until the packet is confirmed, otherwise the subsequent packets will not be received by the upper layer. In addition, retransmission adopts an exponential avoidance strategy, and the RTO(Retransmission Timeout) that determines the retransmission interval cannot be controlled. Such a mechanism will lead to a sharp increase in the message response delay at the application layer when the packet loss rate increases temporarily. It is not suitable for games with high real-time performance and complex network environment.

Acceleration program

Based on udp custom transport layer protocol, introduce sequential and appropriate or adjustable degree of reliability, modify the flow control algorithm. For example, if you set the maximum number of retransmission times, you do not need to re-establish the connection even if retransmission fails. The well-known TCP accelerated open source solutions are: QUIC, ENET, KCP, UDT. Among them, QUIC is a TCP alternative from Google. Its main purpose is to integrate the reliability of TCP with the speed and efficiency of UDP. Its main features include: Avoid presequence packet blocking, reduce packet, forward error correction, session restart and parallel download, etc. However, the object of QUIC is TCP+TLS+SPDY, which is heavier than other schemes, and is less used for online games in China at present. The author of KCP is an outstanding developer in China, and the community is also developing well. The author of KCP and the community developer have done performance tests on ENET, KCP and UDT. For details, please refer to github.com/skywind3000… As can be seen from the test, KCP performs well, followed by ENET, and UDT performs worst. However, a problem is raised here. The original ENET retains the exponential avoidance feature of TCP retransmission, and the interval of each retransmission is still multiplied by 2. The default RTO is also high, which may be the main reason why ENET performs worse than KCP in the test. Here, we first exclude the transmission performance and compare ENET and KCP from other aspects (full mark 5) :

We made some minor changes to Libenet — the default RTT was changed from 500ms to 50ms, and the exponential avoidance strategy for timeout retransmission was removed. In Linux, TC command is used to simulate network delay and packet loss rate, and the control delay is 30ms, 50ms, 70ms respectively, and the control packet loss rate is 1%, 3%, 5%, 7%, 10% respectively. In different simulated network environments, TCP, original ENET and improved ENET are compared and tested.

Two performance metrics were examined in the test:

1) Average response time;

2) Proportion of packets with response times over 300ms.

Libenet code adjustments:

Figure 1 Adjust the default RTT to 50ms

Figure 2 cancel exponential dodge

The tc command is as follows:

Analog delay 100ms(RTT: 200ms) : tc qdisc add dev eth0 root netem delay 100ms

Simulate 1% packet loss rate: TC qdisc add dev eth0 root netem loss 1%

The comparison results are as follows:

FIG. 3 Comparison of the average response time of TCP, ENET and optimized ENET under different packet loss rates and network delay

FIG. 4 Comparison of timeout response ratio of TCP, ENET and optimized ENET under different packet loss rates and network delay

As can be seen from the figure, TCP has no obvious disadvantage in average response. When the delay is 30ms and the packet loss rate is 1%, the average RTT of the improved ENET is 69ms, the average RTT of the original ENET is 67ms, and the average RTT of TCP is 67ms. However, when the response time exceeds 300ms, when the delay is 30ms and the packet loss rate is 1%, the improved ENET RTT exceeds 300ms is 0, while the TCP RTT exceeds 300ms is more than 2%. If it is in a game, this performance can significantly affect the game experience. The results show that TCP has a big problem even when the network is a little unstable, and the improved ENET has obvious advantages.

conclusion

The test results are in line with expectations. In terms of real-time performance, THE network resistance of TCP protocol is not good. For MOBA or other games with high real-time requirements, we do not recommend using TCP as the protocol carrier. In fact, King of Glory’s PVP communication protocol is indeed based on UDP encapsulation; Similarly, pubG, the most popular game of all time, is udp based.

The latter

For developers, optimization protocol and synchronization algorithm are available methods to improve user experience in the existing network environment, but also relatively common methods. In the case of limited network jitter, packet loss is not frequent, and the network environment is not too bad, it can effectively improve the game experience. This approach also have limitations, however, in the network environment out of control, such as on the subway, shopping malls and other crowded, existing network hot spots, delay or packet loss rate is extremely high environment, still can’t solve the problem, the so-called “one”, then cattle X protocols and algorithms, cannot the Midas touch, to fundamentally solve the problem, Ultimately, it comes back to network quality. Compared with the civilian method, changing the network quality requires the accumulation of resources and the underlying scheduling strategy. How to optimize the network link from the player network access point to the server all over the country and even all over the world? How to optimize the access qos(Quality of Service) of the last kilometer from the client to the wireless base station? This method can be called gao Fu Shuai method, and there is such a large demand, and can adopt this method, I am afraid to see only one company: Tencent, and only one game: King of Glory. The good news is that Tencent has opened this ability in Tencent cloud, called: zhiying network excellent. Apply now for a free trial!

Want to know more about the GAME acceleration program and case, immediately register on January 19, tencent cloud GAME – TECH salon hangzhou station, we discuss: cloud.tencent.com/act/event/g…

reading

Enter Tencent, talk about operation and maintenance dry goods (the first phase) : Massive operation and maintenance practice big exposure release technology imagination – independent and controllable e-commerce platform construction road a mobile game product full path network acceleration artifact

This article has been published by Tencent Cloud Technology community authorized by the author