A scalable, fully asynchronous C/S architecture server implementation based on QT (a) overview

Source: Internet
Author: User

This paper introduces the implementation of a scalable TCP service based on Qt. This implementation is built for c/sclient-service cluster application requirements.

Connection monitoring, data transmission, and data processing are carried out in a separate thread pool, depending on the specific task, the number of threads responsible for listening, transmitting, and processing can be arranged so as to achieve a trade-off between high transmission load and high calculation. Pipeline structure for data processing. To avoid the intensive calculation requests of a small number of customers affecting other client processing.

The corresponding code in this article conforms to the LGPL protocol and can be downloaded directly from Https://github.com/goldenhawking/zpserver. can also be downloaded from http://download.csdn.net/detail/goldenhawking/7461157

First, the summary

In many industry applications. client-Service architecture is not an alternative.

Under the client-service architecture, services play an important role.

This article is intended to introduce a more general form of service implementation. This form can be configured flexibly based on detailed application requirements. Thus reducing the time to develop repeatedly. The service implementation supports at least two of the following requirements.

The first type is the forwarding service , which is responsible for communication between the two clients, and does not do complex processing. Such services generally have to withstand dense connections, in some applications. It also has to withstand heavy transmission loads. Typical includes instant messaging, two intra-intranet video communication, etc.

The second type is computational services , which are primarily responsible for receiving the client's raw data. The result is returned after processing.

Such services are typically performed on high-performance servers, invoking back-office parallel Computing and heterogeneous computing resources. The result is returned to the client after processing. The number of clients for these services is generally not large. However, in some applications, when the input and output data is large, the transmission load is also very heavy.

In order to meet the above two types of requirements, service design has such as the following characteristics.

1. Can set the monitoring port flexibly

2, monitoring, transmission, processing are performed in a separate thread pool.

3, can be based on the need. Flexibility to set the number of transfers and processing threads.

4, the processing of a single client. The response of all clients is not slowed down significantly.

5, the need to support distributed cluster services, the typical situation is based on a number of physical computers composed of fast LAN implementation process cluster.

6, can support SSL and ordinary TCP connection at the same time.

These characteristics determine the architecture design of the system.

(i) System structure

The service consists of several modules.


1, network transmission module . Manages sockets for listening, transmitting, and controls the flow of data across different threads.

The data is sent and received by a certain size thread pool, and the implementation method is fully benefited from the thread event loop of Qt. A Qobject object that is bound to a qthread. Its signal-slot event loop is the responsibility of the thread. This makes it easy to specify the thread that is used by a socket object.

The same, benefit from a good package of QT, directly support TCP sockets and SSL sockets. And can be dynamically adjusted at execution time. ( Note: Compiling this module requires QT SSL support, i.e. adding the-OPENSSL option when configure )

2, task Pipeline module . Responsible for the data processing.

In computing-intensive applications, the data processing load is heavier and needs to be separated from the network transmission.

Based on the processing mode of the common thread pool, there is also the problem of queue congestion-the time-consuming operation of several client requests, which blocks the response of other clients. Even other client requests can be processed in a very short time. must also wait in line. The use of pipelining thread pooling avoids this problem. Each client takes the granularity of what needs to be done, and in a circular queue, the thread pool processes only one granular unit of work per client at a time. After a single granular unit is complete. The remaining tasks of the client are then inserted again at the tail of the queue. This mechanism ensures that the overall latency of the client is small.

3, service Cluster Management module. The module uses the function of Network transmission module and Task pipelining module to realize the Server?àserver link of cross-process.

In fast LAN, the connection is fast and stable. As a result, the module is designed as a star-free hub network. Randomly add a server node to select a random node in an existing server cluster. After access. Proactively establish point-to-point connections to other server nodes by broadcasting themselves. This module simply provides a server-to-server communication tunnel and is not responsible for interpreting the contents of the detailed communication. Control of the transmitted content. Determined by the detailed application.

4, database management module .

This module is based on QT's plug-in database encapsulation Qtsql.

The database is managed as a resource. Supported under multi-threaded conditions. Use database resources.

5, Frame interface . While the common service execution is performed as a background process. But in order to better demonstrate the functionality of the server. Avoid cumbersome configuration, or need a graphical interface to display the status, set the number of parameters.

In this example, the interface is responsible for rotation the various states of the server. and set the number of parameters. The set parameters are stored in an INI file and loaded when the service is opened.

6, application of proprietary parts module。 The above 1-4 total of four main modules are universal.

They are not linked to each other, but as a resource exists in the execution of the program (runtime).

The application of the proprietary part of the module according to the detailed task requirements, flexible use of the above resources to achieve functionality. In the sample code, a point-to-point forwarding mechanism is implemented. The presenter virtual out some industrial equipment. And some of the client software used by the operator. The device and client software are required to exchange data after successful authentication and login. By changing the code of this module, you can implement your own functionality.

(ii) Design performance

Project

Indicator description

Indicator values

Note

Supported Connection types

Depending on the type of support for QT

SSL and Plain

Two classes are supported at the same time in execution.

Agreement

Ipv4 TCP, IPV6 TCP

Design the number of single-process connections

Computed under 4\8 transport thread configuration

1024\2048

Depends on the actual machine performance and task form.

Design cluster size

The size of a star cluster is affected by the number of nodes.

100 nodes, 9,900 cross-server connections.

The number of connections in the LAN is node count * (Number of nodes-1).

Design Total User Size

100 nodes, 2048 users per node

200,000

In the next article, we will begin to introduce the design ideas of each module. First, we give the sample code of the test compilation environment:

1, Ubuntu 14.04 + Qt5.2.1 OpenSSL self-compiled version

2, Win 7 x64 + vcexpress x64, x86 + Qt 5.2.1 OpenSSL self-compiled version

3, Win XP x86 + vc2010express x86 + QT5.2.1OPENSSL self-compiled version

Main interface:



A scalable, fully asynchronous C/S architecture server implementation based on QT (a) overview

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.