CN112685148A - Asynchronous communication method and device of mass terminals, computer equipment and storage medium - Google Patents

Asynchronous communication method and device of mass terminals, computer equipment and storage medium Download PDF

Info

Publication number
CN112685148A
CN112685148A CN202011420526.7A CN202011420526A CN112685148A CN 112685148 A CN112685148 A CN 112685148A CN 202011420526 A CN202011420526 A CN 202011420526A CN 112685148 A CN112685148 A CN 112685148A
Authority
CN
China
Prior art keywords
terminal
event
connection object
connection
communication
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
CN202011420526.7A
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.)
Southern Power Grid Digital Grid Research Institute Co Ltd
Original Assignee
Southern Power Grid Digital Grid Research Institute 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 Southern Power Grid Digital Grid Research Institute Co Ltd filed Critical Southern Power Grid Digital Grid Research Institute Co Ltd
Priority to CN202011420526.7A priority Critical patent/CN112685148A/en
Publication of CN112685148A publication Critical patent/CN112685148A/en
Pending legal-status Critical Current

Links

Images

Abstract

The application provides an asynchronous communication method and device of a mass terminal, computer equipment and a storage medium. The method comprises the following steps: the method comprises the steps of establishing communication connection with at least one terminal by monitoring connection requests of a plurality of terminals, adding a terminal handle of at least one terminal into an epoll queue, associating the terminal handle with a connection object, monitoring a communication event in the epoll queue, obtaining an IO ready event and a corresponding terminal handle, determining a target connection object according to the association relation between the terminal handle of the IO ready event and the connection object, processing the IO ready event in the target connection object, and sending an obtained IO message to an IO asynchronous data memory pool. The concurrent access of the massive terminals is realized through the epoll queue, the communication connection of the terminals is virtualized into a connection object, when a communication event occurs, the connection object is called and an IO ready event is processed in the connection object, the IO access and the IO processing are separated through an IO asynchronous data memory pool, and the asynchronous communication efficiency of the massive terminals is improved.

Description

Asynchronous communication method and device of mass terminals, computer equipment and storage medium
Technical Field
The present application relates to the field of power metering automation, and in particular, to an asynchronous communication method and apparatus for mass terminals, a computer device, and a storage medium.
Background
With the development of electric power metering automation, the metering automation of the electric power industry realizes the full coverage of the intelligent electric meter and the full coverage of low-voltage centralized meter reading, the number of terminals accessing a metering automation system is greatly increased, and higher requirements are provided for the terminal communication access efficiency of the system.
In the prior art, communication of massive terminals is usually realized through a server hardware cluster, and the access number of the terminals is limited, so that the efficiency of terminal communication is low.
Disclosure of Invention
Therefore, it is necessary to provide an asynchronous communication method, an asynchronous communication device, a computer device, and a storage medium for mass terminals, aiming at the technical problem of low terminal communication efficiency in the prior art.
An asynchronous communication method of a mass terminal is applied to a metering automation system server, and the method comprises the following steps:
monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding a terminal handle of at least one terminal into an epoll queue, and associating the terminal handle of at least one terminal with a respective corresponding connection object; the connection object is a virtual object generated according to communication connection established by the terminal;
monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event;
determining a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the incidence relation between the at least one terminal handle and the connection object;
and processing the IO ready event in the target connection object, and if the IO ready event is a read/write event, sending the obtained IO message to an IO asynchronous data memory pool, wherein the IO asynchronous data memory pool is used for storing the IO message in a message queue form and accessing and processing the IO message by a processing module of a metering automation system server.
In one embodiment, the monitoring connection requests of a plurality of terminals, establishing a communication connection with at least one terminal, and adding a terminal handle of at least one terminal to an epoll queue includes:
generating a terminal handle corresponding to the at least one terminal according to a Socket corresponding to the at least one terminal;
and adding the terminal handle corresponding to the at least one terminal into the red and black tree of the epoll queue.
In one embodiment, the monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event includes:
and monitoring the communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event from the rdllist doubly linked list.
In one embodiment, the method further comprises:
configuring a connection object corresponding to a terminal identifier of at least one terminal to obtain a connection object pool; the terminal identification is used for identifying different terminal types, and different terminal identifications correspond to different connection objects;
said associating the terminal handle of said at least one terminal with the respective connection object comprises:
inquiring the connection object pool according to the terminal identification of the at least one terminal to obtain connection objects respectively corresponding to the at least one terminal; and associating the terminal handle of the at least one terminal with the corresponding connection object.
In one embodiment, the querying, according to the terminal identifier of the at least one terminal, the connection object pool to obtain the connection objects corresponding to the at least one terminal respectively includes:
if the connection object pool does not comprise a connection object corresponding to the terminal identification of a certain terminal, generating a new connection object corresponding to the terminal identification of the terminal;
and placing the newly added connection object into the connection object pool, and taking the newly added connection object as a connection object corresponding to the terminal.
In one embodiment, after determining the target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the association relationship between the at least one terminal handle and the connection object, the method further includes:
and determining a target IO event model from a pre-configured IO event model according to the size of the target connection object, and distributing the target IO event model to the IO ready event.
In one embodiment, the monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event, further includes:
if the IO ready event is a disconnection event, controlling the corresponding terminal to be disconnected with the target connection object;
and putting the target connection object back to the connection object pool.
An apparatus for asynchronous communication of mass terminals, the apparatus comprising:
a communication connection establishing module, configured to monitor connection requests of multiple terminals, establish a communication connection with at least one terminal, add a terminal handle of the at least one terminal to an epoll queue, and associate the terminal handle of the at least one terminal with a corresponding connection object; the connection object is a virtual object generated according to communication connection established by the terminal;
a communication event monitoring module, configured to monitor a communication event in the epoll queue, and obtain an IO ready event and a terminal handle corresponding to the IO ready event;
a target object determining module, configured to determine a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and an association relationship between the at least one terminal handle and the connection object;
and the IO message sending module is used for processing the IO ready event in the target connection object, and if the IO ready event is a read/write event, sending the obtained IO message to an IO asynchronous data memory pool, wherein the IO asynchronous data memory pool is used for storing the IO message in a message queue mode and accessing and processing the IO message by a processing module of the metering automation system server.
A computer device comprising a memory storing a computer program and a processor implementing the steps of the method of any of the above embodiments when the processor executes the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method steps of any of the above embodiments.
The terminal communication access method, the device, the computer equipment and the storage medium establish communication connection with at least one terminal by monitoring connection requests of a plurality of terminals, add a terminal handle of at least one terminal into an epoll queue, associate the terminal handle with a connection object, monitor a communication event in the epoll queue, acquire an IO ready event and a corresponding terminal handle, determine a target connection object according to the terminal handle of the IO ready event and an association relation between the terminal handle and the connection object, process the IO ready event in the target connection object, send the obtained IO message to an IO asynchronous data memory pool, and access and process the IO ready event by a processing module of a metering automation system server. According to the scheme, concurrent access of massive terminals is achieved through the epoll queue, the communication connection of the terminals is virtualized into a connection object, when a communication event occurs, the connection object is called and an IO ready event is processed in the connection object, separation of IO access and IO processing is achieved through an IO asynchronous data memory pool, and efficiency of asynchronous communication of the massive terminals is improved.
Drawings
Fig. 1 is a diagram of an application environment of a terminal communication access method in one embodiment;
fig. 2 is a flowchart illustrating a communication access method of a terminal according to an embodiment;
fig. 3 is a diagram illustrating a communication access method of a terminal in one embodiment;
fig. 4 is a schematic diagram of a terminal communication access method in another embodiment;
fig. 5 is a schematic diagram of a terminal communication access method in another embodiment;
fig. 6 is a schematic diagram of a terminal communication access method in another embodiment;
FIG. 7 is a block diagram of a terminal communication access device in one embodiment;
FIG. 8 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The terminal communication access method provided by the application can be applied to the application environment shown in fig. 1. The terminal is communicated with a communication access module of the metering automation system server through a network. The metering automation system server can monitor a connection request of a terminal, establish communication connection, monitor communication events in the epoll queue, acquire corresponding IO ready events, process the IO events, obtain IO messages, and process the IO messages through a communication processing module of the metering automation system server. The terminal can be but not limited to various metering terminals, personal computers, notebook computers, smart phones, tablet computers and portable wearable devices, and the metering automation system server can be realized by an independent server or a server cluster formed by a plurality of servers.
In one embodiment, the metering automation system server may implement IO multiplexing based on an IO event driven communication model using Epoll asynchronous IO communication mechanism. Epoll can be pol which is improved by a Linux kernel for processing a large batch of file descriptors, and is an enhanced version of a multiplex IO interface select/pol under Linux, and the Epoll can improve the utilization rate of a system CPU under the condition that a program is only slightly active in a large number of concurrent connections. When acquiring an event, Epoll need not traverse the entire snooped descriptor set, as long as traversing the descriptor sets asynchronously awakened by kernel IO events and added to the Ready queue. Besides providing Level trigger (Level trigger) of select/poll IO event, epoll also provides Edge trigger (Edge trigger), which makes it possible for user space program to buffer IO state, reduces epoll _ wait/epoll _ pwait calls, and improves application program efficiency.
In specific implementation, a metering automation system server may call epoll _ create to establish an epoll object, establish a red-black tree in an inner core cache for storing a new packet transmitted by epoll _ ctl, and establish a rdllist bidirectional linked list for storing an IO ready event.
The metering automation system server can call epoll _ ctl to add a concurrently connected terminal socket to epoll, if a terminal handle is added, check whether the terminal handle exists in the red-black tree, if so, return immediately, if not, add the terminal handle to a trunk of the red-black tree, and then register a callback function with a kernel for temporarily inserting data into the rdllist doubly-linked list when an event occurs. In addition, the epoll _ ctl can modify and delete events to the epoll object, and can search corresponding events from the red and black trees, so as to realize management of concurrent access of massive terminals.
The metering automation system server may invoke epoll _ wait to collect the connections for which events occur. All events added to epoll establish a callback relationship with a driver of a device (such as a network card), that is, the callback method is called when the corresponding event occurs. When epoll _ wait is called, the rdllist two-way chaining table can be queried for the presence of data, and if so, the data is returned.
In one embodiment, as shown in fig. 2, an asynchronous communication method for mass terminals is provided, which is described by taking the method as an example applied to the metering automation system server in fig. 1, and includes the following steps:
step S201, monitoring connection requests of multiple terminals, establishing a communication connection with at least one terminal, adding a terminal handle of the at least one terminal to an epoll queue, and associating the terminal handle of the at least one terminal with a respective corresponding connection object.
Wherein the terminal may be a metering terminal of an electrical power system. The handle may be an identifier for identifying an object or item that an application needs to use when referencing a memory block or object managed by another system. The terminal handle may be an identifier corresponding to the terminal, and may be generated based on a socket of the terminal communication connection. In the connection request of the terminal, the terminal identifier corresponding to the terminal may be carried for distinguishing the type of the terminal. The metering automation system server can establish an epoll queue, and is used for adding a terminal handle of a terminal into the epoll queue when the terminal is accessed for communication. The metering automation system server can realize the concurrent access of a plurality of terminals and manage the concurrent access of the plurality of terminals through the epoll queue.
The connection object can be a virtual object generated by the metering automation system server according to the communication connection of the terminal, and is used for processing the event in the connection object when the terminal has a communication event, so as to realize the prepositive access of the terminal. The connection object can be stored in a pre-configured connection object pool, when the server monitors the connection request of the terminal, whether the corresponding pre-configured connection object exists can be searched first, and the connection object is prevented from being required to be created when the connection is established with the terminal every time. Therefore, when the terminal handle corresponding to the terminal and the connection object corresponding to the terminal are obtained, the metering automation system server can establish the association relationship between the terminal handle of the terminal and the connection object.
In the specific implementation, the metering automation system server may monitor connection requests of a plurality of terminals through a preconfigured server socket, establish communication connection with at least one terminal according to the connection requests, add a terminal handle corresponding to the terminal into an epoll queue, open a corresponding thread, and establish an association relationship between the terminal handle and a corresponding connection object according to the communication connection of the terminal.
Step S202, monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event.
The IO ready event may be an event available for execution in an IO event queue. The IO ready event may include the terminal handle that triggered the event. IO ready events may include read events, write events, and the like.
In specific implementation, the metering automation system server may obtain a corresponding communication event from the rdllist doubly linked list of the epoll queue, call back a corresponding IO ready event from the kernel, and obtain a terminal handle corresponding to the IO ready event.
Step S203, determining a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the association relationship between the at least one terminal handle and the connection object.
In a specific implementation, the metering automation system may determine, according to the obtained IO ready event, a target connection object corresponding to the IO ready event from the association relationship between the terminal handle and the connection object.
Step S204, in the target connection object, processing the IO event, and sending the obtained IO message to the IO asynchronous data memory pool.
The IO asynchronous data memory pool can be a shared memory module, and is used for storing IO messages in a message queue mode, and the IO asynchronous data memory pool is accessed and processed by a processing module of the metering automation system server. IO messages may include write messages, read messages, and the like. Through the IO asynchronous data memory pool, the server can separately perform IO receiving and transmitting and IO processing, and performs interaction through a message queue of a shared memory, so that the communication efficiency is improved.
In specific implementation, the metering automation system server may process an IO event in a target connection object corresponding to each terminal, send the obtained IO message to an IO asynchronous data memory pool if the IO ready event is a read/write event, and interact with the processing module through a message queue of the shared memory of the IO asynchronous data memory pool to implement corresponding data processing.
The asynchronous communication method of the massive terminals comprises the steps of establishing communication connection with at least one terminal by monitoring connection requests of a plurality of terminals, adding a terminal handle of at least one terminal into an epoll queue, associating the terminal handle with a connection object, monitoring a communication event in the epoll queue, obtaining an IO ready event and a corresponding terminal handle, determining a target connection object according to the terminal handle of the IO ready event and the association relationship between the terminal handle and the connection object, processing the IO ready event in the target connection object, sending an obtained IO message to an IO asynchronous data memory pool, and accessing and processing the IO ready event by a processing module of a metering automation system server. According to the scheme, concurrent access of massive terminals is achieved through the epoll queue, the communication connection of the terminals is virtualized into a connection object, when a communication event occurs, the connection object is called and an IO ready event is processed in the connection object, separation of IO access and IO processing is achieved through an IO asynchronous data memory pool, and efficiency of asynchronous communication of the massive terminals is improved.
In one embodiment, the step S201 of determining to monitor connection requests of multiple terminals and establish a communication connection with at least one terminal, and the step of adding a terminal handle of at least one terminal to an epoll queue includes:
generating a terminal handle corresponding to at least one terminal according to a Socket corresponding to at least one terminal; and adding a terminal handle corresponding to at least one terminal into the red and black tree of the epoll queue.
In this embodiment, when the epoll queue is created, the metering automation system server creates a red-black tree, and when a new terminal is monitored to be accessed, the Socket corresponding to the terminal can be obtained, and a corresponding terminal handle is generated and added to the red-black tree of the epoll queue for management. The metering automation system server can register a callback function to the kernel, and when a Socket corresponding to the terminal handle sends an interrupt event, data is inserted into the rdllist bidirectional linked list of the epoll queue.
In some embodiments, if the terminal handle of the terminal already exists in the red-black tree, the information of the terminal handle may be directly returned.
According to the scheme of the embodiment, the terminal handle corresponding to the terminal is generated according to the Socket corresponding to the terminal and is accessed to the red and black tree of the epoll queue, and the efficiency of multi-terminal concurrent access of the metering automation system server is improved.
In an embodiment, the step S202 of determining to monitor a communication event in the epoll queue, and the step of acquiring an IO ready event and a terminal handle corresponding to the IO ready event includes:
and monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event from the rdllist doubly linked list.
In this embodiment, when a communication event is generated in each communication connection in the epoll queue, the communication event may be written into the rdllist bidirectional linked list, and the metering automation system server may query data in the rdllist bidirectional linked list by calling epoll _ wait, and return an IO ready event included in the rdllist bidirectional linked list and a terminal handle corresponding to the IO ready event.
In some embodiments, there may be a plurality of IO ready events, and the metering automation system server may obtain each IO ready event and a corresponding terminal handle, and perform communication access processing through a plurality of threads.
According to the scheme of the embodiment, the IO ready event and the corresponding terminal handle are obtained from the rdllist doubly linked list by monitoring the communication event in the epoll queue, so that the efficiency of multi-terminal concurrent communication is improved.
In one embodiment, the method further comprises:
configuring a connection object corresponding to a terminal identifier of at least one terminal to obtain a connection object pool;
the step of associating the terminal handle of at least one terminal with a respective connection object, further comprises:
inquiring a connection object pool according to the terminal identification of at least one terminal to obtain connection objects corresponding to the at least one terminal respectively; and associating the terminal handle of at least one terminal with the corresponding connection object.
In this embodiment, the metering automation system server may configure a connection object for the communication connection of each terminal, and obtain a connection object pool. Specifically, the metering automation system server may generate a terminal object corresponding to the communication connection of each terminal according to the terminal identifier of each terminal establishing the communication connection. The terminal identifier may be used to identify different terminal types, and different terminal identifiers may correspond to different connection objects.
The metering automation system server may employ a connection object pooling technique, as shown in fig. 3, which is created from system initialization, and when a communication connection of a terminal is monitored and a connection object is created, the connection object may be acquired from the connection object pool. And if the cached connection object does not exist in the memory pool, establishing a new connection object for the communication connection of the terminal. And when the connection is disconnected, putting the corresponding connection object into the connection object pool again for calling when a new communication connection is established.
In one embodiment, a metering automation system server may associate a connection object of a terminal for which a communication connection has been established with the terminal handle. Specifically, the metering automation system server may query the connection object pool according to the terminal identifier of the terminal to obtain a connection object corresponding to the terminal, associate the terminal handle corresponding to the terminal with the connection object, and establish an association relationship between the terminal handle and the connection object.
In one embodiment, if the connection object pool does not include a connection object corresponding to a terminal identifier of a certain terminal, the metering automation system server may generate a new connection object corresponding to the terminal identifier of the terminal; and putting the newly added connection object into a connection object pool, taking the newly added connection object as a connection object corresponding to the terminal, and establishing a corresponding relation between a terminal handle and the newly added connection object. Therefore, the dynamic creation of the connection object is only carried out when the cached connection object does not exist in the connection object pool, and the influence on the system performance caused by a large number of connection and disconnection events in a short time is avoided.
According to the scheme of the embodiment, the connection object is configured in advance for the communication connection of the terminal and is placed in the connection object pool, and the association relation between the terminal handle and the connection object is established, so that the efficiency of communication access management of massive terminals is improved.
In an embodiment, after the step of determining the target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the association relationship between the at least one terminal handle and the connection object in step S203, the method further includes:
and according to the size of the target connection object, determining a target IO event model from a pre-configured IO event model, and allocating the target IO event model to the IO ready event.
In this embodiment, the metering automation system server may manage the processing mechanism of the IO model through multiple threads, and implement selection of the IO event model corresponding to the IO ready event through algorithm scheduling, and allocate the corresponding IO event model to each IO ready event. The IO event model may be a pre-configured algorithmic model of a metering automation system server that may be invoked to process a corresponding IO ready event. The number of the working threads processed by the IO model may be +1 of the number of CPU cores.
In some embodiments, as shown in fig. 4, the metering automation system server may use a multi-thread management communication object model in combination with the event-driven object model, and each communication object model may optimally select a corresponding communication model object according to the load rate, the size of the connection object, and the like, so that system resources are optimally matched to meet the requirement of mass connection access.
In some embodiments, the measurement automation system server may calculate and call back an optimal IO event model according to the size of the target connection object, the load rate of the system, and the like, so that system resources are optimally matched, and the requirement for communication access of a large number of terminals is met.
According to the scheme of the embodiment, the target IO event model is determined from the pre-configured IO event models according to the size of the target connection object and is allocated to the IO ready event, so that the efficiency of system resource configuration is improved, and the communication efficiency of the terminal is further improved.
In an embodiment, the step of monitoring a communication event in the epoll queue in step S203 and acquiring an IO ready event and a terminal handle corresponding to the IO ready event further includes:
if the IO ready event is a disconnection event, controlling the corresponding terminal to be disconnected with the target connection object; and putting the target connection object back to the connection object pool.
In this embodiment, the metering automation system server may control the corresponding terminal to disconnect from the target connection object according to the monitored disconnection event, and replace the target connection object in the connection object pool. The efficiency of the multiplexing of the connection objects is improved.
In an embodiment, as shown in fig. 5, the metering automation system server may adopt an asynchronous streaming processing model technology to change serial processing of communication into concurrent waterfall processing, and separate a communication process into IO transceiving access and IO processing, and directly interact with a message queue of a shared memory to improve the efficiency of network IO transceiving, and an IO processing module of the metering automation system server performs processing such as message analysis, alarm response, heartbeat response, interruption state, data forwarding, and the like according to IO messages.
In an embodiment, as shown in fig. 6, an asynchronous IO event-driven object communication model is provided, a communication engine framework based on asynchronous IO of a kernel layer is established, a kernel asynchronous IO multiplexing technology is used, communication efficiency is greatly improved through techniques such as kernel optimization, edge triggering, zero copy, object pooling for connection, an asynchronous streaming processing model, and an event-driven message processing mechanism is provided upwards, and concurrent access of a large number of terminals is realized. Meanwhile, each connection is virtualized into a communication object by using an object-oriented idea, an event of the communication object is triggered during data IO, the main function of prepositive access can be completed by processing the event in the service object, and communication details irrelevant to the service are hidden in a communication frame engine, so that logic processing is simplified according to the idea of layered structure modularization, and data processing is simplified, thereby ensuring reliability and high efficiency of the data. The specific steps may include:
step S601, monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, and generating a terminal handle corresponding to at least one terminal according to a Socket corresponding to at least one terminal; and adding a terminal handle corresponding to at least one terminal into the red and black tree of the epoll queue.
Step S602, inquiring a pre-configured connection object pool according to the terminal identification of at least one terminal to obtain connection objects corresponding to the at least one terminal respectively; associating the terminal handle of at least one terminal with the respective corresponding connection object; the connection object is a virtual object generated according to the communication connection established by the terminal.
Step S603, monitoring a communication event in the epoll queue, and obtaining an IO ready event and a terminal handle corresponding to the IO ready event from the rdllist doubly linked list.
Step S604, determining a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the incidence relation between the at least one terminal handle and the connection object; and according to the size of the target connection object, determining a target IO event model from a pre-configured IO event model, and allocating the target IO event model to an IO ready event.
Step S605, processing an IO ready event in a target connection object; if the IO ready event is a read/write event, sending the obtained IO message to an IO asynchronous data memory pool, wherein the IO asynchronous data memory pool is used for storing the IO message in a message queue form and accessing and processing the IO message by a processing module of a metering automation system server; if the IO ready event is a disconnection event, controlling the corresponding terminal to be disconnected with the target connection object; and putting the target connection object back to the connection object pool.
The solution of the above embodiment, by listening to connection requests of a plurality of terminals, establishing a communication connection with at least one terminal, adding a terminal handle of at least one terminal to a red-black tree of the epoll queue, associating the terminal handle with a connection object, monitoring a communication event in the epoll queue, acquiring an IO ready event and a corresponding terminal handle from a rdllist bi-directional linked list of the epoll queue, determining a target connection object according to the terminal handle of the IO ready event and the incidence relation between the terminal handle and the connection object, and processing an IO ready event in the target connection object, if the IO ready event is a read-write event, sending the obtained IO message to an IO asynchronous data memory pool, accessing and processing the IO asynchronous data memory pool by a processing module of the metering automation system server, and if the IO ready event is a disconnection event, controlling the corresponding terminal to be disconnected with the target connection object. According to the scheme, concurrent access of massive terminals is achieved through the epoll queue, the communication connection of the terminals is virtualized into a connection object, when a communication event occurs, the connection object is called and an IO ready event is processed in the connection object, separation of IO access and IO processing is achieved through an IO asynchronous data memory pool, and efficiency of asynchronous communication of the massive terminals is improved.
It should be understood that although the various steps in the flow charts of fig. 2-6 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2-6 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed in turn or alternately with other steps or at least some of the other steps.
In one embodiment, as shown in fig. 7, there is provided an asynchronous communication apparatus for mass terminals, the apparatus 700 comprising:
a communication connection establishing module 701, configured to monitor connection requests of multiple terminals, establish a communication connection with at least one terminal, add a terminal handle of the at least one terminal to an epoll queue, and associate the terminal handle of the at least one terminal with a corresponding connection object; the connection object is a virtual object generated according to the communication connection established by the terminal;
a communication event monitoring module 702, configured to monitor a communication event in the epoll queue, and obtain an IO ready event and a terminal handle corresponding to the IO ready event;
a target object determining module 703, configured to determine a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and an association relationship between at least one terminal handle and the connection object;
and the IO message sending module 704 is configured to process an IO ready event in the target connection object, and if the IO ready event is a read/write event, send the obtained IO message to an IO asynchronous data memory pool, where the IO asynchronous data memory pool is used to store the IO message in a form of a message queue, and the IO message is accessed and processed by a processing module of the metering automation system server.
In one embodiment, the communication connection establishing module 701 includes: the system comprises a red-black tree unit, a black-red tree unit and a black-red tree unit, wherein the red-black tree unit is used for generating a terminal handle corresponding to at least one terminal according to a Socket corresponding to the at least one terminal; and adding a terminal handle corresponding to at least one terminal into the red and black tree of the epoll queue.
In one embodiment, the communication event listening module 702 includes: and the linked list unit is used for monitoring the communication events in the epoll queue, and acquiring the IO ready events and the terminal handles corresponding to the IO ready events from the rdllist bi-directional linked list.
In one embodiment, the apparatus 700 further includes: the connection object pool module is used for configuring a connection object corresponding to the terminal identifier of at least one terminal to obtain a connection object pool; the terminal identification is used for identifying different terminal types, and different terminal identifications correspond to different connection objects.
In an embodiment, the communication connection establishing module 701 further includes: the handle and object association unit is used for inquiring the connection object pool according to the terminal identification of at least one terminal to obtain connection objects corresponding to the at least one terminal respectively; and associating the terminal handle of at least one terminal with the corresponding connection object.
In an embodiment, the handle and object associating unit is further configured to generate a new connection object corresponding to the terminal identifier of the terminal if the connection object pool does not include the connection object corresponding to the terminal identifier of the certain terminal; and putting the newly added connection object into the connection object pool, and taking the newly added connection object as a connection object corresponding to the terminal.
In one embodiment, the target object determination module 703 includes: and the IO event model unit is used for determining a target IO event model from the pre-configured IO event model according to the size of the target connection object and distributing the target IO event model to the IO ready event.
In one embodiment, the IO message sending module 704 includes: the disconnection unit is used for controlling the corresponding terminal to be disconnected with the target connection object if the IO ready event is a disconnection event; and putting the target connection object back to the connection object pool.
For specific limitations of the asynchronous communication device of the mass terminals, reference may be made to the above limitations of the asynchronous communication method of the mass terminals, and details are not described here. The modules in the asynchronous communication device of the mass terminal can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
The asynchronous communication method of the mass terminals provided by the application can be applied to computer equipment, the computer equipment can be a server, and the internal structure diagram can be shown in fig. 8. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to store the connection object and epoll data. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement an asynchronous communication method of a mass terminal.
Those skilled in the art will appreciate that the architecture shown in fig. 8 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the above-described method embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical storage, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. The asynchronous communication method of the mass terminal is applied to a metering automation system server, and comprises the following steps:
monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding a terminal handle of at least one terminal into an epoll queue, and associating the terminal handle of at least one terminal with a respective corresponding connection object; the connection object is a virtual object generated according to communication connection established by the terminal;
monitoring a communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event;
determining a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the incidence relation between the at least one terminal handle and the connection object;
and processing the IO ready event in the target connection object, and if the IO ready event is a read/write event, sending the obtained IO message to an IO asynchronous data memory pool, wherein the IO asynchronous data memory pool is used for storing the IO message in a message queue form and accessing and processing the IO message by a processing module of a metering automation system server.
2. The method of claim 1, wherein the listening for connection requests of a plurality of terminals, establishing a communication connection with at least one terminal, and adding a terminal handle of at least one terminal to an epoll queue comprises:
generating a terminal handle corresponding to the at least one terminal according to a Socket corresponding to the at least one terminal;
and adding the terminal handle corresponding to the at least one terminal into the red and black tree of the epoll queue.
3. The method according to claim 2, wherein the monitoring the communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event includes:
and monitoring the communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event from the rdllist doubly linked list.
4. The method of claim 1, further comprising:
configuring a connection object corresponding to a terminal identifier of at least one terminal to obtain a connection object pool; the terminal identification is used for identifying different terminal types, and different terminal identifications correspond to different connection objects;
said associating the terminal handle of said at least one terminal with the respective connection object comprises:
inquiring the connection object pool according to the terminal identification of the at least one terminal to obtain connection objects respectively corresponding to the at least one terminal; and associating the terminal handle of the at least one terminal with the corresponding connection object.
5. The method according to claim 4, wherein the querying the connection object pool according to the terminal identifier of the at least one terminal to obtain the connection objects respectively corresponding to the at least one terminal comprises:
if the connection object pool does not comprise a connection object corresponding to the terminal identification of a certain terminal, generating a new connection object corresponding to the terminal identification of the terminal;
and placing the newly added connection object into the connection object pool, and taking the newly added connection object as a connection object corresponding to the terminal.
6. The method according to claim 1, wherein after determining a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and the association relationship between the at least one terminal handle and the connection object, the method further comprises:
and determining a target IO event model from a pre-configured IO event model according to the size of the target connection object, and distributing the target IO event model to the IO ready event.
7. The method according to claim 4, wherein the monitoring the communication event in the epoll queue, and acquiring an IO ready event and a terminal handle corresponding to the IO ready event, further comprises:
if the IO ready event is a disconnection event, controlling the corresponding terminal to be disconnected with the target connection object;
and putting the target connection object back to the connection object pool.
8. An apparatus for asynchronous communication of mass terminals, the apparatus comprising:
a communication connection establishing module, configured to monitor connection requests of multiple terminals, establish a communication connection with at least one terminal, add a terminal handle of the at least one terminal to an epoll queue, and associate the terminal handle of the at least one terminal with a corresponding connection object; the connection object is a virtual object generated according to communication connection established by the terminal;
a communication event monitoring module, configured to monitor a communication event in the epoll queue, and obtain an IO ready event and a terminal handle corresponding to the IO ready event;
a target object determining module, configured to determine a target connection object corresponding to the IO ready event according to the terminal handle corresponding to the IO ready event and an association relationship between the at least one terminal handle and the connection object;
and the IO message sending module is used for processing the IO ready event in the target connection object, and if the IO ready event is a read/write event, sending the obtained IO message to an IO asynchronous data memory pool, wherein the IO asynchronous data memory pool is used for storing the IO message in a message queue mode and accessing and processing the IO message by a processing module of the metering automation system server.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method of any of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
CN202011420526.7A 2020-12-07 2020-12-07 Asynchronous communication method and device of mass terminals, computer equipment and storage medium Pending CN112685148A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011420526.7A CN112685148A (en) 2020-12-07 2020-12-07 Asynchronous communication method and device of mass terminals, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011420526.7A CN112685148A (en) 2020-12-07 2020-12-07 Asynchronous communication method and device of mass terminals, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112685148A true CN112685148A (en) 2021-04-20

Family

ID=75446207

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011420526.7A Pending CN112685148A (en) 2020-12-07 2020-12-07 Asynchronous communication method and device of mass terminals, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112685148A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113127204A (en) * 2021-04-29 2021-07-16 四川虹美智能科技有限公司 Method and server for processing concurrent services based on reactor network model
CN113342554A (en) * 2021-08-02 2021-09-03 阿里云计算有限公司 IO multiplexing method, medium, device and operating system
CN113965561A (en) * 2021-10-20 2022-01-21 中电科航空电子有限公司 Airborne file transmission system based on asynchronous event driving
CN116820430A (en) * 2023-08-28 2023-09-29 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070043856A1 (en) * 2005-02-07 2007-02-22 Metavize, Inc. Methods and systems for low-latency event pipelining
US20130024875A1 (en) * 2011-07-22 2013-01-24 Yilin Wang Event System And Methods For Using Same
US20150277997A1 (en) * 2014-03-31 2015-10-01 Solarflare Communications, Inc. Ordered Event Notification
US20160277215A1 (en) * 2013-12-30 2016-09-22 Tencent Technology (Shenzhen) Company Limited Data transfer method and system
CN106534107A (en) * 2016-11-04 2017-03-22 北方工业大学 Internet of Things message service system
CN106815083A (en) * 2016-12-20 2017-06-09 微梦创科网络科技(中国)有限公司 A kind of client asynchronous processing method and client based on Memcache agreements
CN108563493A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of event-driven method, device, equipment and readable storage medium storing program for executing
CN109002363A (en) * 2018-06-21 2018-12-14 郑州云海信息技术有限公司 A kind of event-handling method, device, equipment and readable storage medium storing program for executing
CN109309599A (en) * 2018-09-06 2019-02-05 华南理工大学 A method of the communication of internet of things equipment high concurrent is realized based on street lamp hardware platform
WO2020181486A1 (en) * 2019-03-12 2020-09-17 华为技术有限公司 Information processing method, apparatus, and system

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070043856A1 (en) * 2005-02-07 2007-02-22 Metavize, Inc. Methods and systems for low-latency event pipelining
US20130024875A1 (en) * 2011-07-22 2013-01-24 Yilin Wang Event System And Methods For Using Same
US20160277215A1 (en) * 2013-12-30 2016-09-22 Tencent Technology (Shenzhen) Company Limited Data transfer method and system
US20150277997A1 (en) * 2014-03-31 2015-10-01 Solarflare Communications, Inc. Ordered Event Notification
CN106534107A (en) * 2016-11-04 2017-03-22 北方工业大学 Internet of Things message service system
CN106815083A (en) * 2016-12-20 2017-06-09 微梦创科网络科技(中国)有限公司 A kind of client asynchronous processing method and client based on Memcache agreements
CN108563493A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of event-driven method, device, equipment and readable storage medium storing program for executing
CN109002363A (en) * 2018-06-21 2018-12-14 郑州云海信息技术有限公司 A kind of event-handling method, device, equipment and readable storage medium storing program for executing
CN109309599A (en) * 2018-09-06 2019-02-05 华南理工大学 A method of the communication of internet of things equipment high concurrent is realized based on street lamp hardware platform
WO2020181486A1 (en) * 2019-03-12 2020-09-17 华为技术有限公司 Information processing method, apparatus, and system

Non-Patent Citations (11)

* Cited by examiner, † Cited by third party
Title
DAAN KOLTHOF: "Asynchronous file I/O on Linux: the epoll API", pages 1 - 2, Retrieved from the Internet <URL:https://daankolthof.com/2019/08/01/asynchronous-file-i-o-on-linux-the-epoll-api/> *
LINUX: "Linux下的socket编程实践—epoll实现高并发的原理及其使用", pages 1 - 3, Retrieved from the Internet <URL:https://zhuanlan.zhihu.com/p/94136425> *
SHENYA1314: "高并发网络编程之epoll详解", pages 1 - 12, Retrieved from the Internet <URL:https://blog.csdn.net/shenya1314/article/details/73691088> *
YOUNG WANG: "IO模型和基于事件驱动的IO多路复用模式", pages 1, Retrieved from the Internet <URL:https://zhuanlan.zhihu.com/p/161357177> *
付学良;李德军;: "Linux下基于epoll机制的海量配电终端信息采集C/S模型", 华电技术, no. 05 *
余二五: "epoll事件处理机制详解", pages 1 - 10, Retrieved from the Internet <URL:https://developer.aliyun.com/article/484014> *
戴伟: "基于Nginx高性能Web服务器的理论研究与性能改进", 中国优秀硕士学位论文全文数据库 信息科技辑, no. 2, 15 February 2020 (2020-02-15), pages 137 - 180 *
林强;刘暾东;蔡建立;江灏;: "高性能I/O完成端口服务器的实现与优化", 电脑知识与技术, no. 33 *
王华伟;: "基于异步多线程机制的实时通信研究", 铁路通信信号工程技术, no. 03, 25 June 2017 (2017-06-25), pages 18 - 22 *
王文武 等: "高性能服务器底层网络通信模块的设计方法", 计算机工程, no. 03, 5 February 2009 (2009-02-05), pages 103 - 105 *
科幻与显示: "利用epoll实现异步IO", pages 1 - 2, Retrieved from the Internet <URL:https://www.cnblogs.com/zhouyang123200/p/6613302.html> *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113127204A (en) * 2021-04-29 2021-07-16 四川虹美智能科技有限公司 Method and server for processing concurrent services based on reactor network model
CN113342554A (en) * 2021-08-02 2021-09-03 阿里云计算有限公司 IO multiplexing method, medium, device and operating system
CN113342554B (en) * 2021-08-02 2022-01-04 阿里云计算有限公司 IO multiplexing method, medium, device and operating system
CN113965561A (en) * 2021-10-20 2022-01-21 中电科航空电子有限公司 Airborne file transmission system based on asynchronous event driving
CN113965561B (en) * 2021-10-20 2023-08-25 中电科航空电子有限公司 Asynchronous event driven-based airborne file transmission system
CN116820430A (en) * 2023-08-28 2023-09-29 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium
CN116820430B (en) * 2023-08-28 2024-01-09 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112685148A (en) Asynchronous communication method and device of mass terminals, computer equipment and storage medium
US8381230B2 (en) Message passing with queues and channels
CN107241281B (en) Data processing method and device
CN111865657B (en) Acceleration management node, acceleration node, client and method
EP2898655B1 (en) System and method for small batching processing of usage requests
CN115328663A (en) Method, device, equipment and storage medium for scheduling resources based on PaaS platform
CN112825042A (en) Resource management method and device, electronic equipment and storage medium
CN111338779B (en) Resource allocation method, device, computer equipment and storage medium
WO2021051881A1 (en) Vpp cluster management method and device, computer device and storage medium
CN112698952A (en) Unified management method and device for computing resources, computer equipment and storage medium
CN110162395B (en) Memory allocation method and device
CN110941681B (en) Multi-tenant data processing system, method and device of power system
CN111885184A (en) Method and device for processing hot spot access keywords in high concurrency scene
CN111858656A (en) Static data query method and device based on distributed architecture
CN116126916A (en) Data query method, device and equipment based on intelligent network card
CN115480934A (en) Distributed data processing method, device, equipment and storage medium
CN115062340A (en) Device access method, interface processing method and device
CN115202853A (en) Virtual reality video cloud computing service method
CN115878309A (en) Resource allocation method, device, processing core, equipment and computer readable medium
CN112463748A (en) Storage system file lock identification method, system, terminal and storage medium
CN112231290A (en) Method, device and equipment for processing local log and storage medium
WO2024037629A1 (en) Data integration method and apparatus for blockchain, and computer device and storage medium
CN117076133B (en) Cloud game platform heterogeneous resource allocation method, computer device and storage medium
CN116820430B (en) Asynchronous read-write method, device, computer equipment and storage medium
CN111949414B (en) Method, system, terminal and storage medium for optimizing performance of storage controller

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