Simple Network Application Platform Design

Source: Internet
Author: User

In network communication applications, it is a complicated project to develop a stable, efficient, scalable, and scalable network application system with a single host carrying thousands or even tens of thousands of users online at the same time, it involves many professional knowledge, such as TCP, UDP, socket development, multi-thread programming, thread pool, concurrency architecture, distributed architecture, and completion port (iocp) model, asynchronous programming model, design mode, and so on. I recently studied various online network programming introductions, so I have the following ideas.

Most network applications use the following framework:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/F8/wKiom1QgyYSywjr7AAIUXtrBKNU739.jpg "Title =" 1.png" alt = "wkiom1qgyysywjr7aaiuxtrbknu739.jpg"/>


The network application platform consists of the device layer (client and terminal device), platform layer (primary application server and secondary Application Server), and service layer (functional server and functional plug-in), data layer (Network Database ).

Function server (FS) is a function server that processes and only processes all functional requests, and does not participate in user management or status maintenance. It provides pure functional services. The number of functional server FS in may be 0 to n (n> 0. In a sense, each function server FS can be considered interchangeable. Because FS only provides the most pure functional services and does not require user management and State persistence, this function server is stateless during running, making it easy for functional servers to implement Load Balancing clusters.

As (appliction server) application server, main functions include: management of various external devices (Cu, Pu) maintain the status of external devices, authenticate Device Permissions, route system messages, provide the "framework + plug-in" structure management service function plug-in (addins), management function server (FS), and so on.

As supports the "Regional distributed" architecture. The above 4-layer architecture is already a distributed architecture, but this distributed architecture is a "vertical" architecture, while "regional distributed" focuses on "horizontal ", in the "Regional distributed" architecture, the implementation of each specific "layer-4 architecture" is only an element.


As Application Server

As Application Server mainly implements server functions, including managing various external devices (Cu, Pu, FS) maintain external device status, device permission authentication, system message routing, and provide the "framework + plug-in" structure management service function plug-in (addins ). The AS Application Server provides the underlying network communication framework. You only need to focus on specific business processing, instead of how to implement the underlying network communication. You can process specific services in two ways. One is to directly develop the corresponding service processing plug-in and load it to the AS Application Server plug-in Manager through the plug-in framework. The other is to develop a FS function server to access the AS Application Server. The AS Application Server forwards business data to the FS function server and then processes the data by the FS function server. The former is suitable for services with simple functions and lighter processor loads, while the latter is suitable for services with complicated functions, large I/O throughput, and heavy processor loads (such as chip and video processing ).


As application server module diagram:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/F8/wKiom1Qgy1jxX7d3AAKhHK4E36o467.jpg "Title =" 2.jpg" alt = "wkiom1qgy1jxx7d3aakhhk4e36o467.jpg"/>


The main modules of the AS Application Server include:

1. Asynchronous Network Module.

2. network stream parsing module.

3. Message pipeline module.

4. Message subscription and publishing module.

5. device module.

6. Business pool plug-in module.

7. Application Server Module.


Semi-synchronous-semi-Asynchronous Parallel Mode

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/FA/wKioL1Qgy76gQxDoAAFB-llD7Qk739.jpg "Title =" 3.jpg" alt = "wKioL1Qgy76gQxDoAAFB-llD7Qk739.jpg"/>



The network application platform uses the semi-synchronous-semi-asynchronous mode to solve concurrency. The Unit is described as follows:

LSynchronization task layer (user level)

The task at this layer is to complete the processing of message data. Data is transmitted through the queue at the queue layer using the Synchronization Model. Unlike the asynchronous layer, the synchronization layer tasks are executed using activity objects, which have their own running threads. When a synchronization task is executed, it may be blocked.


LQueue Layer

This layer provides synchronous control and caching between the synchronization task layer and the asynchronous task layer. The I/O events of asynchronous tasks are cached in the message queue, and the synchronization task layer extracts these events from the queue.


LAsynchronous IoLayer

Process low-level events, which are generated by multiple external event sources (such as NICs and terminals ). Unlike a synchronization task, the object in this layer is a passive object and cannot be blocked because it does not have its own running thread.

 

When an external event arrives, the components of the semi-synchronous-semi-asynchronous mode collaborate and process the event. The collaboration process is divided into the following three phases:

1. asynchronous phase: through asynchronous event notification, external event sources and asynchronous task layers can complete interaction.

2. queuing phase: the queue layer provides a synchronous control mechanism to respond to input events and cache messages between the synchronization layer and the asynchronous layer.

3. Synchronization phase: the synchronization task layer extracts messages from the queue layer. Note: The data transfer protocol between the synchronization layer and the asynchronous layer is independent of the specific communication method of the queue layer.

The producer/consumer model is used for communication between the synchronization layer and the asynchronous layer. The key to understanding this model is that the synchronization task is the activity object. They can block the call to read or write at any time. If the data is not ready, these activity objects can wait. On the contrary, the entity at the asynchronous task layer is a passive object. They cannot be blocked. These objects are triggered by notifications or external objects.


Asynchronous Network Module

The Asynchronous Network Module provides basic network operation functions for the upper layer, including setting up server listening, accepting external connections, and actively connecting to a remote host. All network operations are performed asynchronously to improve concurrency.


Device Module

The main function of the device module is to access devices in the management network and maintain device operation permissions.


Message parsing module

After receiving a message stream, the network layer needs to parse the message stream and package the parsed messages into the message structure agreed in the system.


Message Queue Module

After receiving data in the network, it is parsed by the parser. The received message body directly enters the system message pipeline framework for processing. The message pipeline Processing Framework is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/FA/wKioL1Qgz7ay6XOqAAG29agdmjc812.jpg "Title =" 4.jpg" alt = "wkiol1qgz7ay6xoqaag29agdmjc812.jpg"/>

The message pipeline framework involves multiple modules, including the Asynchronous Network Module, message pipeline module, and message subscription-publishing module. The message pipeline framework is a bridge between the system's message processing process ", the system decouples the network layer and application layer through the message pipeline framework.

Messagepipe can be seen as the "encapsulation" of gatewaymessagespy, messagetransformer, and innermessagespy. The processing sequence of messages entering the message queue is gatewaymessagespy, messagetransformer, and innermessagespy. The processing sequence of the outbound message queue is innermessagespy, messagetransformer, and gatewaymessagespy.


Message subscription and Publishing

When the platform receives a message and intends to pass it to the business logic layer for processing, there are multiple methods to achieve it. We use the message subscription and publishing mode to "Deliver" messages from the platform to the business logic ". Each business logic acts as a subscriber to subscribe to messages of interest to the publisher. When a message arrives at the publisher, the publisher calls the corresponding function of the subscriber to process the message. The message subscription and publishing mode reduces the coupling between the platform and business logic, and uses a unified message subscription interface to reduce dependencies.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/F9/wKiom1QgzWeSBwN0AAF-wbjb7dI496.jpg "Title =" 5.jpg" alt = "wKiom1QgzWeSBwN0AAF-wbjb7dI496.jpg"/>

The entire network platform uses the semi-synchronous-semi-asynchronous mode in the parallel mode. The asynchronous layer is the Asynchronous Network Module, after receiving the data, the Network Module puts the data into the message subscription and publishing module, while the queue and synchronization layers are implemented by the message subscription and publishing module. In the message subscription and publishing module, the message processor piles up the message data from the asynchronous cache layer, at the same time, the message processing component in the processor heap continuously retrieves messages from the message queue as the active object and calls the corresponding message subscriber function.

The message processing module includes the message subscription-publish module and message execution module. The message subscription-publish module mainly implements the system message subscription-publish framework, the message execution module caches the message data sent from the network layer, retrieves messages from the message queue, and simultaneously processes messages as active objects.


Application Server Module

The functional server module is one of the core modules of the network application platform. Its main function is to integrate other functional modules to build a unified network management platform.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/FA/wKioL1QgzgfDg4QTAAHTJe-_IaA478.jpg "Title =" 6.jpg" alt = "wKioL1QgzgfDg4QTAAHTJe-_IaA478.jpg"/>

A single server is usually used to support communication applications that can connect thousands of devices online at the same time. However, when the number of devices online at the same time reaches tens of thousands, hundreds of thousands, or even millions, we need a lot of servers to share the load. However, organizing these servers based on the rules and structures and enabling them to coordinate and cooperate with each other are the most critical issues. The network application platform aims to help quickly build large-scale network-based communication applications. The network application platform also solves massive concurrency through Application Server clusters.

The network platform adopts a domain-based distributed architecture and is divided into a level-1 platform and a level-2 platform. Each domain contains a level-2 Application Server and several functional servers, terminal devices, client devices, and databases. The second-level application server manages all access devices in the domain. The domain and the domain are relatively independent, and the Inter-Domain node cannot be accessed directly. The second-level application server in each domain is centrally managed by the first-level application server. Inter-Domain access is performed through the first-level application server to exchange data.


Unified device code across the network

To identify all devices connected to the network platform, a unique identifier must be assigned to the devices on the network platform.

The encoding is as follows:

XXXX | xxxx32 in totalBITs, first 16Bit indicates the region encoding, the last 16Bit indicates the node encoding in the region.

The Application Server encoding format is xxxx0000, and other devices are encoded as XXXXXXXX. The application server and all devices in the same domain have the same region code. Therefore, you can use the region code to determine whether the device and Application Server are in the same domain.

 

Message routing across the network

Messages on the network have both the sender and the destination. How can messages flow across the network platform? What should I do when a terminal needs to send a message to another terminal or when the terminal needs to reply to a message sent from another terminal? In this case, you need to consider how messages are routed to the destination in the network.

 

Message Body route ID

The message body in each network has the following structure:

<? XML version = "1.0" encoding = "UTF-8"?> <Message version = "1.0"> 

WhereFrom,The field indicates the message source and the Message destination. You must enter the from and to fields correctly, whether you are actively sending messages to or replying to messages from the terminal.


Asmsggatewayspy)

After receiving a network message, the second-level application server must first determine whether the current message is sent to the device in the current domain. If the Message destination is a local device, the message is delivered to the corresponding device through the second-level application server. If the Message destination is not a device in the current domain, the message must be delivered to the second-level application server in the current domain, let the level-1 application server deliver the message to the level-2 Application server of the corresponding domain, and then the level-2 Application Server forwards the message to the corresponding target device.

The message pipeline processing mechanism solves the problem of Route processing when network messages arrive at the application server. We can implement an igatewaymessagespy interface to implement message routing in the spymessagereceived function.









This article from the "sensitive" blog, please be sure to keep this source http://9249657.blog.51cto.com/9239657/1557201

Simple Network Application Platform Design

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.