Article 1: Hypothetical QQ game server architecture
In the past few days, QQ games finally broke through the goal of millions of concurrent online users and moved toward a more ambitious goal, which eclipsed many other traditional chess and card casual game platforms, lianzhong does not seem to be a competitor of QQ at all, because QQ has more than 1 million registrations in addition to the 0.3 billion online game users (of course many of them are registered repeatedly) as well as the 9 million simultaneous online rate of QQ chat software, we can refer to the powerful chess and casual game empire built by QQ in the future.
In terms of technology, how can QQ games achieve simultaneous online play for millions of people and maintain high efficiency?
In fact, for any single network server program, the number of simultaneous connections that can be tolerated has a theoretical peak. The tsocket type is defined in C ++: word, we can determine that the theoretical peak value of this connection is 65535. That is to say, your single server program can withstand the simultaneous connection of more than 60 thousand users. However, in practical applications, it is not easy to connect to 10 thousand people at the same time and ensure normal data exchange. Generally, this value is between 2000 and 5000, it is said that the number of connections to a single server of QQ is at the same time.
It is not difficult to achieve a single server of 2000 to 5000 users online simultaneously. In Windows, iocp is used to complete the port. There are a lot of documents related to port completion on the Internet and csdn forums. If you are interested, you can search for them by yourself. As long as it is used properly, a complete port server can reach 2 K to 5 K at the same time. However, the number of 5 k is too different from that of one million. Therefore, the number of simultaneous online users cannot be achieved by a single server.
To achieve simultaneous online for millions of users, we must first implement a complete port server model that requires at least 2 K to 5 K at the same time (of course, if you have more money, you can also only develop servers that allow up to 100 online users ). After the basic port server is built, the architecture of the server group is designed. This is a server group because it is not only a server, but also a type of server.
Simply put, the server model for Achieving simultaneous online access for millions of users should be: Login Server + lobby SERVER + room server. Of course, it can also be other models, but the basic idea is the same. Next, I will introduce the respective functions of these three types of servers one by one.
Login Server: in general, we will open several public login servers to players, just like the QQ game server from which you choose to log on when logging on to QQ, when logging on to QQ, the six server portals that gamers choose are actually login servers. Log on to the server to balance the load. In details, there are n Hall servers behind the login server. The Login server is only used to select which Hall server should be connected to next for the current client connection, after the login server selects a suitable Hall server for the current client connection, the client starts to connect to the corresponding Hall server based on the information provided by the login server, and the client disconnects from the login server, makes socket resources available for other player clients to connect to the login server. When designing login servers, at least the following functions should be provided: Each Hall server of N Hall servers must be connected to all login servers, in addition, the number of concurrent online users of servers in this Hall is notified to login servers in real time, including: information about the number of concurrent online users and the number of concurrent online users who log out is increased. The number of simultaneous online users of servers in each hall is the basis for the login server to select a hall for the client to log on. For example, Player A connects to the login server through Login Server 1. The Login server starts to select a hall for the current gamer among the numerous Hall servers based on the number of servers in the hall, at the same time, the connection IP address and port of this Hall are sent to the client. After receiving the IP address and port information, the client connects to this Hall based on the information. At the same time, the client disconnects from the login server, this is the process of logging on to the server during user login.
Hall server: A hall server that is invisible to ordinary players. Its connection IP address and port information are logged on to the server to notify the client. That is to say, in the local file of the QQ game, the specific Hall server connection IP address and port information are not saved. The main function of the lobby server is to send the game room list information to players, including the type, name, number of online players of each game room, connection address and other information such as the game Help File URL. From the interface, the lobby server is the game room list interface that we enter the user name and password and pass the verification. The lobby server provides the following functions: first, it broadcasts information about the number of online players in each game room to the current player; second, it provides the game version and information; the third is to provide the connection IP address and port information of servers in each game room; the fourth is the URL information that provides game help; and the fifth is to provide other game auxiliary functions. However, among these many features, one of the most core is to provide players with a channel to enter a specific game room, allowing them to smoothly enter the game room they want to enter. Based on the number of online players in each game room, the player determines which room he entered. Then, double-click a game room in the server list and the player starts to enter the game room server.
Game room servers: Game room servers, specifically game rooms such as "Landlords 1" and "Landlords 2. The game room server is the Server responsible for executing the game-related logic. Such game logic is divided into two categories: general game room logic, such as: entering the room, leaving the room, entering the table, leaving the table, and talking in the room; the second category is game table logic, which is the main difference between different types of games, such as the logic of landlords or landlords. Of course, the game table logic also includes the general game logic that exists in each game, such as speaking in the table. In short, the game room server is the server that truly executes the game's specific logic.
The three types of servers mentioned here all adopt the complete port model. Each server can be connected to a maximum of 5000 people. However, I made a logical layer limit on the server in the game room, up to 300 concurrent online users are allowed. The other two servers still allow a maximum of 5000 concurrent online users. If we adopt this structure, we need to achieve simultaneous online for millions of people: first, the hall, 1000000/5000 = 200. That is to say, at least 200 Hall servers are required, but generally, at least 250 Hall server programs should be prepared considering the processing capacity and load of servers in actual use. In addition, the number of servers required for various types of game rooms must be calculated based on the number of players currently playing various types of games. For example, the number of landlords is at most 100,000 online simultaneously, each server allows a maximum of 300 concurrent online users. Therefore, the number of landlords required should be no less than: 100000/300 = 333. To be fully prepared, we need to prepare 350 landlords.
In addition to normal player connections, consider the following:
For login servers, there will be 250 Hall servers connected to each login server, which is always maintained;
For Hall servers, if there is only a server like landlords, more than 350 connections will be maintained with all Hall servers. From this point of view, my structure still needs to be improved in some aspects, but the core idea is to provide the user login speed as soon as possible, make it as easy as possible for players to enter the game.
Article Source: http://news.17173.com/content/2005-3-14/n430_347054.html
A classic online game server architecture
This figure shows the architecture of a zone. The architecture of all zones is the same. The servergroup In the dotted box above is the same as that in the box next to it. All x n servers in the figure are composed of multiple servers. The red lines, green lines, and blue lines are shown in the diagram. As you can see about the agent server, it is actually the gate.
This section describes the content and significance of the data connection that marks the location of the number.
1-this is a WebService pipeline. When a user activates the account in the region or modifies the account password, this channel is used to insert and update the account information of the user.
2-this is also a WebService pipeline, which is used to obtain and control the role information of the user in the group, as well as update operations such as pay mall tokens.
3-this is a local TCP/IP connection. This connection is mainly used to register a server group on the login server, and to register account login information with the user server after logging on to the server to verify the account, and perform operations on the account role information that has been logged on (such as kicking the current login role), as well as server group information updates (the current number of online players, etc ).
4-this is also a local TCP/IP connection. This connection is used to verify the Client Connected to the gameserver, obtain the role data information, and return the role data changes on the gameserver.
5-this connection is also a local TCP/IP connection, which is used for interaction between the Public Information Server and several game servers and for exchanging some world-class game information (such as Guild information, cross-server team information and cross-server chat channels ).
6-the two connections here mean that the agent of userserver and gameserver can be used interchangeably, that is, after the player enters the Group, there is no need to switch the agent. If you are not afraid of chaos, you can also calculate the agent used to log on to the server, so that you do not need to change the agent throughout the process, reducing the number of repeated connections and improving stability. (After all, the number of connections is reduced, which also reduces the chance of disconnections to the server)
In this architecture, gameserver is actually a combination of game logic, which can be expanded into several different logic servers for public data exchange through publicserver.
Userserver actually acts as a servergroup leader. It registers and updates the server group information (name, current number of people) with loginserver and schedules the agent, provide an agent with the minimum number of users to players who have selected this group. At the same time, it also provides a role management server function, which is sent to the client's current role list, role creation, deletion, selection, and other management operations. It is also a server for verifying user information. gameserver needs to verify the validity of the client and obtain the role data selected by the player.
Games using this architecture usually have the following performances.
1-you must activate a region to log on to your account in the region.
2-when you start the client, a login device is displayed, and a region is selected.
3-when a user starts a real client, the user enters the account and password at the beginning.
4-after the Account Verification is complete, select a server in the region.
5-after selecting the server, go to role management. Roles cannot be shared on different servers.
There are quite a few games on the market that match the above performance characteristics, and there is no lack of great achievements. This architecture is not a new architecture, but it is classic enough and perfect, and the logic is simple and clear. It is a good choice for MMORPG or server architectures of other online games.
Article Source: http://lingchuangsong.blog.163.com/blog/static/12693232200872752746177/
Not complete...