Implementation of the simultaneous online server architecture for millions of QQ games [zz]

Source: Internet
Author: User
Tags file url
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.