Some issues related to game server architecture and performance optimization

Question 1: Why is there a lag in the game with too many online users? Server hardware or network or other reasons?

Answer: There are many reasons, which should be analyzed according to different situations:

1. The performance of the mobile phone or computer is not good, the client itself freezes, and the fps is very low;

2. Problems of the network itself, such as packet loss, high latency, or a weak network during mobile games, will cause the client to freeze, such as switching to chrysanthemums;

3. The server load is high and the performance is degraded, which makes it impossible to process client requests in a timely manner. It may be that the server hardware itself needs to be upgraded. On the other hand, the throughput of the program itself is not enough, the performance is low, and there may be architectural problems. , For example, without distributed processing, dynamic expansion is impossible.

Question 2: When a game reaches the middle and late stages of its life, it often needs to perform a large number of zone closing operations. What is a better solution for frequent zone closing?

Answer: You can use a server architecture where the storage layer is fully served in the entire region, and the access layer and logical layer are partitioned to serve to avoid the cost of data processing during compliance. To put it simply, the storage layer should be managed in a unified manner and not isolated to ensure that the game servers in different areas of the front end can access the core data of any area. The access layer and the logic layer are divided into cells, allowing players to play on different servers. .

The central global DB mode can be adopted, and the service does not require any DB operation, just some configuration changes, which can be automated.

Question 3: State synchronization or frame synchronization, how to ensure smooth communication? For real-time battle games, if you design a synchronization mechanism, such as state synchronization and frame synchronization, how to ensure smooth communication from the perspective of the server?

Answer: Regarding communication, it is recommended to select UDP as the protocol, control the packet size below 576byte, select reliable UDP for important information, and use unreliable UDP for unimportant information. In consideration of packet loss, a redundancy scheme can be adopted, and the client chooses access Some accelerated products.
image

Question 4: Ask whether AI is implemented on the client or the server? Does the client bridge synchronization or write directly on the server and rely on the server to synchronize to all clients?

Answer: It is related to the synchronization scheme selected by the game. For example, the king uses frame synchronization, and the AI ​​calculation is placed on the client. The opening server sends a random number seed to the client. Based on the same seed, according to the frame number, each client A consistent AI state can be calculated. This piece of anti-plugin can be done by the server spot checking whether the calculation results of each client are consistent. There are also many games, such as Inverse War, Sky Sword, Contra, etc. that use state synchronization, AI computing is placed on the server, and 3D collision processing is also placed on the server. This area has some in-depth optimizations.

Question 5: Some small questions about UDP

1. How is the UDP of King's Glory realized? UDP+EPOLL or multithreading?

2. How does UDP ensure reliability? How do you specifically do redundancy?

3. Does the data sent by the server need to be cached? How much is appropriate if it is a cache?

4. What if the packet sent to the client is lost, and the packet is buffered when the sending buffer is full?

5. Will battle data be cached on the server side?

6. Does the server do calculations? Is the frame sync used?

Answer: I didn’t participate in the King’s project. I have obtained some information from other channels, which may not be accurate. For reference:

1. The UDP component of the R&D department of Huyu Entertainment is used, unreliable UDP, UDP+EPOLL is sufficient, no multi-threading is required;

2. Reliable UDP is not used, and the efficiency is relatively low. It is guaranteed by redundancy. The specific way is that subsequent UDP packets will be redundant to a certain amount of previously sent UDP packets, for example, waiting for the response of the previous udp packet During this period, subsequent udp packets attach the previous unanswered packets, which can be redundant according to the situation, until the previous response is received, which is a way to exchange efficiency through traffic;

3. I don’t understand what you mean by this cache. When the frame is synchronized, their server will send the client in parallel. For example, if the client is 30 frames, the server will send 15 frames; 2 and 1;

4. Increasing the cache can alleviate the problem, but it is not a solution. It is necessary to analyze why this situation occurs, indicating that there is a problem with the design. Some players have problems with the network, so you need to sacrifice the game experience of players with poor networks. Give priority to ensuring the game experience of players with good networks, so some players do not answer for a long time, and the packet is lost if they are lost, regardless of their game experience;

5. They use frame synchronization, the server will perform a certain verification, but does not run the complete game logic, in order to anti-plug, you can bypass a complete verification server, you need to run the complete game logic;

6. See 5.

image

Question 6: What is the best solution for the login concurrency problem? It is related to the following processing aspects.

1. Concurrent data reading.

2. Data caching.

3. Package body.

4. Network cache.

5. Server organization structure.

6. The crash plan.

answer:

1. Distributed storage, or the popular nosql database, supports massive concurrent reading;

2. Cache is essential, even multi-level cache can be adopted;

3. I don't understand what it means. Does it mean that the package body is too big? Can be compressed

4. The requirements for the access layer are relatively high. Now the front-end access layer of the server is independent, and it can be solved by using a distributed solution;

5. The server architecture for massive services must be expanded by each module, there is no single point of bottleneck, and there must be a better load balancing mechanism;

6. High availability, lossy services can be adopted, that is, the crash of one server does not affect the people of other servers, minimize the impact, and can quickly restore, involving monitoring, alarm, backup and dynamic adjustment;

For example, Tencent's massive server has its own set of methodology and landing plans. Whether it's games or other Internet services, you can google it: "Tencent's massive service approach". There are many articles on the Internet.

Question 7: What technologies do I need to learn when learning game server programming?

Answer: Take Tencent's game server as an example. The main knowledge and skills are as follows:

1. Operating system: It is mainly based on unix/linux, so you need to be familiar with the operating system. You can go from preliminary understanding to use to in-depth study. Some books are recommended: "Linux Beginner's Guide", "Depth Exploration" Linux Operating System: System Construction and Principle Analysis", "LINUX Command Line and Shell Script Programming Encyclopedia", "In-depth Understanding of Computer Systems (Original Book 2nd Edition)", "Unix Advanced Environment Programming", etc., the main thing is to do more;

2. Programming languages: C/C++, lua, python. Tencent uses java and other programming languages ​​on the server side, so I won’t say more about these;

3. Network programming: Volume 1 or 2 of "TCP/IP Protocol Principles", Volume 1 or 2 of "Unix Network Programming";

4. Database: relational database mysql, now more popular nosql database should be familiar with, there are many open source;

5. Design patterns, object-oriented, etc.;

If you want to be engaged in game development more deeply, it is best to be able to understand the development knowledge and skills related to the game client, so that you don't want to be more involved;

Familiar with these knowledge and skills, it is basically no problem to engage in game back-end development. It is more important to participate in experience projects, understand the back-end architecture and development process, as well as the way of interacting with the client and planning and operating students. Exercise, study and sum up from the actual combat of the project.

Finally: Live broadcast on January 13/14, 2021: Game server framework—Yunfeng’s skynet training camp
is now open for registration. Those who are interested can subscribe to it, and
look forward to sharing the technology event
with you. Join the group 812855908 to receive the recording and broadcasting of the last skynet training camp and the preview materials for this period!
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40989769/article/details/112277900