Design and Application of ACE framework in online game servers

Source: Internet
Author: User
Design and Application of ACE framework in online game servers
Tao Dao, Wan wanggen
(School of Communication and Information Engineering, Shanghai University, Shanghai 200072, China)


With the development of computer networks, especially the emergence of the Internet, the digital entertainment and online gaming industry has been booming, and the emergence of online games has become a pioneer in China's network industry. And
With the advancement of information technology, computers, mobile phones, and different media terminals are constantly emerging. How to interconnect and interact these terminals over the Internet has become a major technical difficulty, the breakthrough of these difficulties depends on
Developed for online game servers. Currently, the software design mode has been widely used in the design and development of various server communication software. Modular Configuration is often used in the development of large-scale server communication software.
. When a large server system executes tasks, different modules are usually used for collaboration. In this case, data communication between machines becomes very complicated and complex. Different Operating Systems
Different information mechanisms also affect the development and efficiency of communication software. Network programmers usually develop from the underlying layer, which greatly increases the difficulty and cycle of software development. To address the above problems, Ace Adaptive Communication
The architecture provides a good solution. Ace can carry out common network programming tasks across a variety of operating system platforms, combined with the software design mode, this avoids re-development of communication software based on different environments.
Vulnerabilities reduce the software development cycle and funds, and simplify and strengthen the system design.

1 ACE framework

Ace adaptive communication environment (Adaptive
Communicationenvironment is a free-to-use, open-source object-oriented (OO) framework, in which many implementations are used for concurrency.
The core mode of communication software. ACE provides a rich set of reusable C ++ wrapper
Facade and framework components can complete common communication software tasks across multiple platforms, including: Event Multi-Channel Separation and event processor allocation, signal processing, service initialization, inter-process communication
Information, shared memory management, message routing, distributed service dynamic (heavy) configuration, concurrent execution and synchronization. The ACE architecture includes three basic layers: operating system adaptation layer, C ++ packaging layer, and framework components.
Layer. The operating system adaptation layer directly resides on the local OS API written in C.
API-related platform proprietary features are shielded. The abstraction provided by the ace operation adaptation layer greatly enhances the portability and maintainability of ACE. The C ++ packaging layer provides type-safe
C ++ interface simplifies communication applicationsProgramVarious Applications can selectively inherit, aggregate, or instantiate components to use these packages. ACE also includes an advanced network programming framework that integrates and enhances
Lower-level C ++ packaging layer. This framework supports dynamic configuration of concurrent distributed services.

Most networked applications can be developed through a portable middleware such as Ace, because Ace encapsulates and enhances the local operating system mechanism, and its components can remove the underlying operating system API
Tedious and error-prone creating reusable network programs.

2 network game Server System Framework Design

In the process of designing a network server, how to ensure the security of the server and maximize support for more client connections is an important issue for developers. To solve these two problems
Verification: The following server architecture can effectively solve the above two problems during game server development.

2.1 game server architecture supporting Gate

In this architecture, the client is connected to the gate server instead of directly connected to the game server. Gate
The server is mainly responsible for forwarding data packets between the client and the game server, and the game server is responsible for processing all the logic of the game. 1.

This architecture has the following advantages: the client is connected to the game server game Servet through gate setver, and the game server
The IP address is invisible to external users, making the game server safer and more vulnerable to attacks. A game server can also correspond to several gates.
When a gate server is under attack or shut down, other gate servers continue to run as usual.
The Client Connected to the server can still play the game normally; more client connections are supported. The gate server distributes many client connections to multiple games.
Server, rather than alone, to support more client connections; gate server can share part of security management work to reduce game
Server pressure. For example, if a client does not send data packets for a period of time, the gate server can take the client offline.

2.2 division of software functional modules

When designing a server framework, there is a basic principle: the specific implementation of the Framework and the communication underlying needs to be separated. The specific implementation of the communication underlying does not affect the framework.Code. Because the specific implementation of the underlying communication layer is very
Multiple methods, the specific implementation of different operating system platforms is also very different. For example, only Windows platforms have windows message-based, event-based, and completed ports.
I/O model implementation. The separation of the framework and the communication underlying layer is also conducive to the use of some mature development frameworks, such as the ACE framework. In this way, when a new communication technology is used to achieve the Communication Base
Layer, you can modify the communication underlying layer without changing the Server framework. When designing a server, the server framework is designed into multiple modules based on the principle that the server framework is separated from the communication underlying layer. And generate the corresponding
Dynamic Link Library for calling. The software module framework 2 is shown.

In software module division, the underlying communication layer consists of thread modules and communication modules, and the upper layer consists of synchronization, online management, and interest zone management modules. The synchronization module is based on conservative/optimistic synchronization.AlgorithmStructure
The server synchronization subsystem is built, and the client can use the space speculation method to reduce the server packet sending frequency. The interest area management module is used to filter correlation information. By subscribing to a range of players' interest, this module can effectively reduce
Low network bandwidth consumption and server load. The online management module is mainly responsible for compressing and encrypting the communication protocols and data packets in data packets. data packets are encrypted to increase the security performance of the server system.
To reduce network bandwidth consumption.

3. Implementation of Server System Communication

3.1 Implementation of thread Module

In the design thread module, the ace_task class and ace_message_queue in the ace framework are used to implement the active object mode. They are used to process active objects and implement multithreading.
. The traditional object is a passive code segment, and the code in the object is executed in the thread that calls the method to it. When the method is called, the call thread will be blocked until the call ends. The active objects are different.
These objects have their own command execution threads. The methods of the active objects are executed in their own execution threads without blocking the calling methods. Because the method call of the active object is not blocked, the system response speed is improved.
Degree.

In the design, the active object inherits the ace_task, the application open is initialized, and the derived thread cyclically determines whether there is a method object in the method queue. If the queue is not empty, the method is queued and executed.
3.

When creating a task and an active object, the subclass is derived from the ace_task class. After the subclass is derived, take the following steps:

(1) Implementation of service initialization and termination methods: the open () method should contain all the initialization Code dedicated to the task; the close () method contains the corresponding termination method.

(2) Call the Activation Method: After an active object is instantiated, it must be enabled by calling activate. Number of threads created in the active object and
Other parameters need to be passed to the activate () method. The activate () method will make the SVE () method the startup point of all other threads.

(3) Implement the proprietary Processing Method of the service. After the active object is enabled, each new thread starts in the SVC () method.

The procedure 4 for implementing the concurrency policy is as follows:

3.2 Implementation of the Communication Module

3.2.1 ace reactor and forward camera ace proactor

Ace
Reactor and proactor are scalable object-oriented multi-channel splitters that distribute application proprietary processors to respond to various types of I/O-based, timer,
Signal and synchronization events.

Ace_reactor is used in synchronous I/O operations to implement multi-channel event separation and allocation, and can process I/O from multiple sources. Three steps are required to use the reactor framework:
One or more event processor classes are derived from ace_event_handler, and corresponding event processing behaviors are defined. The application event processing objects are registered to the ace_reactor class. Run
The ace_reactor event loop calls back the event processing function in the event processor when an event occurs.

Ace_proactor is applied to asynchronous I/O operations. Unlike the reactors, ace_proactor waits for the event to be completed, and then processes the event after the callback is completed. After I/O read/write is initialized
To the system. After the event is completed, the camera returns the execution I/O result to the object and processes the event after the callback is completed. The preference model allows a single application thread to initiate multiple requests at the same time. This design allows
A single-threaded application executes multiple I/O operations concurrently without the overhead or design complexity associated with the traditional multithreading mechanism. This greatly reduces the I/O processing time.

3.2.2 efficient asynchronous I/O data communication using the predictor

The main participants in the pre-Camera mode used in the communication module include the pre-camera initiator, processor, asynchronous operation, asynchronous operation processor, and dispatcher. Its structure is shown in Figure 5:

The precamera initiator (the main thread of the server application) is the entity of any Asynchronous Operation in the application. He registers the completed processor and the completed dispatcher to the Asynchronous Operation processor. Completed processor interface for different
Step-by-step notification. asynchronous operations are used to execute requests on behalf of applications. When the asynchronous operation is complete, the Asynchronous Operation processor delegates the Application Notification to the completion distributor. Asynchronous operations are run by the Asynchronous Operation processor.
This component is usually implemented by the operating system. The completion dispatcher calls back the application's completion processor when asynchronous operations are completed. When the Asynchronous Operation processor completes the asynchronous operation
Execute the application callback. Figure 6 shows the interaction between the implementation of this mechanism:

3.2.3 establish a Communication Connection

In a specific communication module, the main types of ACE used include asynchronous connection, service processing, asynchronous operation, and processing result. The connection process is as follows: Create an asynchronous active connection and a passive connection subclass,
During asynchronous connection, a new service processing class is created and the service class is passed to the asynchronous connection class. In this way, data transmission is performed by the service class. Implement the Hook method provided in the Service Processing subclass and
Create an ace_sock_stream and an asynchronous read/write stream class for asynchronous communication. Register the asynchronous read/write stream to the created proactor during initialization, and save the sentence of the asynchronous read/write stream class.
Handle. Finally, the result and status of data transmission are handed over to the processing result class for processing. Asynchronous Communication initialization:

(1) create a derived class of the asynchronous active connection class and a derived class of the passive connection class respectively.

Class tcommandchannelconnectoracelmpl: Public
Ace_asynch_connector <tcommandchannelacelmpl>

Class tcommandchannelacceptoracelmpi: Public
Ace_asynch_acceptor <tcommandchannelaceimpl>

(2) create an active connection Class Object connector and a passive connection Class Object acceptor;

(3) for active connections, call connector. Open (...), And register it with proactor. The framework automatically creates an asynchronous communication service class and automatically detects connection creation.
Status;

(4) For passive connections, call acceptor. Open (...), And register it with the proactor. The framework automatically creates an asynchronous communication service class and automatically detects connection establishment.
Status, waiting for listening;

The entire asynchronous communication mechanism is implemented in Process 7:

3.2.4 ace_proactor Multi-Channel Separation

The ace_proactor class is responsible for driving the completion of the pre-camera framework. To enable asynchronous I/O to complete event processing, you also need to run the event loop of the camera.
.

4 knots

This article designs a server-side architecture suitable for developing online games, and uses the ACE framework component and the object-oriented design mode to develop the underlying server communication. Ace is a free and open-source
Middleware is a practical design model rich in network and system programming. It has excellent features such as cross-platform, and is suitable for the development of any communication software. Especially for online game server developers, Ace is undoubtedly a value
The communication framework has good application prospects.

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.