CN116781764A - Long-connection task execution method and device and related equipment - Google Patents

Long-connection task execution method and device and related equipment Download PDF

Info

Publication number
CN116781764A
CN116781764A CN202210226181.4A CN202210226181A CN116781764A CN 116781764 A CN116781764 A CN 116781764A CN 202210226181 A CN202210226181 A CN 202210226181A CN 116781764 A CN116781764 A CN 116781764A
Authority
CN
China
Prior art keywords
information
target
client
task
request
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210226181.4A
Other languages
Chinese (zh)
Inventor
张伟
李万勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202210226181.4A priority Critical patent/CN116781764A/en
Publication of CN116781764A publication Critical patent/CN116781764A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the application provides a long-connection task execution method, a long-connection task execution device and related equipment, and relates to the technical field of Internet of things; the method can be applied to the scenes such as message pushing, instant messaging service, internet of things communication service and the like. The long connection task execution method comprises the following steps: receiving a target request sent by a first client through a long connection channel; the target request carries target task information; invoking a target queue thread corresponding to the first client based on the target task information, and executing a target task corresponding to the target request by the target queue thread based on pre-stored task information stored by adopting a dictionary data structure; based on the target request, feeding back the result information of the target queue thread executing the target task to the first client through the long connection channel; the long connection channel and the first client establish a corresponding relation based on the identity of the client. The implementation of the application can support high concurrency requests of the client.

Description

Long-connection task execution method and device and related equipment
Technical Field
The application relates to the technical field of the Internet of things, in particular to a long-connection task execution method, a long-connection task execution device and related equipment.
Background
With the development of internet of things, more and more clients request to establish long connection with a server. In the existing service implementation scheme based on long connection, the number of long connection supported by a server is small, and after the number of the supported long connection reaches a certain threshold, the problem that a client request is overtime easily occurs.
Disclosure of Invention
The application aims to provide a long-connection task execution method, a long-connection task execution device and related equipment, which can improve the number of long connections supported by a server and support high concurrent requests of a client. In order to achieve the purpose, the technical scheme provided by the embodiment of the application is as follows:
in a first aspect, an embodiment of the present application provides a method for executing a task with long connection, including:
receiving a target request sent by a first client through a long connection channel; the target request carries target task information;
invoking a target queue thread corresponding to the first client based on the target task information, and executing a target task corresponding to the target request based on pre-stored task information through the target queue thread; the pre-stored task information is stored by adopting a dictionary data structure;
Based on the target request, feeding back result information of the target queue thread executing the target task to the first client through the long connection channel;
and the long connection channel and the first client establish a corresponding relation based on the identity of the client.
In a possible embodiment, before the receiving, through the long connection channel, the target request sent by the first client, the method further includes:
receiving a connection request initiated by the first client through a message queue telemetry transmission protocol, and establishing a long connection of a transmission control protocol or a secure socket layer so as to transmit information through a long connection channel corresponding to the first client; the connection request carries connection information;
performing verification operation based on the first object information in the connection information and preset password information;
if the first object information is matched with the pre-stored object information and the target hash value is matched with the pre-stored hash value corresponding to the first client, determining that verification is successful and storing the connection information by taking the identity of the first client as a key value by adopting a dictionary data structure; otherwise, determining that the verification fails and disconnecting the long connection; the target hash value is determined by performing hash operation based on the preset password information.
In a possible embodiment, the calling the target queue thread corresponding to the first client based on the target task information includes:
performing hash operation based on the identity of the first client in the target task information and the number of queues included in a thread pool, and determining a target queue identity corresponding to the first client;
invoking a corresponding target queue thread based on the target queue identification to serially process requests in the target queue thread through the target queue thread.
In a possible embodiment, the target task information includes first object information and subject information; the executing, by the target queue thread, a target task corresponding to the target request based on pre-stored task information, including:
inquiring whether a theme list corresponding to the first object information comprises the theme information or not in pre-stored task information through the target queue thread;
if yes, outputting result information comprising task response information when executing a target task corresponding to the target request;
if not, outputting result information comprising task execution failure information when executing the target task corresponding to the target request;
The pre-stored task information comprises a corresponding relation between theme information and object information stored by adopting at least one section of dictionary data structure; the subject information is a traversal key, and the object information is a traversal value.
In a possible embodiment, the target request is a subscription request or a release request;
when the target request is a subscription request and task response information is output, executing the target task includes: storing the corresponding relation between the first object information and the theme information in the pre-stored task information;
when the target request is a release request and task response information is output, executing the target task includes: acquiring release information and theme information in the target task information; inquiring second object information with a corresponding relation with the theme information in the pre-stored task information; and sending the release information to a second client corresponding to the second object information.
In a possible embodiment, when the received published information is encrypted information encrypted by the first client using an advanced encryption standard algorithm, the obtaining published information in the target task information includes:
Acquiring the encryption information in the target task information;
and decrypting the encrypted information through the advanced encryption standard algorithm to obtain the release information.
In a possible embodiment, when the received release information is compressed information compressed by the first client using a compression algorithm, the obtaining release information in the target task information includes:
acquiring the compression information in the target task information;
decompressing the compressed information through the compression algorithm to obtain the release information.
In a possible embodiment, the method further comprises:
receiving an offline request sent by the first client; the offline request carries disconnection information;
and closing a long connection channel corresponding to the first client based on the disconnection information, and clearing information related to the first client.
In a second aspect, an embodiment of the present application provides a service allocation method, including:
based on a load balancing strategy, distributing the received client connections to corresponding servers respectively; the server cluster where the server is located comprises at least one server;
the server executes the long-connection task execution method according to any embodiment of the first aspect.
In a third aspect, an embodiment of the present application provides a long-connection task execution device, including:
the receiving module is used for receiving a target request sent by the first client through the long connection channel; the target request carries target task information;
the calling module is used for calling a target queue thread corresponding to the first client based on the target task information and executing a target task corresponding to the target request based on pre-stored task information through the target queue thread; the pre-stored task information is stored by adopting a dictionary data structure;
the feedback module is used for feeding back the result information of the target queue thread executing the target task to the first client through the long connection channel based on the target request;
and the long connection channel and the first client establish a corresponding relation based on the identity of the client.
In a possible embodiment, the receiving module is configured to, before the receiving, by the long connection channel, the target request sent by the first client, further be configured to:
receiving a connection request initiated by the first client through a message queue telemetry transmission protocol, and establishing a long connection of a transmission control protocol or a secure socket layer so as to transmit information through a long connection channel corresponding to the first client; the connection request carries connection information;
Performing verification operation based on the first object information in the connection information and preset password information;
if the first object information is matched with the pre-stored object information and the target hash value is matched with the pre-stored hash value corresponding to the first client, determining that verification is successful and storing the connection information by taking the identity of the first client as a key value by adopting a dictionary data structure; otherwise, determining that the verification fails and disconnecting the long connection; the target hash value is determined by performing hash operation based on the preset password information.
In a possible embodiment, the calling module, when used for executing the target task corresponding to the target request and calling the target queue thread corresponding to the first client based on the target task information, is specifically configured to:
performing hash operation based on the identity of the first client in the target task information and the number of queues included in a thread pool, and determining a target queue identity corresponding to the first client;
and calling a corresponding target queue thread to execute a target task corresponding to the target request based on the target queue identification so as to serially process various requests in the target queue thread.
In a possible embodiment, the target task information includes first object information and subject information; the calling module is used for executing the target task corresponding to the target request, and is specifically used for:
inquiring whether a theme list corresponding to the first object information comprises the theme information or not in pre-stored task information;
if yes, outputting result information comprising task response information when executing a target task corresponding to the target request;
if not, outputting result information comprising task execution failure information when executing the target task corresponding to the target request;
the pre-stored task information comprises a corresponding relation between theme information and object information stored by adopting at least one section of dictionary data structure; the subject information is a traversal key, and the object information is a traversal value.
In a possible embodiment, the target request is a subscription request or a release request;
when the target request is a subscription request and task response information is output, the calling module is specifically configured to: storing the corresponding relation between the first object information and the theme information in the pre-stored task information;
When the target request is a release request and task response information is output, the calling module is specifically used for executing the target task: acquiring release information and theme information in the target task information; inquiring second object information with a corresponding relation with the theme information in the pre-stored task information; and sending the release information to a second client corresponding to the second object information.
In a possible embodiment, when the received release information is encrypted information encrypted by the first client using an advanced encryption standard algorithm, the calling module is specifically configured to:
acquiring the encryption information in the target task information;
and decrypting the encrypted information through the advanced encryption standard algorithm to obtain the release information.
In a possible embodiment, when the received release information is compressed information compressed by the first client by adopting a compression algorithm, the calling module is specifically configured to:
acquiring the compression information in the target task information;
Decompressing the compressed information through the compression algorithm to obtain the release information.
In a possible embodiment, the apparatus further comprises a disconnection module for:
receiving an offline request sent by the first client; the offline request carries disconnection information;
and closing a long connection channel corresponding to the first client based on the disconnection information, and clearing information related to the first client.
In a fourth aspect, an embodiment of the present application provides a service allocation apparatus, including:
the distribution module is used for distributing the received client connection to the corresponding server respectively based on the load balancing strategy; the server cluster where the server is located comprises at least one server;
the server executes the long-connection task execution method according to any embodiment of the first aspect.
In a fifth aspect, the application also provides an electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, which when executed is adapted to carry out the method provided in any of the alternative embodiments of the application.
In a sixth aspect, the application also provides a computer readable storage medium having stored therein a computer program for performing the method provided in any of the alternative embodiments of the application when the computer program is run in a processor.
In a seventh aspect, the application provides a computer program product, or a computer program comprising a computer program, which when executed by a processor, implements the method provided in any of the alternative embodiments of the application.
The technical scheme provided by the application has the beneficial effects that:
the embodiment of the application provides a long-connection task execution method, which can be applied to a server, and particularly, when a long-connection channel and a first client are in corresponding relation based on the identity of the client, namely, long connection is established between the first client and the server, a target request sent by the first client can be received through the long-connection channel, and the target request carries target task information; then, calling a target queue thread corresponding to the first client based on the target task information, and executing a target task corresponding to the target request based on the pre-stored task information through the target queue thread; based on the target request, the result information of the target task executed by the target queue thread is fed back to the first client through the long connection. Compared with the prior art, the implementation of the task execution method adjusts an implementation main body of the task execution method from an overall architecture, firstly establishes a long connection relation between a client and a server based on the identity identification establishment of the client, then executes a target task corresponding to a target request initiated by the client in the form of calling a queue thread, stores pre-stored task information for executing the target task by adopting a dictionary data structure, improves the number of long connections which can be supported by a single server by providing a high-performance architecture, and on the basis, reduces the lock granularity for processing the target task information by adopting the dictionary data structure to store the pre-stored task information for executing the target task, improves the query rate per second for request processing, reduces the request delay of the client, and provides high-performance communication.
The embodiment of the application also provides a service distribution method which can be applied to the load balancing equipment for managing each single server, wherein the server cluster managed by the load balancing equipment comprises at least one server; specifically, based on the load balancing policy, each received client connection is distributed to a corresponding server, and each server may execute the task execution method of the long connection shown in the above embodiment. The implementation of the application can be used for arranging a plurality of servers in the server cluster, namely, the servers correspond to a plurality of back-end service nodes, each back-end service node is mounted on load balancing equipment, and the load balancing equipment distributes flow according to a load balancing strategy, so that the balancing of the number of long connections supported by each single server is facilitated; on the basis, the cluster capacity expansion or contraction can be realized by increasing or reducing the number of the deployed servers in the server cluster, so that the expandability and the usability of the service are improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings that are required to be used in the description of the embodiments of the present application will be briefly described below.
FIG. 1 is a schematic flow chart of a method for executing a task with long connection according to an embodiment of the present application;
fig. 2 is a schematic flow chart of a service allocation method according to an embodiment of the present application;
FIG. 3 is a schematic diagram of an operation architecture according to an embodiment of the present application;
fig. 4 is a schematic diagram of a server cluster deployment architecture according to an embodiment of the present application;
fig. 5 is a schematic diagram of a server architecture according to an embodiment of the present application;
FIG. 6 is a schematic diagram of a data structure according to an embodiment of the present application;
fig. 7 is a schematic diagram of a client request flow provided in an embodiment of the present application;
FIG. 8 is a schematic structural diagram of a long-connection task execution device according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of a service distribution device according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar elements or elements having like or similar functions throughout. The embodiments described below by referring to the drawings are illustrative only and are not to be construed as limiting the application.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless expressly stated otherwise, as understood by those skilled in the art. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein includes all or any element and all combination of one or more of the associated listed items.
The application provides a long connection task execution method, a device and related equipment, which aim at the problems that the number of long connections supported by a server is small and a client request is overtime easily after the number of the supported long connections reaches a certain threshold value in the existing long connection-based service implementation scheme.
The scheme of the embodiment of the application relates to the scenes of message pushing, instant messaging service, internet of things communication service and the like, and can provide high-performance long-connection publishing or subscribing service.
Before further describing embodiments of the present application in detail, the terms and terminology involved in the embodiments of the present application will be described, and the terms and terminology involved in the embodiments of the present application are suitable for the following explanation.
The internet of things (Internet of Things, ioT) refers to collecting any object or process needing to be connected and interacted in real time through various devices and technologies such as various information sensors, radio frequency identification technologies, global positioning systems, infrared sensors, laser scanners, and the like, collecting various needed information such as sound, light, heat, electricity, mechanics, chemistry, biology, positions and the like, accessing through various possible networks, realizing ubiquitous connection of objects and objects, and realizing intelligent perception, identification and management of objects and processes. The internet of things is an information carrier based on the internet, a traditional telecommunication network and the like, and can enable all common physical objects which can be independently addressed to form an interconnection network.
The Cloud IOT aims to connect information perceived by sensing equipment in the traditional IOT and accepted instructions into the Internet, networking is truly realized, mass data storage and operation are realized through a Cloud computing technology, the current running states of all 'objects' are perceived in real time due to the fact that the things are connected with each other, a large amount of data information can be generated in the process, how to collect the information, how to screen useful information in the mass information and make decision support for subsequent development, and the Cloud is a key problem affecting the development of the IOT, and the Internet of things Cloud based on Cloud computing and Cloud storage technology is also a powerful support for the technology and application of the IOT.
Message queue telemetry transport (Message Queuing Telemetry Transport, MQTT) protocol is a client-and server-based message publish/subscribe transport protocol. May be used in machine-to-machine (M2M) communications and internet of things (IoT).
Dictionary (map) data structure: the map is a data type, the key and the value are bound together, the bottom layer is realized by a hash table, and the corresponding value can be quickly found through the key.
The transmission control protocol (Transmission Control Protocol, TCP) is a connection-oriented, reliable, byte stream based transport layer communication protocol.
The secure socket layer (Secure Socket Layer, SSL) is a secure protocol implemented over a transport communication protocol. Information security is achieved by using public key and symmetric key techniques. All traffic between the SSL client and the server is encrypted using keys and algorithms established during the SSL handshake.
Query-per-second (QPS) is a measure of how much traffic a particular query server handles in a specified time.
The advanced encryption standard (Advanced Encryption Standard, AES) algorithm is a symmetric encryption algorithm, which uses the same key for both encryption and decryption.
Load balancing (Cloud Load Balancer, CLB) provides a secure and fast traffic distribution service, access traffic can be automatically distributed to multiple cloud servers in the cloud via CLB, service capability of the system is extended and single point failure is eliminated. The load balancing supports hundred million-level connection and tens of millions of level concurrency, can easily cope with large-flow access, and meets business requirements.
The following describes the technical scheme of the present application and how the technical scheme of the present application solves the above technical problems in detail with specific embodiments. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Fig. 1 is a schematic flow chart of a long-connection task execution method according to an embodiment of the present application, where the method may be executed by any electronic device, for example, a server. The server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligence platforms, but is not limited thereto. In the method, a request initiated by a client can be received in the process of executing a task with long connection, the client (client) corresponds to a server (also called a service end) and provides a local service for an object, and the client is generally installed on the terminal and operates in cooperation with the service end except for some programs which only operate locally; the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart sound box, a smart watch, a vehicle-mounted device and the like; the client may be a web browser, email client, instant messaging client, or the like.
Specifically, as shown in fig. 1, the method for executing the task of the long connection provided by the embodiment of the present application includes the following steps S101 to S103:
step S101: receiving a target request sent by a first client through a long connection channel; the target request carries target task information. And the long connection channel and the first client establish a corresponding relation based on the identity of the client.
The long connection channel can provide cloud data downlink capability packaged by the IoT service protocol, and provide the clients with the capability of subscribing messages, publishing messages and supporting a request response model. Specifically, the long connection channel has interfaces corresponding to connection requests, subscription requests, unsubscribe requests, publish messages, and the like. In the embodiment of the application, data (such as a request initiated by the client, information carried by the request, or result information, release information and the like issued by the server to the client) is transmitted between the client and the server through a long connection channel.
The target request sent by the first client may be a service request, a subscription request, an unsubscribe request, a publishing request, etc. The target task information carried by the target request is related to the content of the request, for example, when the target request is a subscription request, the target task information may include object information, an identity identifier of the client, subject information, and the like. The content corresponding to the target task information will be described in detail for each different request case in the subsequent embodiments. Alternatively, the object may be a user using the client.
As shown in fig. 5, the server includes a client manager (ClientManager), specifically, the client manager manages client information in a memory, and uses a dictionary map data structure to realize data storage; in the map, a traversal key (key) is a client identity ID; the traversal value (value) is client information, and may include a client ID, client connection information, a client state, and the like. Specifically, the correspondence between the long connection channel and the first client may be determined based on the correspondence between the current server and the client stored in the client manager; that is, in the embodiment of the present application, description is made with respect to a long connection between a single server and a plurality of clients. Specifically, after the first client establishes a long connection with the server, the first client may send a target request to the server through the long connection channel.
Step S102: invoking a target queue thread corresponding to the first client based on the target task information, and executing a target task corresponding to the target request based on pre-stored task information through the target queue thread; the pre-stored task information is stored by adopting a dictionary map data structure.
Specifically, as shown in fig. 5, the internal thread pool (workermaool) at the server end is composed of n queues (queue), where the size of n may be configured according to the cluster size, which is not limited in the present application; the queues can store client request tasks, and each queue can be correspondingly provided with a thread for task processing.
When a first client initiates a target request, the target task information is carried in the target request and synchronously sent to a server, and the server can determine a target queue corresponding to the first client (for example, distinguishing each queue through an ID) based on the target task information, and then put a target task corresponding to the target request into the target queue so as to call a corresponding target queue thread to execute the target task.
The pre-stored task information is information pre-stored in implementation and can be information corresponding to a target task, for example, when the target request is a release request, the pre-stored task information can comprise an association relationship between pre-stored subject information and object information. Specifically, in the embodiment of the application, the dictionary data structure is adopted to store the pre-stored task information, and the map data structure is adopted to store the information, so that the lock granularity of target task information processing is reduced, the QPS of request processing is improved, and the request delay of a client is reduced.
Step S103: and based on the target request, feeding back the result information of the target queue thread executing the target task to the first client through the long connection channel.
Specifically, because of the different target tasks (which may be different processing tasks or the same processing task but for different processing contents; e.g., subscription tasks as well, but different subscribed topics), the thread outputs different result information when executing different target tasks. After the thread processes the task requested by the client, the server can feed back corresponding result information to the first client through the long connection channel.
The present example is a service implementation based on a long connection, which means that multiple data packets can be sent consecutively over one connection. For example, when a connection for transmitting data between a client and a server is not closed after a web page is opened, the client accesses the server again, based on using an already established connection.
To better illustrate the specific operation of the various embodiments of the present application, the overall architecture of the server in the embodiments of the present application will be described first with reference to fig. 3, 5 and 6.
In one embodiment, FIG. 3 illustrates the overall architecture of a long connection based publish/subscribe service according to an embodiment of the present application. The first client 10 and the server 20 may establish a long connection via the TCP protocol or the TCP SSL protocol (a security protocol implemented on TCP) and use the MQTT protocol for data transmission.
In an embodiment, fig. 5 shows the overall architecture of the server according to the embodiment of the present application.
The server may be composed of four components, respectively: client manager (ClientManager), server internal thread pool (WorkerPool), topic manager (Topicmanager), and rights checking module (AuthChecker).
The Client manager manages Client information in a memory, and is realized by a map data structure, wherein a key is an identity identifier (Client ID) of a Client, and a value is Client information; the client information may include client ID, client connection information, client status. As shown in fig. 5, the management of the client information is performed by the client manager in the same server, so that n pieces of client information can be managed, which is beneficial to improving the number of long connections supported by the server in the long connection service.
The internal thread pool (workbench pool) of the server side consists of n queues (queue) with the length of a preset value (4096, for example), wherein the size of n can be configured according to the cluster scale, the client side requests tasks are stored in the queues, and each queue carries out task processing by one thread. The client request can calculate a corresponding queue, such as a queue ID, by a hash algorithm and modulo a preset value 4096; specifically, the algorithm may express the following formula (1):
queueid= hash (ClientID)% n
The server side puts the calculated queue ID into a corresponding queue for processing, so that each client side request can be processed in series.
The topic manager (TopicManager) is implemented by multiple maps, manages topic (topic) information of a client in a memory, optimizes a topic storage structure, and can store topic and Subscribers (Subscribers) (such as objects initiating subscription requests) by using a segmented map data structure. The data structure adopted by the theme manager is shown in fig. 6. Optionally, the theme manager is implemented specifically as follows:
(1) Key in each Map (e.g. Map 0 or Map 1) is a topic string, value is subscniber (which may correspond to an object name), and the relationship between topic and Subscriber is saved; as shown in the figure, the topic 0 and the subscriber 0, and the correspondence between the topic 2 and the subscriber 1 are stored in the current Map 0.
(2) The system can be composed of a plurality of maps (such as 1000 maps, the number of which can be adjusted according to actual demands, the embodiment of the application is not limited to the above, and the processing speed of the topic manager and the request QPS are improved by subdividing the lock granularity by the plurality of maps.
The authority checking module (AuthChecker) performs authority checking (as shown in fig. 5) on a request (such as a request of connection, subscription, release, etc.) initiated by a client, wherein an internal data structure of the authority checking module is map, a key is object information (such as an object name, a uesrname), and a value is a hash value password, a subscribed information topic list, a released information topic list, etc. corresponding to the key.
The following describes a specific procedure regarding processing of a connection request initiated by a client in an embodiment of the present application.
In a possible embodiment, before step S101 of receiving the target request sent by the first client through the long connection channel, steps S001-S003 are further included:
step S001: receiving a connection request initiated by the first client through a message queue telemetry transmission protocol, and establishing a long connection of a transmission control protocol or a secure socket layer so as to transmit information through a long connection channel corresponding to the first client; the connection request carries connection information.
Specifically, the first client may initiate a connection request with the server through the MQTT protocol to establish a TCP/TCP SSL long connection. After the long connection is established, the server may invoke the long connection channel to implement information transmission with the first client.
Step S002: and performing verification operation based on the first object information in the connection information and preset password information.
Specifically, the server may acquire first object information (e.g., object name username) and preset Password information (e.g., password) in connection information (e.g., MQTT connection packet), and then the server may perform sha256 hash algorithm operation on the Password to calculate a target hash value (sha 256 Password); and matching the first object information with the pre-stored object information (such as the object name dbUsername) in the back-end database, and matching the target hash value (dbSha 256 Password) with the pre-stored hash value in the back-end database. Wherein the hash algorithm may be expressed as the following formula (2):
sha256 password=sha 256 (Password.). The formula (2)
The Database (Database), which may be referred to as an electronic file cabinet, stores electronic files, and may perform operations such as adding, querying, updating, deleting, etc. on data in the files. A database is a collection of data stored together in a manner that can be shared with multiple users, with as little redundancy as possible, independent of the application.
Step S003: if the first object information is matched with the pre-stored object information and the target hash value is matched with the pre-stored hash value corresponding to the first client, determining that verification is successful and storing the connection information by taking the identity of the first client as a key value by adopting a map data structure; otherwise, determining that the verification fails and disconnecting the long connection; the target hash value is determined by carrying out hash operation based on preset password information.
Specifically, if the first object information (i.e., the object name) exists in the database, and the corresponding pre-stored hash value Password in the database is equal to the target hash value sha256Password, it may be determined that the verification is passed (i.e., the permission verification module may determine that the first client has the connection permission), otherwise the verification fails, and the client connection is disconnected (such as the TCP/TCP SSL long connection referred to in step S001 above). After the connection authority is checked, a Client manager (Client manager) in the server may store the identity (Client ID) and connection information of the Client.
The following describes specific operations related to an internal thread pool of a server in an embodiment of the present application.
In a possible embodiment, invoking the target queue thread corresponding to the first client based on the target task information in step S102 includes the following steps A1-A2:
step A1: and carrying out hash operation based on the identity of the first client in the target task information and the number of queues included in the thread pool, and determining a target queue identity corresponding to the first client.
Step A2: invoking a corresponding target queue thread based on the target queue identification to serially process requests in the target queue thread through the target queue thread.
Specifically, as shown in fig. 5, a hash algorithm as shown in the above formula (1) may be used to determine the corresponding target queue identifier based on the identity of the first client and the number of queues included in the internal thread pool. After determining the target queue identification, the target task may be placed in a corresponding queue, and the tasks included in the queue may be executed by the corresponding target queue thread in a serial processing manner.
The following describes a specific procedure of rights verification related to publish or subscribe in the embodiment of the present application.
In a possible embodiment, the target task information includes first object information and subject information; in step S102, executing, by the target queue thread, a target task corresponding to the target request based on pre-stored task information, including steps B1-B3:
step B1: inquiring whether the theme list corresponding to the first object information comprises the theme information or not in the pre-stored task information through the target queue thread.
Step B2: if yes, outputting result information comprising task response information when executing the target task corresponding to the target request.
Step B3: if not, outputting result information comprising task execution failure information when executing the target task corresponding to the target request.
The pre-stored task information comprises a corresponding relation between theme information and object information stored by adopting at least one map data structure; the subject information is a traversal key, and the object information is a traversal value.
The following describes the implementation of each operation step with respect to steps B1-B3 executed in the above embodiment, with the target request being a subscription request and a release request.
The target request is a subscription request:
after the first client and the server are successfully connected (i.e., the server can provide long connection service for the first client), the target task information (which can be subscription information at this time) can be carried in a subscription request and sent, and the subscription information can be presented in the form of an MQTT subscription package (subscription package), where the subscription package can include the first object information, an identity identifier of the first client, a message ID, and subject information that the first client requests to subscribe.
The server receives the MQTT subscription package and analyzes the subscription package, so that the identity and the theme information of the first client can be obtained. Then, the server side can acquire topic authority information corresponding to the object name username of the client side from the database, if the topic list subscribed by the username in the database contains the subject information in the subscription package, the verification can be determined to pass, otherwise, the verification fails. Alternatively, the verification process may be performed in the rights verification module.
When the verification is passed, executing the step B2 to output result information comprising task response information, wherein the task response information can be a subscription response packet (subsapackpacket); at this time, the task response information may be transmitted to the first client by executing step S103, so that the first client perceives that the related subject has been successfully subscribed.
When the verification fails, executing step B3 to output result information comprising task execution failure information, wherein the task execution failure information can comprise a subscription failure error code; at this time, by executing step S103, task execution failure information may be transmitted to the first client, so that the first client perceives that the subscription related subject fails.
The target request is a release request:
the first client may carry the target task information (at this time, the target task information may be information related to the publishing request) to send in the publishing request, where the target task information may be presented in the form of an MQTT publishing packet (publishing hpacket), and the publishing packet may include publishing information (such as a message body content payload), a message ID, an identity of the first client, first object information, and subject information requested to be published by the first client.
The server receives the MQTT release packet, analyzes the release packet, and can acquire the identity and the subject information of the first client. Then, the server side can acquire the publishing topic authority information corresponding to the object name username of the client side from the database, if the topic list which can be published by the username in the database contains the subject information in the publishing package, the verification can be determined to pass, otherwise, the verification fails. Alternatively, the verification process may be performed in the rights verification module.
When the verification is passed, executing the step B2 to output result information comprising task response information, wherein the task response information can be a release response packet; at this time, the task response information may be transmitted to the first client by executing step S103, so that the first client perceives that the relevant release information has been successfully released.
When the verification fails, executing step B3 to output result information comprising task execution failure information, wherein the task execution failure information can comprise release failure error codes; at this time, the task execution failure information may be transmitted to the first client by executing step S103, so that the first client perceives that the publishing information fails.
In a possible embodiment, the target request is a subscription request or a publish request.
When the target request is a subscription request and task response information is output, executing the target task in step S102 includes step C1:
step C1: and storing the corresponding relation between the first object information and the theme information in the pre-stored task information.
Specifically, when it is determined that the first client has the subscription right, subscription relationship between the currently subscribed topic information and the first client may be saved in the topic manager TopicManager.
When the target request is a release request and task response information is output, executing the target task in step S102 includes steps D1-D3:
step D1: and acquiring release information and theme information in the target task information.
Specifically, when it is determined that the first client has the distribution right, the distribution information (message body content payload) and the topic information corresponding to the distribution information in the target task information may be acquired.
Step D2: and inquiring second object information with a corresponding relation with the theme information in the pre-stored task information.
Specifically, since the subscription relationship between each topic information and each client is stored in the pre-stored task information (which is managed by the topic manager), at least one second object information (subscriber Subscribers) of the topic (topic information in the target task information carried by the publishing request) can be queried in the topic manager TopicManager.
Step D3: and sending the release information to a second client corresponding to the second object information.
Specifically, the server side can acquire corresponding second client side information according to the second object information, and then send release information to the second client side after being connected with the second client side; namely, the release information required to be released by the first client is transmitted to at least one second client which has a subscription relationship with the subject information of the release information, and the operation of the message release process is completed.
In a possible embodiment, the embodiment of the present application further provides a data encryption scheme, specifically, when the received published information is encrypted information encrypted by the first client using an AES algorithm, the obtaining, in step D1, the published information in the target task information includes steps D11-D12:
step D11: and acquiring the encryption information in the target task information.
Step D12: and decrypting the encrypted information through the AES algorithm to obtain the release information.
Specifically, in the process of transmitting information between the server and the client, AES encryption is performed on the payload field content in the MQTT protocol, and decryption can be performed after the encrypted message is acquired, so that the data transmission safety is effectively ensured. Optionally, the encryption process may occur between the first client and the server, for example, the first client encrypts the published information and transmits the encrypted published information to the server, or the server encrypts the published information and transmits the encrypted published information to the second client; the decryption process may occur at the server and the second client, such as the server decrypting the published information encrypted by the first client, or the second client decrypting the published information encrypted by the server. In addition, the server may not participate in the encryption or decryption process, but directly transmit the encrypted release information of the first client to the second client, and the second client decrypts the encrypted release information of the first client.
Wherein the encryption algorithm involved can be expressed as shown in the following formula (3):
encryptedpayload=aes. Encrypt (payload) & gt
Wherein the decryption algorithm involved can be expressed as shown in the following formula (4):
decryptedpayload=aes. Decrypt (payload)..
In a data encryption scheme, the server side of the embodiment of the application supports MQTT SSL connection, namely the client side carries out secure communication after successful connection through the MQTT SSL connection; it can be understood that the full link encryption is realized when the SSL connection is adopted, so that the security of the data can be effectively improved.
In a possible embodiment, the embodiment of the present application further provides a data compression scheme, specifically, when the received release information is compressed information compressed by the first client using a compression algorithm, the release information in the target task information is obtained in step D1, including steps D13-D14:
step D13: and acquiring the compressed information in the target task information.
Step D14: decompressing the compressed information through the compression algorithm to obtain the release information.
Specifically, before the first client sends the publishing request, the publishing information (payload field content) in the target task information (publishing packet) is compressed, and a gzip compression algorithm may be adopted. After receiving the target task information of the first client, the server can decompress the release information.
Wherein the compression algorithm involved can be expressed as shown in the following formula (5):
compressedpayload=gzip.encode (payload) & formula (5)
Wherein the decompression algorithm involved can be expressed as shown in the following formula (6):
payload=gzip.decode (combedpayload.. The formula (6)
The embodiment of the application can effectively solve the problem that the service overall occupies higher bandwidth under the condition that the communication requests of the client and the service are frequent, and can effectively reduce the length of a request body and the bandwidth occupation proportion through a data compression scheme.
The following describes a specific procedure of client offline request processing in an embodiment of the present application.
In a possible embodiment, the long-connection task execution method further includes steps E1-E2:
step E1: receiving an offline request sent by the first client; the offline request carries disconnection information.
Step E2: and closing a long connection channel corresponding to the first client based on the disconnection information, and clearing information related to the first client.
Specifically, the first client may send the disconnection information (such as MQTT disconnection packet disconnect packet) to the server in the offline request. The server, upon receiving the disconnect information sent by the first client, closes the long connection of the first client, and simultaneously notifies a client manager (ClientManager) component to clear information related to the first client, and notifies a topic manager (TopicManager) component to clear topic information and subscription information related to the first client.
As shown in fig. 2, the embodiment of the present application further provides a service allocation method, which may be applied to a load balancing device, including step S201:
step S201: based on a load balancing strategy, distributing the received client connections to corresponding servers respectively; the server cluster where the server is located comprises at least one server.
The server executes the long-connection task execution method shown in any embodiment.
Specifically, as shown in fig. 4, a transfer device, such as a load balancing device CLB, may be further disposed between the client and the server, where the client is connected to the CLB, and then the CLB automatically performs traffic distribution, and connects to the back-end server.
A plurality of backend service nodes hmq _browser (such as server 1 and server 2 shown in fig. 4.) can be deployed at a backend service end for providing services, all backend service nodes are mounted on a CLB, and flow distribution is uniformly performed by the CLB, and meanwhile, the CLB can perform load balancing according to the connection number of each backend server, so that the balancing of the connection number of each backend server is ensured.
It will be appreciated that the load balancing device manages a server cluster consisting of n servers. Aiming at the server cluster, the embodiment of the application provides a cluster deployment scheme for cluster capacity expansion and cluster capacity reduction.
Cluster expansion scheme: and increasing the number of back-end service node deployments, and mounting the newly added service nodes to the CLB to realize cluster capacity expansion.
The cluster capacity reduction scheme comprises the following steps: the number of back-end service node deployments is reduced, and the CLB can automatically identify the service nodes which are already offline so as to realize cluster capacity reduction.
In the embodiment of the application, the provided cluster deployment scheme supports the transverse capacity expansion or contraction of the server side, and is beneficial to improving the expandability and usability of the service.
In a possible embodiment, as shown in fig. 7, in an embodiment of the present application, a client may include four processes for one message delivery (i.e., in one long connection): initiating a connection, initiating a subscription request, initiating a publication request, and disconnecting the connection; the processing of the server for the four processes may refer to the specific description of the corresponding embodiments.
In a possible embodiment, the identity of the client referred to in the embodiment of the present application may be determined based on the address of the client, or may be determined based on other information related to the client; as shown in fig. 5, when the client manager saves the client information through the map, the client manager may assign corresponding identities to each client, for example, the client manager may record the identity of the client as client 1 for the client a, record the identity of the client manager as client 2 for the client B, and so on, it is understood that each client has an independent identity. On the basis, the information which is stored in the server or can be acquired and related to the client can establish an association relationship with the identity of the client; such as determining corresponding object information (e.g., object name usernames) based on the obtained identity of the client segment.
Optionally, data (such as target task information, client identity, user information, connection information, password information, topic information, etc.) involved in the method provided by the application may be stored in the blockchain. The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm and the like. The Blockchain (Blockchain), which is essentially a de-centralized database, is a string of data blocks that are generated in association using cryptographic methods, each of which contains a certain amount of processed data that is used to verify the validity of its information (anti-counterfeit) and to generate the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, an application services layer, and the like.
In the operation process of the embodiment of the application, cloud technology (Cloud technology) is also involved, and the Cloud technology refers to a hosting technology for integrating serial resources such as hardware, software, network and the like in a wide area network or a local area network to realize calculation, storage, processing and sharing of data. Cloud technology (Cloud technology) is based on the general terms of network technology, information technology, integration technology, management platform technology, application technology and the like applied by Cloud computing business models, and can form a resource pool, so that the Cloud computing business model is flexible and convenient as required. Cloud computing technology will become an important support. Background services of technical networking systems require a large amount of computing, storage resources, such as video websites, picture-like websites, and more portals. Along with the high development and application of the internet industry, each article possibly has an own identification mark in the future, the identification mark needs to be transmitted to a background system for logic processing, data with different levels can be processed separately, and various industry data needs strong system rear shield support and can be realized only through cloud computing.
It will be appreciated that the calculations (such as those involved in the rights verification process, the data encryption process, the data compression process, etc.) performed in the above embodiments may be implemented using cloud computing. Cloud computing (closed computing) refers to the delivery and usage mode of an IT infrastructure, meaning that required resources are obtained in an on-demand, easily scalable manner through a network; generalized cloud computing refers to the delivery and usage patterns of services, meaning that the required services are obtained in an on-demand, easily scalable manner over a network. Such services may be IT, software, internet related, or other services. Cloud Computing is a product of fusion of traditional computer and network technology developments such as Grid Computing (Grid Computing), distributed Computing (distributed Computing), parallel Computing (Parallel Computing), utility Computing (Utility Computing), network storage (Network Storage Technologies), virtualization (Virtualization), load balancing (Load balancing), and the like. With the development of the internet, real-time data flow and diversification of connected devices, and the promotion of demands of search services, social networks, mobile commerce, open collaboration and the like, cloud computing is rapidly developed. Unlike the previous parallel distributed computing, the generation of cloud computing will promote the revolutionary transformation of the whole internet mode and enterprise management mode in concept.
In addition, in the above embodiment, the storage of the information (such as the client information, the subscription relationship, etc.) by the service end may be implemented by using cloud storage. Cloud storage (cloud storage) is a new concept that extends and develops in the concept of cloud computing, and a distributed cloud storage system (hereinafter referred to as a storage system for short) refers to a storage system that integrates a large number of storage devices (storage devices are also referred to as storage nodes) of various types in a network to work cooperatively through application software or application interfaces through functions such as cluster application, grid technology, and a distributed storage file system, so as to provide data storage and service access functions for the outside. At present, the storage method of the storage system is as follows: when creating logical volumes, each logical volume is allocated a physical storage space, which may be a disk composition of a certain storage device or of several storage devices. The client stores data on a certain logical volume, that is, the data is stored on a file system, the file system divides the data into a plurality of parts, each part is an object, the object not only contains the data but also contains additional information such as a data Identification (ID) and the like, the file system writes each object into a physical storage space of the logical volume, and the file system records storage position information of each object, so that when the client requests to access the data, the file system can enable the client to access the data according to the storage position information of each object. The process of allocating physical storage space for the logical volume by the storage system specifically includes: physical storage space is divided into stripes in advance according to the set of capacity measures for objects stored on a logical volume (which measures tend to have a large margin with respect to the capacity of the object actually to be stored) and redundant array of independent disks (RAID, redundant Array of Independent Disk), and a logical volume can be understood as a stripe, whereby physical storage space is allocated for the logical volume.
It should be noted that, in the alternative embodiment of the present application, related data such as object information is required to obtain permission or consent of the object when the above embodiment of the present application is applied to a specific product or technology, and the collection, use and processing of related data are required to comply with related laws and regulations and standards of related countries and regions. That is, in the embodiment of the present application, if data related to the subject is involved, the data needs to be obtained through the subject authorization consent and in accordance with the relevant laws and regulations and standards of the country and region.
Based on the same principle as the above-mentioned long-connection task execution method embodiment, the embodiment of the present application further provides a long-connection task execution device, as shown in fig. 8, where the long-connection task execution device 100 may include a receiving module 101, a calling module 102, and a feedback module 103.
The receiving module 101 is configured to receive, through a long connection channel, a target request sent by a first client; the target request carries target task information; the calling module 102 is configured to call a target queue thread corresponding to the first client based on the target task information, and execute, by the target queue thread, a target task corresponding to the target request based on pre-stored task information; the pre-stored task information is stored by adopting a dictionary data structure; a feedback module 103, configured to feedback, based on the target request, result information of the target queue thread executing the target task to the first client through the long connection channel; and the long connection channel and the first client establish a corresponding relation based on the identity of the client.
In a possible embodiment, the receiving module 101 is configured to, before the receiving, by the long connection channel, the target request sent by the first client, further be configured to:
receiving a connection request initiated by the first client through a message queue telemetry transmission protocol, and establishing a long connection of a transmission control protocol or a secure socket layer so as to transmit information through a long connection channel corresponding to the first client; the connection request carries connection information;
performing verification operation based on the first object information in the connection information and preset password information;
if the first object information is matched with the pre-stored object information and the target hash value is matched with the corresponding pre-stored hash value, determining that verification is successful and storing the connection information by taking the identity of the first client as a key value by adopting a dictionary data structure; otherwise, determining that the verification fails and disconnecting the long connection; the target hash value is determined by performing hash operation based on the preset password information.
In a possible embodiment, the calling module 102 is specifically configured to, when configured to execute calling a target queue thread corresponding to the first client based on the target task information:
Performing hash operation based on the identity of the first client in the target task information and the number of queues included in a thread pool, and determining a target queue identity corresponding to the first client;
invoking a corresponding target queue thread based on the target queue identification to serially process requests in the target queue thread through the target queue thread.
In a possible embodiment, the target task information includes first object information and subject information; the calling module 102, when used for executing, by the target queue thread, a target task corresponding to the target request based on pre-stored task information, is specifically configured to:
inquiring whether a theme list corresponding to the first object information comprises the theme information or not in pre-stored task information through the target queue thread;
if yes, outputting result information comprising task response information when executing a target task corresponding to the target request;
if not, outputting result information comprising task execution failure information when executing the target task corresponding to the target request;
the pre-stored task information comprises a corresponding relation between theme information and object information stored by adopting at least one section of dictionary data structure; the subject information is a traversal key, and the object information is a traversal value.
In a possible embodiment, the target request is a subscription request or a release request;
when the target request is a subscription request and task response information is output, the calling module 102 is specifically configured to: storing the corresponding relation between the first object information and the theme information in the pre-stored task information;
when the target request is a release request and the task response information is output, the calling module 102 is specifically configured to: acquiring release information and theme information in the target task information; inquiring second object information with a corresponding relation with the theme information in the pre-stored task information; and sending the release information to a second client corresponding to the second object information.
In a possible embodiment, when the received published information is encrypted information encrypted by the first client using the AES algorithm, the calling module 102 is specifically configured to:
acquiring the encryption information in the target task information;
and decrypting the encrypted information through the advanced encryption standard algorithm to obtain the release information.
In a possible embodiment, when the received published information is compressed information compressed by the first client using a compression algorithm, the calling module 102 is specifically configured to:
acquiring the compression information in the target task information;
decompressing the compressed information through the compression algorithm to obtain the release information.
In a possible embodiment, the apparatus further comprises a disconnection module for:
receiving an offline request sent by the first client; the offline request carries disconnection information;
and closing a long connection channel corresponding to the first client based on the disconnection information, and clearing information related to the first client.
Based on the same principle as the above-described service allocation method embodiment, the embodiment of the present application further provides a service allocation apparatus, as shown in fig. 9, where the service allocation apparatus 200 may include a distribution module 201.
The distribution module 201 is configured to distribute the received client connections to corresponding servers respectively based on a load balancing policy; the server cluster where the server is located comprises at least one server; the server executes the long-connection task execution method in the embodiment.
The device of the embodiment of the present application may perform the method provided by the embodiment of the present application, and its implementation principle is similar, and actions performed by each module in the device of the embodiment of the present application correspond to steps in the method of the embodiment of the present application, and detailed functional descriptions of each module of the device may be referred to the descriptions in the corresponding methods shown in the foregoing, which are not repeated herein.
The embodiment of the application provides an electronic device, which comprises a memory, a processor and a computer program stored on the memory, wherein the processor executes the computer program to realize the steps of a long-connection task execution method, compared with the related technology:
on the one hand: the embodiment of the application provides a long-connection task execution method, which can be applied to a server, and particularly, when a long-connection channel and a first client are in corresponding relation based on the identity of the client, namely, long connection is established between the first client and the server, a target request sent by the first client can be received through the long-connection channel, and the target request carries target task information; then, calling a target queue thread corresponding to the first client based on the target task information to execute a target task corresponding to the target request; based on the target request, the result information of the target task executed by the target queue thread based on the pre-stored task information through the long connection is fed back to the first client. Compared with the prior art, the implementation of the task execution method adjusts an implementation main body of the task execution method from an overall architecture, firstly establishes a long connection relation between a client and a server based on the identity identification establishment of the client, then executes a target task corresponding to a target request initiated by the client in the form of calling a queue thread, stores pre-stored task information for executing the target task by adopting a dictionary data structure, improves the number of long connections which can be supported by a single server by providing a high-performance architecture, and on the basis, reduces the lock granularity for processing the target task information by adopting the dictionary data structure to store the pre-stored task information for executing the target task, improves the query rate per second for request processing, reduces the request delay of the client, and provides high-performance communication.
On the other hand: the embodiment of the application also provides a service distribution method which can be applied to the load balancing equipment for managing each single server, wherein the server cluster managed by the load balancing equipment comprises at least one server; specifically, based on the load balancing policy, each received client connection is distributed to a corresponding server, and each server may execute the task execution method of the long connection shown in the above embodiment. The implementation of the application can be used for arranging a plurality of servers in the server cluster, namely, the servers correspond to a plurality of back-end service nodes, each back-end service node is mounted on load balancing equipment, and the load balancing equipment distributes flow according to a load balancing strategy, so that the balancing of the number of long connections supported by each single server is facilitated; on the basis, the cluster capacity expansion or contraction can be realized by increasing or reducing the number of the deployed servers in the server cluster, so that the expandability and the usability of the service are improved.
In an alternative embodiment, there is provided an electronic device, as shown in fig. 10, the electronic device 4000 shown in fig. 10 includes: a processor 4001 and a memory 4003. Wherein the processor 4001 is coupled to the memory 4003, such as via a bus 4002. Optionally, the electronic device 4000 may further comprise a transceiver 4004, the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data, etc. It should be noted that, in practical applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 is not limited to the embodiment of the present application.
The processor 4001 may be a CPU (Central Processing Unit ), general purpose processor, DSP (Digital Signal Processor, data signal processor), ASIC (Application Specific Integrated Circuit ), FPGA (Field Programmable Gate Array, field programmable gate array) or other programmable logic device, transistor logic device, hardware components, or any combination thereof. Which may implement or perform the various exemplary logic blocks, modules and circuits described in connection with this disclosure. The processor 4001 may also be a combination that implements computing functionality, e.g., comprising one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
Bus 4002 may include a path to transfer information between the aforementioned components. Bus 4002 may be a PCI (Peripheral Component Interconnect, peripheral component interconnect standard) bus or an EISA (Extended Industry Standard Architecture ) bus, or the like. The bus 4002 can be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 10, but not only one bus or one type of bus.
Memory 4003 may be, but is not limited to, ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, RAM (Random Access Memory ) or other type of dynamic storage device that can store information and instructions, EEPROM (Electrically Erasable Programmable Read Only Memory ), CD-ROM (Compact Disc Read Only Memory, compact disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and that can be Read by a computer.
The memory 4003 is used for storing a computer program for executing an embodiment of the present application, and is controlled to be executed by the processor 4001. The processor 4001 is configured to execute a computer program stored in the memory 4003 to realize the steps shown in the foregoing method embodiment.
Among them, electronic devices include, but are not limited to: server, terminal, on-vehicle equipment.
Embodiments of the present application provide a computer readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of the foregoing method embodiments and corresponding content.
The embodiment of the application also provides a computer program product, which comprises a computer program, wherein the computer program can realize the steps and corresponding contents of the embodiment of the method when being executed by a processor.
The terms "first," "second," "third," "fourth," "1," "2," and the like in the description and in the claims and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate, such that the embodiments of the application described herein may be implemented in other sequences than those illustrated or otherwise described.
It should be understood that, although the flowcharts of the embodiments of the present application instruct various operation steps through arrows, the order of execution of these steps is not limited to the order in which the arrows are instructed. In some implementations of embodiments of the application, the implementation steps in the flowcharts may be performed in other orders as desired, unless explicitly stated herein. Furthermore, some or all of the steps in the flowcharts may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or phases may be performed at the same time, or each of these sub-steps or phases may be performed at different times, respectively. In the case of different execution time, the execution sequence of the sub-steps or stages can be flexibly configured according to the requirement, which is not limited by the embodiment of the present application.
The foregoing is merely an optional implementation manner of some of the implementation scenarios of the present application, and it should be noted that, for those skilled in the art, other similar implementation manners based on the technical ideas of the present application are adopted without departing from the technical ideas of the scheme of the present application, and the implementation manner is also within the protection scope of the embodiments of the present application.

Claims (12)

1. A method for performing a long-connection task, comprising:
receiving a target request sent by a first client through a long connection channel; the target request carries target task information;
invoking a target queue thread corresponding to the first client based on the target task information, and executing a target task corresponding to the target request based on pre-stored task information through the target queue thread; the pre-stored task information is stored by adopting a dictionary data structure;
based on the target request, feeding back result information of the target queue thread executing the target task to the first client through the long connection channel;
and the long connection channel and the first client establish a corresponding relation based on the identity of the client.
2. The method of claim 1, further comprising, prior to receiving the target request from the first client over the long connection channel:
Receiving a connection request initiated by the first client through a message queue telemetry transmission protocol, and establishing a long connection of a transmission control protocol or a secure socket layer so as to transmit information through a long connection channel corresponding to the first client; the connection request carries connection information;
performing verification operation based on the first object information in the connection information and preset password information;
if the first object information is matched with the pre-stored object information and the target hash value is matched with the pre-stored hash value corresponding to the first client, determining that verification is successful and storing the connection information by taking the identity of the first client as a key value by adopting a dictionary data structure; otherwise, determining that the verification fails and disconnecting the long connection; the target hash value is determined by performing hash operation based on the preset password information.
3. The method of claim 1, wherein invoking the target queue thread corresponding to the first client based on the target task information comprises:
performing hash operation based on the identity of the first client in the target task information and the number of queues included in a thread pool, and determining a target queue identity corresponding to the first client;
Invoking a corresponding target queue thread based on the target queue identification to serially process requests in the target queue thread through the target queue thread.
4. The method of claim 1, wherein the target task information includes first object information and theme information; the executing, by the target queue thread, a target task corresponding to the target request based on pre-stored task information, including:
inquiring whether a theme list corresponding to the first object information comprises the theme information or not in pre-stored task information through the target queue thread;
if yes, outputting result information comprising task response information when executing a target task corresponding to the target request;
if not, outputting result information comprising task execution failure information when executing the target task corresponding to the target request;
the pre-stored task information comprises a corresponding relation between theme information and object information stored by adopting at least one section of dictionary data structure; the subject information is a traversal key, and the object information is a traversal value.
5. The method of claim 4, wherein the target request is a subscription request or a publication request;
When the target request is a subscription request and task response information is output, executing the target task includes: storing the corresponding relation between the first object information and the theme information in the pre-stored task information;
when the target request is a release request and task response information is output, executing the target task includes: acquiring release information and theme information in the target task information; inquiring second object information with a corresponding relation with the theme information in the pre-stored task information; and sending the release information to a second client corresponding to the second object information.
6. The method according to claim 5, wherein when the received published information is encrypted information encrypted by the first client using an advanced encryption standard algorithm, the obtaining published information in the target task information includes:
acquiring the encryption information in the target task information;
and decrypting the encrypted information through the advanced encryption standard algorithm to obtain the release information.
7. The method of claim 5, wherein when the received published information is compressed information compressed by the first client using a compression algorithm, the obtaining published information in the target task information includes:
Acquiring the compression information in the target task information;
decompressing the compressed information through the compression algorithm to obtain the release information.
8. The method according to claim 1, characterized in that the method further comprises:
receiving an offline request sent by the first client; the offline request carries disconnection information;
and closing a long connection channel corresponding to the first client based on the disconnection information, and clearing information related to the first client.
9. A long-connection task execution device, comprising:
the receiving module is used for receiving a target request sent by the first client through the long connection channel; the target request carries target task information;
the calling module is used for calling a target queue thread corresponding to the first client based on the target task information and executing a target task corresponding to the target request based on pre-stored task information through the target queue thread; the pre-stored task information is stored by adopting a dictionary data structure;
the feedback module is used for feeding back the result information of the target queue thread executing the target task to the first client through the long connection channel based on the target request;
And the long connection channel and the first client establish a corresponding relation based on the identity of the client.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is configured to perform the method of any of claims 1 to 8 when the computer program is run.
11. A computer readable storage medium, characterized in that the storage medium has stored therein a computer program for executing the method of any of claims 1 to 8 when the computer program is run in a processor.
12. A computer program product, characterized in that the computer product comprises a computer program which, when executed by a processor, implements the method of any one of claims 1 to 8.
CN202210226181.4A 2022-03-09 2022-03-09 Long-connection task execution method and device and related equipment Pending CN116781764A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210226181.4A CN116781764A (en) 2022-03-09 2022-03-09 Long-connection task execution method and device and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210226181.4A CN116781764A (en) 2022-03-09 2022-03-09 Long-connection task execution method and device and related equipment

Publications (1)

Publication Number Publication Date
CN116781764A true CN116781764A (en) 2023-09-19

Family

ID=88006834

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210226181.4A Pending CN116781764A (en) 2022-03-09 2022-03-09 Long-connection task execution method and device and related equipment

Country Status (1)

Country Link
CN (1) CN116781764A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056056A (en) * 2023-10-10 2023-11-14 腾讯科技(深圳)有限公司 Task execution method and device, storage medium and electronic equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056056A (en) * 2023-10-10 2023-11-14 腾讯科技(深圳)有限公司 Task execution method and device, storage medium and electronic equipment

Similar Documents

Publication Publication Date Title
US20200204530A1 (en) Self-encrypting key management system
CN113347206B (en) Network access method and device
CN113875206B (en) Dedicated virtual network replication of cloud databases
CN110059055B (en) File storage and reading method and device based on distributed private cloud
US20190044998A1 (en) Network file transfer including file obfuscation
EP2521311A1 (en) Resource control method, apparatus and system in peer-to-peer network
CN104348870A (en) Data management method and system of cloud storage system based on trusted timestamp
CN106464596A (en) Openflow communication method, system, controller, and service gateway
CN106797384B (en) Routing requests to the same endpoint in a cluster in different protocols
CN113572864B (en) Data processing method, network element equipment and readable storage medium
US11394636B1 (en) Network connection path obfuscation using global access points
CN118018517A (en) Data processing method, network element equipment and readable storage medium
US10944801B1 (en) Serverless signaling in peer-to-peer session initialization
CN116781764A (en) Long-connection task execution method and device and related equipment
CN111984615B (en) File sharing method, device and system
EP3547231B1 (en) Electronic device management
US20190334701A1 (en) Lightweight security for internet of things messaging
CN114615315A (en) Communication method, device, equipment and storage medium for online conversation
US11271968B2 (en) Zero round trip time transmission for anticipatory request messages
CN110995730B (en) Data transmission method and device, proxy server and proxy server cluster
CN110958285B (en) Data storage system based on block chain
CN111984613A (en) Method, device and system for sharing files
CN113419878B (en) Data operation method and device
CN116743377B (en) Data processing method, device, equipment and storage medium based on blockchain key
Jing et al. Cloud storage encryption security analysis

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination