General knowledge of game server architecture BigWorlds丨skynet

Preface

We will start from the simple history of game server development and take a bird's eye view of most current game server architectures.

Here, as much as possible to avoid falling into detailed technical problems, but to infer what the original problem is from the result state of technological evolution. I hope that through this process, I can explain clearly what problems the game server is solving and where the pain points are.

1. Early online game server.

We have mentioned the game server framework in the wild period. At that time, the game server was no different from a small web service.

The server in the Wild Era is only responsible for storing player accounts, data, and forwarding the behavior of other players in the scene. A lot of key logics such as moving and using skills are not on the server at all. You can change the speed of the game with the variable gear at will.

Since the era of "Legend", game servers are no longer simply uploading archives, downloading archives, and accessing pages. Game logic appears inside the game server, which can be used to synchronize the world that each player sees, but also to separate the logic from the client, avoiding the unpredictable logic system of early online games (external defense capability is 0 ).

Insert picture description here

As shown in the figure, after the client logs in through some form of authentication, it is directly connected to the server via TCP. The load-bearing capacity of this kind of server was not high, but at that time, the game logic was also simplified and the load was reduced to the extreme.

· For example: 1. The player cannot see the blood volume of the monster, or can only see the blood volume of the monster being hit. 2. The map has the concept of grids, each grid can only have one unit, which greatly limits the number of people on the same screen.

As the logic is simplified as much as possible, although the server logic services at this time are all single-process and single-threaded, they are enough to express the feeling of interaction.

The strange thing about this architecture is that the pressure of processing network connection data transmission and the pressure of logic processing are on the same server (the storage module may also be in the same process), even if the logic processing pressure is 0, the number of hosts is not much higher. .

Although the game server design at this time is very simple, but for the first time online games gave players a real-world experience. The problem of insufficient number of single servers can be achieved by opening multiple sets of servers, so there was a glorious era of hundreds of sets of servers.

2. The improved version of the early game server

After the developers have the initial experience, the development of new works naturally transitions to the following form:

Insert picture description here

The game logic service is still on a server, a single process (the logic processing itself must be in a thread, and there may be child threads responsible for intranet communication). But we naturally think that the storage load and network connection load can be separated from the logic server.

The connection server is responsible for converting the message between the client and the server into the message between the server, and can do some encryption and decryption work by the way.

This small change greatly increases the upper limit of the number of people connected to a single server. However, the demands of players increased, and the vacated performance was quickly eaten up by the rich game system.

Since the connection server itself has no time sequence, it is easy to be distributed (in fact, most games still use only one connection server). The storage service does not require high real-time performance. The storage interval during peak periods can be slightly longer, which will not affect the game server. influences.

3. Mature server framework

Logical server load sharing method 1: Divide multiple server processes according to functions

Insert picture description here

Logical server load sharing method 2: Divide multiple server processes according to scenarios

Insert picture description here

After a basic understanding of the history of game servers, mature game servers are easy to understand. Simply put, it is to distribute the pressure of a single process of a logical server to multiple servers.

The difficulty lies in the logical design. It is necessary to cut apart the originally integrated functions like an operation, and abstract several APIs to keep in touch (the server is a TCP connection).

When disassembling, look for the weakest link, such as the separation between scenes and scenes, separate chat services, team services, and friend services.

In any case, the final result can only be a limited number of services. And the finer the decomposition, the more difficult the development. Because the cross-server logic turns simple synchronous logic into asynchronous Callback logic, and it is prone to problems such as timing problems that are not easy to test.

A single scene service is almost impossible to decompose. It is so difficult to decompose a single scene that the BigWorld engine appears to specifically solve the scene segmentation problem, which will be discussed later.

This mature form of game server has been able to meet 99% of the demand for frequent interactive online games in reality, and is the mainstream form of large-scale MMO terminal games and page games.

Of course, powerful companies will make a lot of changes on this basis, realizing dynamic development of copies, phase technology, etc., but the changes are inseparable, and their essence is no different from the picture above.

Attachment: open-room online games

Open-room online games are also an important branch of the game, such as League of Legends, DOTA, and many mobile games such as Royal War, Glory of Kings, and so on.

There is almost no interaction between the game rooms, only the lobby has interaction, which can be understood as a parallel expansion of the original game server.

Room-style game expansion is less difficult, but it needs to dynamically expand the number of game rooms and servers based on the number of players. Much like the structure of a website.

Insert picture description here

This kind of game architecture is most suitable to be placed on the cloud platform. If the design is reasonable, the problems it may encounter are almost the same as those of large websites. No need to discuss them in particular.

It’s just that, after all, games are not all about opening a room.

Summary: Game server framework features
1. The real data is in memory, and database performance is not so important

· Note: Many large games use shared memory to avoid excessive losses during downtime.

2. The performance of a single CPU is more important than the number of CPUs.

3. There are many games, especially mobile games, which use Redis to read and write instead of memory, and even Mongo is also useful.

4. The situation of opening new services and combining services in old areas is very suitable for cloud platforms.

Five, advanced server framework

· Advanced Server Framework 1 BigWorld

Representative works of BigWorld engine:

· China: "Tian Xia II", "Tian Xia III" and so on dozens of models, NetEase has contributed a lot to the practicality of BigWorld.

· International: Early versions of "World of Warcraft", "World of Tanks", "War Thunder"

The core idea of ​​BigWorld is to return to the scene segmentation problem mentioned above.

BigWorld uses the principle of plane segmentation to divide the scene into small pieces, and different pieces can run on different servers. Moreover, the division of blocks is dynamic, and the size of blocks is dynamically adjusted according to the intensity and number of players. .

Technically, the Actor model is used, and each object is required to be an independent Entity, and the objects can only collaborate through messages, strictly limiting the direct interaction between objects.

Later, with the rise of mobile games, the decline of terminal games, and the diversification of online game play, this series of changes caused the BigWorld engine to quickly decline.

The BigWorld engine has gone from being a big hit to no one cares now, reflecting the development trend of game server technology. BigWorld's mandatory Actor model actually sacrifices development efficiency in exchange for server scalability.

Theoretically, the number of people carrying a single server can reach millions. However, the business logic of the game is frequently modified, and the low development efficiency is an unbearable burden for game designers.

This architecture is inherently prepared for cloud computing, and the carrying capacity of a single physical machine is very limited, and each game area requires a large number of physical machines.

If BigWorld succeeds... Unfortunately, it runs counter to the development trend of the actual market.

Compared with the e-commerce system, game development is several orders of magnitude smaller in scale, but relatively, the iteration speed is several times faster. If there are different types or gameplay between projects, there are not many codes that can be reused.

Talk about 100,000 lines of code. The speed of game server development is restricted by the speed of art resource production and client development speed. In recent years, I guess there will be no major technological innovations in servers.

The future trend of game development is diversification, low threshold, and popularization. For a long time, BigWorld, a monster-level engine, will not rise again.

The time of the rise of the distributed framework, in any case, is also after the maturity of VR technology.

· Advanced Server Framework 2, Skynet

Skynet is an emerging general-purpose server framework (completely open source), which walks between traditional servers that are not easily distributed and distributed servers.

It is a general-purpose framework that can not only be used as a game server framework, but also has amazing performance for building HTTP services (a simple HTTP implementation of a few hundred lines of code can reach 60% of nginx's performance).

Paradoxically, because it did some important hacks on the scripting virtual machine, it was completely bound to the language Lua.

Skynet principle explanation:

The service is abstracted into microservices. Thousands of microservices can be built in a system. Skynet schedules m threads (m=number of CPU cores) and processes the events of n microservices.

Since n microservices are in the same process, internal communication with zero latency can be achieved (no copy in extreme cases)

At the same time, the Lua virtual machine also provides a sandbox mechanism. The Lua logic code between microservices will not have any interference. When necessary, data can be shared at the C language level and outside the Lua sandbox.

Because the service itself has good isolation, it can be more convenient to deploy the service on multiple physical machines (considering performance issues, it cannot be deployed arbitrarily like BigWorld).

The Skynet architecture has been widely used in game companies of the Lua system (represented by NetEase), and has quietly penetrated into other companies. (Similar to the situation of Lua language back then, gold always shines.)

6. Advanced server framework 3. Other frameworks based on Go language

The goroutine feature of Go language brings huge imagination to game developers.

On the basis of the Go language, it is easy to have a better room-style game framework, a Skynet-like framework, and an improved traditional framework.

But it can be boldly predicted that the final effect will not exceed the scope of frameworks such as erlang and skynet. This is because of the characteristics of the game business itself.

Concluding remarks

This article briefly discusses the development of mainstream server frameworks in the past ten or two decades, focusing on the most representative type of online games such as MMO-RPG (at the same time MMO poses the greatest challenge to server architecture), and talks about some other Type of game. Due to the variety of game types, developers in various countries and regions have very different architectures. It is inevitable that the article will miss 10,000, but it does not affect the overall context, nor does it affect the summary of the core issues of online game servers-logical disassembly Minute.

Recommend to everyone a training camp about the actual combat of the skynet project. Registration is now equivalent to free. The main content:

Multi-core concurrent programming
message queue. Thread pool
actor message scheduling
Network module implementation
Time wheel timer implementation
lua/c/interface programming
Skynet programming essentials
demo demonstrates actor programming thinking

Address: Click to watch the video.
More skynet information plus group: 832218493 Get it for free!
Insert picture description here

Guess you like

Origin blog.csdn.net/lingshengxueyuan/article/details/112363892