Detailed explanation of mobile game server development technology and server Development Technology

Source: Internet
Author: User

Detailed explanation of mobile game server development technology and server Development Technology

Welcome to reprint, reprint please indicate the original address: http://blog.csdn.net/majianfei1023/article/details/46716073


I have been engaged in game server development for almost two years. I have participated in many projects, learned many game server development technologies, and participated in server development with several different architectures, just talk about the technologies required for game server development. (The Game servers mentioned below are more inclined to mobile games, because I have little access to client games and web games)


1. Let's talk about something to consider about server development.

1. Selection of development languages:

To do what they want, you must first sharpen the tool. choosing a suitable development syntax will do more with less for later development.

The main game servers in the industry are c/c ++ Python/lua mode. C/c ++ implements network communication data transmission, and python/lua implements business logic. This not only ensures the efficiency of network transmission (c ++), but also improves the development efficiency (Python/lua) and supports hot updates.

Of course, there are also other server development languages, erlang (never used, many web game companies use), c # (awesome country, amazing nation ), java (I was shocked when I first heard of it), node. js (for a small number of games, there is also a node. the engine written in js is called pemolo. php (php + mysql is also a good choice for http Communication games ),...

Two game server Engines

1. firefly (9 s community developed a python game server framework) https://github.com/9miao/Firefly

2. kbengine (the author said he was designed based on the bigworld architecture, c ++ python) https://github.com/kbengine/kbengine


2. Database
Currently, two popular types of databases are relational database mysql and non-relational database mongodb. This is the two most used databases.
There are many comparisons between the two on the Internet. Of course, you can also use other databases. for SQL server, if you are not afraid of being pitted, use it (I have never liked Microsoft's stuff ).

3. Server Architecture
One of the architecture models I have used is also designed by the company based on the bigworld architecture:
1. Gate: first, there must be a gateway Server responsible for client connection and message forwarding to Game (Game server) to maintain the connection between the client and the server.
There is no logic, only message encryption and decryption, and the client and server message Forwarding (equivalent to the bridge between the two ).
2. gameServer: GameServer is a game process that provides the game logic function (single-process (or single-thread) model. the bottleneck of the game server is never on the CPU. Therefore, if you only use the logic function, a single thread is sufficient, here there is no need to use multiple threads or multi-process ).
3. DBManager: Implements database read and write, facilitating the Game server to asynchronously read and write database data (some put the database read and write on the Game server, and there is no separate server, so I am afraid the single process in the Game server is not enough ).
4. GameManager: manages all GameServer and GameServer message forwarding and provides the function of broadcasting to all games.


4. Protocol
Protocol communication between the client and the server. You can use tcp or http. The main focus is on the Game Model. If it is a stand-alone method with Weak networking, it is enough to use http, such as daily cool run, to process an http request response only when needed.

However, there are still many tcp comparisons. Most of today's online games are tcp, such as MMORPG games. Our current game uses both http and tcp, and the client and game server adopt http protocol. Tcp persistent connections are used only when multiple battles are switched to the combat server.

Udp: in fact, the game has udp. In some efficient scenarios, such as real-time pvp combat, tcp congestion control and timeout retransmission are not suitable, and some use udp, then we re-send packet loss, and change the network fairness to the efficiency of the game.

Now the game involved in development uses both http and tcp Protocols. In the game server, http is used for standalone gameplay. The battle server requires a persistent connection to save the Protocol Status and uses tcp.


5. Inventory

If there is a database, there must be database read/write operations. The most important thing is to save disks, and to save disks periodically or instantly.

Instant storage means that each operation data is stored in the database. Of course, this will lead to too frequent operations on the database. After all, this is one of the bottlenecks in efficiency.

A periodic disk is also called a Fixed Disk, that is, a disk is stored at a fixed time, for example, 10 seconds or 15 seconds. In this way, the pressure on the database will be much lower. Of course, you must perform data operations in the memory, prevents data contamination or data storage failures, resulting in rollback.


2. Develop an open source technology to be mastered by a game server
1. libevent, boost. asio and other network libraries. There are many open-source network libraries on the Internet. Instead of making their own wheels, it is better to use the open-source network library as the communication library of their own servers. The most famous ones are libevent and boost. asio.
Boost ASIO is an asynchronous IO library that encapsulates common Socket operations and simplifies socket-based program development. Supports cross-platform.
Libevent is a C language written event-driven Open Source Network Library, see: http://blog.csdn.net/majianfei1023/article/details/46485705
The efficiency between the two is benevolent.
Of course, there are many more such as skynet (c + lua) written by Yunfeng and muduo (c ++) written by Chen Shuo ). They all write well, and Yun Feng's writing is simple and easy to use. Chen Shuo is presenting his c ++ technology.

2. protobuf: Google Protocol Buffers, a tool library developed by google for data storage and Protocol coding/decoding during network communication. It is similar to XML or JSON, that is, it saves the information of a certain data structure in a certain format (XML, JSON,
Protobuf differs from XML and JSON in that protobuf is binary-based. It is mainly used for data storage and transmission protocol formats. See specific: http://blog.csdn.net/majianfei1023/article/details/45112415

Protobuf has the advantage of being compact and small in data generated for transmission of relatively large data, which can significantly reduce the transmission volume.
In addition, the processing speed is also relatively fast, and there are various programming languages, such as C ++, Java, PHP and so on.
The disadvantage is that it cannot be edited in plain text (the data is binary ).

It is convenient to use protobuf rpc for data transmission, so it is a good choice. Google protobuf is only responsible for the packaging and settlement of messages, and does not include RPC implementation. Therefore, you need to implement it by yourself.


3. zeromq: Message queue, the basis of a robust and concise multi-process communication solution. ZeroMQ is not an encapsulation of socket and cannot be used to implement existing network protocols. It has its own mode, which is different from the underlying point-to-point communication mode. It has a higher level of protocol than tcp. (Of course, ZeroMQ is not necessarily based on the TCP protocol. It can also be used for inter-process and intra-process communication .) It changes the assumption that communication is based on one-to-one connections.
Here, it is more suitable for communication between servers, such as communication between the logic server and the combat server.

4. memcached: a high-performance distributed memory object Cache System for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of reads to the database, thus improving the speed of dynamic and database-driven websites.
It can be used for caching. For example, the client needs to operate the database for each operation, which seriously affects the efficiency. In this case, a cache system is added in the middle to improve the performance. Memcached is a good choice for http-based communication. For tcp persistent connections, you can directly maintain an online memory object.
Similar technologies include redis.

5. glog/zlog: You must record the log.


6. tcmalloc: Memory Performance Analysis


7. distcc: distributed compilation tool. make takes half an hour to modify the code each time before. It is much faster to use distcc to compile multiple computers at the same time.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.