CN112685148B - Asynchronous communication method and device for mass terminals, computer equipment and storage medium - Google Patents

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

Info

Publication number
CN112685148B
CN112685148B CN202011420526.7A CN202011420526A CN112685148B CN 112685148 B CN112685148 B CN 112685148B CN 202011420526 A CN202011420526 A CN 202011420526A CN 112685148 B CN112685148 B CN 112685148B
Authority
CN
China
Prior art keywords
terminal
connection object
event
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.)
Active
Application number
CN202011420526.7A
Other languages
Chinese (zh)
Other versions
CN112685148A (en
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/CN112685148B/en
Publication of CN112685148A publication Critical patent/CN112685148A/en
Application granted granted Critical
Publication of CN112685148B publication Critical patent/CN112685148B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Telephonic Communication Services (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application provides an asynchronous communication method, an asynchronous communication device, computer equipment and a storage medium of a mass terminal. The method comprises the following steps: the method comprises the steps of monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding terminal handles of the at least one terminal to an epoll queue, associating the terminal handles with connection objects, monitoring communication events in the epoll queue, acquiring IO ready events and corresponding terminal handles, determining a target connection object according to association relation between the IO ready event terminal handles and the connection objects, processing the IO ready events in the target connection object, and sending obtained IO messages to an IO asynchronous data memory pool. And the concurrent access of the mass 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 separation of IO access and IO processing is realized through the IO asynchronous data memory pool, and the asynchronous communication efficiency of the mass terminals is improved.

Description

Asynchronous communication method and device for 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 a mass terminal, a computer device, and a storage medium.
Background
Along 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 the low-voltage centralized meter reading, the number of the terminal access metering automation systems is greatly increased, and higher requirements are provided for the terminal communication access efficiency of the systems.
In the prior art, communication of a large number of terminals is generally realized through a server hardware cluster, and the terminal has limited access quantity, so that the efficiency of terminal communication is low.
Disclosure of Invention
Based on this, it is necessary to provide an asynchronous communication method, apparatus, computer device and storage medium for a mass terminal, aiming at the technical problem of low communication efficiency of the terminal in the prior art.
An asynchronous communication method of a mass terminal, which is applied to a metering automation system server, comprises the following steps:
monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding terminal handles of the at least one terminal into an epoll queue, and associating the terminal handles of the at least one terminal with respective corresponding connection objects; the connection object is a virtual object generated according to the 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 association relation between the at least one terminal handle and the connection object;
And in the target connection object, processing the IO ready event, 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 the at least one terminal to an epoll queue includes:
generating a terminal handle corresponding to the at least one terminal according to the Socket corresponding to the at least one terminal;
And adding the terminal handle corresponding to the at least one terminal to the red-black tree of the epoll queue.
In one embodiment, the monitoring the communication event in the epoll queue, acquiring the IO ready event and the 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 a 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 identifier is used for identifying different terminal types, and the different terminal identifiers correspond to different connection objects;
The associating the terminal handle of the at least one terminal with the respective connection object includes:
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 the connection object pool according to the terminal identifier of the at least one terminal to obtain the connection object corresponding to the at least one terminal includes:
if the connection object pool does not comprise a connection object corresponding to the terminal identifier of a certain terminal, generating a newly added connection object corresponding to the terminal identifier 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 IO ready event.
In one embodiment, the monitoring the communication event in the epoll queue, 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 placing the target connection object back into the connection object pool.
An asynchronous communication device for a mass terminal, the device comprising:
The communication connection establishment module is used for monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding terminal handles of the at least one terminal into an epoll queue, and associating the terminal handles of the at least one terminal with respective corresponding connection objects; the connection object is a virtual object generated according to the communication connection established by the terminal;
The communication event monitoring module is used for monitoring communication events in the epoll queue and acquiring IO ready events and terminal handles corresponding to the IO ready events;
The target object determining module is used for 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 relation 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, sending the obtained IO message to an IO asynchronous data memory pool if the IO ready event is a read/write event, and storing the IO message in a message queue form by the IO asynchronous data memory pool, 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 embodiments described above when the computer program is executed.
A computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method steps of any of the embodiments described above.
The terminal communication access method, the device, the computer equipment and the storage medium are characterized in that communication connection is established with at least one terminal by monitoring connection requests of a plurality of terminals, terminal handles of the at least one terminal are added into an epoll queue, the terminal handles are associated with connection objects, communication events in the epoll queue are monitored, IO ready events and corresponding terminal handles are acquired, a target connection object is determined according to the terminal handles of the IO ready events and the association relation between the terminal handles and the connection objects, IO ready events are processed in the target connection object, the acquired IO messages are sent to an IO asynchronous data memory pool, and the IO asynchronous data memory pool is accessed and processed by a processing module of a metering automation system server. According to the scheme, concurrent access of the mass terminals is realized through the epoll queue, communication connection of the terminals is virtualized into the 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 realized through the IO asynchronous data memory pool, and the asynchronous communication efficiency of the mass terminals is improved.
Drawings
FIG. 1 is an application environment diagram of a terminal communication access method in one embodiment;
fig. 2 is a flow chart of a method for accessing terminal communication in one embodiment;
FIG. 3 is a schematic diagram of a method of terminal communication access 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 an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The terminal communication access method provided by the application can be applied to an application environment shown in figure 1. The terminal communicates with a communication access module of the metering automation system server through a network. The metering automation system server can monitor the connection request of the terminal, establish communication connection, monitor the communication event in the epoll queue, acquire the corresponding IO ready event, process the IO event, acquire IO information, and process the IO information by the communication processing module of the metering automation system server. The terminal may 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 may be implemented by a separate server or a server cluster formed by a plurality of servers.
In one embodiment, the metering automation system server may implement IO multiplexing using an Epoll asynchronous IO communication mechanism based on an IO event driven communication model. The Epoll can be poll improved by the Linux kernel for processing large-batch file descriptors, is an enhanced version of the multiplexing IO interface select/poll under Linux, and can improve the system CPU utilization rate of a program under the condition that only a small amount of concurrent connections are active. When acquiring an event, epoll does not need to traverse the whole monitored descriptor set, but only traverses the descriptor set which is asynchronously awakened by the kernel IO event and is added into the Ready queue. In addition to providing horizontal triggering (LEVEL TRIGGERED) of IO events of the select/poll type, the epoll also provides edge triggering (EDGE TRIGGERED), which makes it possible for the user space program to cache IO status, reducing the invocation of epoll_wait/epoll_ pwait, and improving application efficiency.
In a specific implementation, the metering automation system server may call epoll_create to create an epoll object, create a red-black tree in the kernel cache to store the epoll_ctl new incoming socket, and create rdllist a doubly linked list to store the IO ready event.
The metering automation system server may 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 yes, immediately return, if not, add to the trunk of the red-black tree, and then register a callback function with the 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 in the epoll object, and can search corresponding events from the red and black trees, so that the management of concurrent access of mass terminals is realized.
The metering automation system server may invoke epoll_wait to collect connections for occurrence. All events added to the epoll will establish callback relation with the driver of the device (such as the network card), that is, the callback method will be called when the corresponding event occurs. When epoll_wait is invoked, whether data exists in the rdllist bidirectional link table can be queried, and if so, the data is returned.
In one embodiment, as shown in fig. 2, there is provided an asynchronous communication method of a mass terminal, which is described by taking an example that the method is applied to the metering automation system server of fig. 1, and includes the following steps:
Step S201, monitoring connection requests of a plurality of terminals, establishing communication connection with at least one terminal, adding terminal handles of at least one terminal to an epoll queue, and associating terminal handles of at least one terminal with respective corresponding connection objects.
The terminal may be a metering terminal of the power system. The handle may be an identifier for identifying an object or item that the application needs to use when referencing a memory block or object managed by other systems. 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 can be carried for distinguishing the type of the terminal. The metering automation system server may establish an epoll queue for adding a terminal handle of a terminal to the epoll queue when there is a terminal communication access. 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 may be a virtual object generated by the metering automation system server according to the communication connection of the terminal, and is used for processing an event in the connection object when the terminal has a communication event, so as to realize the front access of the terminal. The connection object can be stored in a preconfigured connection object pool, and when the server monitors the connection request of the terminal, whether the corresponding preconfigured connection object exists or not can be searched first, so that the connection object needs to be created every time connection is established with the terminal. 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 specific implementation, the metering automation system server can 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 terminal handles corresponding to the terminal into an epoll queue, start corresponding threads, and establish association relation between the terminal handles and corresponding connection objects according to the communication connection of the terminal.
Step S202, monitoring communication events in an epoll queue, and acquiring IO ready events and terminal handles corresponding to the IO ready events.
The IO ready event may be an event available for execution in an IO event queue. The IO ready event may include a terminal handle that triggers the event. IO ready events may include read events, write events, and the like.
In a specific implementation, the metering automation system server may acquire a corresponding communication event from the rdllist bidirectional linked list of the epoll queue, and call back an IO ready event corresponding to the kernel, and acquire 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 relation between at least one terminal handle and the connection object.
In a specific implementation, the metering automation system can determine a target connection object corresponding to the IO ready event from the association relationship between the terminal handle and the connection object according to the obtained IO ready event.
And 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 the form of message queues, and the IO messages are accessed and processed by a processing module of the metering automation system server. The IO message may include a write message, a read message, and the like. Through the IO asynchronous data memory pool, the server can separate IO receiving and transmitting from IO processing, and the communication efficiency is improved through interaction of message queues of the shared memory.
In the specific implementation, the metering automation system server can process IO events in the target connection objects corresponding to the terminals, if the IO ready events are read/write events, the obtained IO messages are sent to the IO asynchronous data memory pool, and the corresponding data processing is realized by interaction between the message queues of the shared memory of the IO asynchronous data memory pool and the processing module.
According to the asynchronous communication method of the mass terminals, communication connection is established with at least one terminal by monitoring connection requests of a plurality of terminals, terminal handles of the at least one terminal are added into an epoll queue, the terminal handles are associated with connection objects, communication events in the epoll queue are monitored, IO ready events and corresponding terminal handles are obtained, a target connection object is determined according to the terminal handles of the IO ready events and the association relation between the terminal handles and the connection objects, the IO ready events are processed in the target connection object, the obtained IO messages are sent to an IO asynchronous data memory pool, and the IO asynchronous data memory pool is accessed and processed by a processing module of a metering automation system server. According to the scheme, concurrent access of the mass terminals is realized through the epoll queue, communication connection of the terminals is virtualized into the 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 realized through the IO asynchronous data memory pool, and the asynchronous communication efficiency of the mass terminals is improved.
In one embodiment, the step of determining to monitor connection requests of a plurality of terminals, establishing a communication connection with at least one terminal, and adding a terminal handle of the at least one terminal to the epoll queue in step S201 includes:
Generating a terminal handle corresponding to at least one terminal according to the Socket corresponding to the at least one terminal; and adding the terminal handle corresponding to at least one terminal into the red black tree of the epoll queue.
In this embodiment, when the metering automation system server creates the epoll queue, it creates the red-black tree, and when it monitors that a new terminal is accessed, it can acquire the Socket corresponding to the terminal, generate the corresponding terminal handle, and add the corresponding terminal handle 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 insert data into the rdllist bidirectional linked list of the epoll queue when the Socket corresponding to the terminal handle sends an interrupt event.
In some embodiments, if the terminal handle of the terminal already exists in the mangrove, the information of the terminal handle may be returned directly.
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 the mangrove is accessed to the epoll queue, so that the multi-terminal concurrent access efficiency of the metering automation system server is improved.
In one embodiment, the step of determining to monitor the communication event in the epoll queue in step S202, and the step of obtaining the IO ready event and the terminal handle corresponding to the IO ready event includes:
and monitoring communication events in the epoll queue, and acquiring the 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 rdllist data in the bidirectional linked list by calling epoll_wait, and return the IO ready event contained therein and the terminal handle corresponding to the IO ready event.
In some embodiments, there may be multiple 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 multiple threads.
According to the scheme of the embodiment, the IO ready event and the corresponding terminal handle are acquired 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 terminal handles of at least one terminal with respective connection objects further comprises:
inquiring a connection object pool according to the terminal identification of at least one terminal to obtain connection objects respectively corresponding to at least one terminal; 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, to 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 that establishes the communication connection. The terminal identification may be used to identify different terminal types, which may correspond to different connection objects.
The metering automation system server may employ a connection object pooling technique, as shown in fig. 3, to create a connection object pool from the system initialization, and may acquire a connection object from the connection object pool when monitoring the communication connection of the terminal and creating the connection object. And if the cached connection object does not exist in the memory pool, newly establishing the connection object for the communication connection of the terminal. When the connection is disconnected, the corresponding connection object is put into the connection object pool again for being called when the new communication connection is established.
In one embodiment, the metering automation system server may be associated with a connection object for a terminal for which a communication connection has been established. 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, and further associate the terminal handle corresponding to the terminal with the connection object, so as to 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 newly added 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. 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 objects are pre-configured for the communication connection of the terminal and placed in the connection object pool, so that the association relationship between the terminal handle and the connection objects is established, and the efficiency of communication access management of mass terminals is improved.
In one 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 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 IO ready event.
In this embodiment, the metering automation system server may implement selection of an IO event model corresponding to an IO ready event through processing mechanism of multithreading management IO model and algorithm scheduling, and allocate a corresponding IO event model to each IO ready event. The IO event model may be an algorithmic model pre-configured by the metering automation system server that may be invoked to process the corresponding IO ready event. The number of working threads processed by the IO model can be CPU core number +1.
In some embodiments, as shown in fig. 4, the metering automation system server may use a multithreading management communication object model in combination with an event driven object model, where each communication object model may calculate an optimal selection of a corresponding communication model object according to a load rate, a connection object size, and the like, so as to enable system resources to be optimally matched, and meet a requirement of massive connection access.
In some embodiments, the metering 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 of mass terminal communication access 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 distributed 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 one embodiment, the step of monitoring the communication event in the epoll queue in step S203, obtaining the IO ready event and the 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 placing the target connection object back into the connection object pool.
In this embodiment, the metering automation system server may control, according to the detected disconnection event, the corresponding terminal to disconnect from the target connection object, and put the target connection object back into the connection object pool. The efficiency of multiplexing the connection objects is improved.
In one embodiment, as shown in fig. 5, the metering automation system server may adopt an asynchronous flow processing model technology, change serial processing of communication into concurrent waterfall processing, separate a communication process into IO receiving and transmitting access and IO processing, directly interact through a message queue of a shared memory, improve efficiency of network IO receiving and transmitting, and perform processing such as message analysis, alarm response, heartbeat response, interrupt state, data forwarding and the like by an IO processing module of the metering automation system server according to the IO message.
In one embodiment, as shown in fig. 6, an object communication model driven by an asynchronous IO event is provided, a communication engine framework based on an asynchronous IO of a kernel layer is established, a kernel asynchronous IO multiplexing technology is used, communication efficiency is greatly improved through technologies such as kernel optimization, edge triggering, zero copying, object pooling connection, asynchronous streaming processing model and the like, an event driven message processing mechanism is provided upwards, and massive terminal concurrent access is realized. And simultaneously, by using an object-oriented idea, each connection is virtualized into a communication object, an event of the communication object is triggered when data is input or output, the main function of front access can be finished 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 hierarchical structure assembly, and the data processing is simplified, thereby ensuring the reliability and the 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 terminal handles corresponding to at least one terminal according to sockets corresponding to the at least one terminal; and adding the terminal handle corresponding to at least one terminal into the red 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 respectively corresponding to at least one terminal; associating terminal handles of at least one terminal with respective corresponding connection objects; the connection object is a virtual object generated according to the communication connection established by the terminal.
Step S603, monitor the communication event in the epoll queue, obtain the IO ready event from the rdllist doubly linked list, and the terminal handle corresponding to the IO ready event.
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 association relation between at least one terminal handle and the connection object; and 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 IO event model to the IO ready event.
Step S605, in the target connection object, processing an IO ready event; if the IO ready event is a read/write event, the obtained IO message is sent to an IO asynchronous data memory pool, and the IO asynchronous data memory pool is used for storing the IO message in a message queue form and is accessed and processed by a processing module of the 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 placing the target connection object back into the connection object pool.
According to the scheme of the embodiment, communication connection is established with at least one terminal by monitoring connection requests of a plurality of terminals, terminal handles of the at least one terminal are added to a red-black tree of an epoll queue, the terminal handles are associated with connection objects, communication events in the epoll queue are monitored, IO ready events and corresponding terminal handles are obtained from a rdllist bidirectional linked list of the epoll queue, a target connection object is determined according to the terminal handles of the IO ready events and the association relation between the terminal handles and the connection objects, IO ready events are processed in the target connection object, if the IO ready events are read-write events, the obtained IO messages are sent to an IO asynchronous data memory pool and are accessed and processed by a processing module of a metering automation system server, and if the IO ready events are disconnection events, the corresponding terminal is controlled to be disconnected from the target connection object. According to the scheme, concurrent access of the mass terminals is realized through the epoll queue, communication connection of the terminals is virtualized into the 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 realized through the IO asynchronous data memory pool, and the asynchronous communication efficiency of the mass terminals is improved.
It should be understood that, although the steps in the flowcharts of fig. 2-6 are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 2-6 may include multiple steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor does the order in which the steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of the steps or stages in other steps or other steps.
In one embodiment, as shown in fig. 7, there is provided an asynchronous communication apparatus of a mass terminal, the apparatus 700 comprising:
A communication connection establishment module 701, configured to monitor connection requests of a plurality of 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 respective corresponding connection object; the connection object is a virtual object generated according to the communication connection established by the terminal;
The communication event monitoring module 702 is 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;
the target object determining module 703 is 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, send the obtained IO message to the IO asynchronous data memory pool if the IO ready event is a read/write event, and the IO asynchronous data memory pool is configured to store the IO message in a message queue form, and access and process the IO message by the processing module of the metering automation system server.
In one embodiment, the communication connection establishment module 701 includes: the mangrove unit is used for generating a terminal handle corresponding to at least one terminal according to the Socket corresponding to the at least one terminal; and adding the terminal handle corresponding to at least one terminal into the red black tree of the epoll queue.
In one embodiment, the communication event listening module 702 includes: the linked list unit is used for monitoring communication events in the epoll queue, acquiring IO ready events from the rdllist bidirectional linked list and terminal handles corresponding to the IO ready events.
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 the different terminal identifications correspond to different connection objects.
In one embodiment, the communication connection establishment 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 respectively corresponding to at least one terminal; and associating the terminal handle of at least one terminal with the corresponding connection object.
In one embodiment, the handle and object association unit is further configured to generate a newly added connection object corresponding to a terminal identifier of a terminal if the connection object pool does not include a connection object corresponding to the terminal identifier of a certain terminal; and putting the newly added connection object into a 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, IO message transmission 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 placing the target connection object back into the connection object pool.
For a specific limitation of the asynchronous communication device of the mass terminal, reference may be made to the above limitation of the asynchronous communication method of the mass terminal, and the description thereof will not be repeated here. The modules in the asynchronous communication device of the mass terminal can be realized in whole or in part by software, hardware and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
The asynchronous communication method of the mass terminals can be applied to computer equipment, wherein the computer equipment can be a server, and the internal structure diagram of the computer equipment can be shown as figure 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 includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is used to store connection objects 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, when executed by a processor, implements a method for asynchronous communication of a mass of terminals.
It will be appreciated by those skilled in the art that the structure shown in FIG. 8 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be implemented, as a specific computer device may include more or fewer components than shown, or may be combined with 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 method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, or the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.

Claims (8)

1. An asynchronous communication method of a mass terminal, which is applied to a metering automation system server, the method comprising:
Generating a terminal handle corresponding to at least one terminal according to a Socket corresponding to the at least one terminal; adding a terminal handle corresponding to the at least one terminal to a red-black tree of an epoll queue; configuring a connection object corresponding to the terminal identifier of at least one terminal to obtain a connection object pool; 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; associating terminal handles of the at least one terminal with respective corresponding connection objects; the connection object is a virtual object generated according to the communication connection established by the terminal; the terminal identifier is used for identifying different terminal types, and the different terminal identifiers correspond to different connection objects;
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 association relation between the at least one terminal handle and the connection object;
And in the target connection object, processing the IO ready event, 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 monitoring the communication event in the epoll queue, obtaining an IO ready event and a terminal handle corresponding to the IO ready event, comprises:
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 a rdllist doubly linked list.
3. The method according to claim 1, 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 includes:
if the connection object pool does not comprise a connection object corresponding to the terminal identifier of a certain terminal, generating a newly added connection object corresponding to the terminal identifier 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.
4. The method according to claim 1, wherein 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 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 IO ready event.
5. The method of claim 4, wherein the monitoring the communication event in the epoll queue, obtaining 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 placing the target connection object back into the connection object pool.
6. An asynchronous communication device for a mass terminal, the device comprising:
The communication connection establishment module is used for generating a terminal handle corresponding to at least one terminal according to a Socket corresponding to the at least one terminal; adding a terminal handle corresponding to the at least one terminal to a red-black tree of an epoll queue; configuring a connection object corresponding to the terminal identifier of at least one terminal to obtain a connection object pool; 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; associating terminal handles of the at least one terminal with respective corresponding connection objects; the connection object is a virtual object generated according to the communication connection established by the terminal; the terminal identifier is used for identifying different terminal types, and the different terminal identifiers correspond to different connection objects;
The communication event monitoring module is used for monitoring communication events in the epoll queue and acquiring IO ready events and terminal handles corresponding to the IO ready events;
The target object determining module is used for 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 relation 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, sending the obtained IO message to an IO asynchronous data memory pool if the IO ready event is a read/write event, and storing the IO message in a message queue form by the IO asynchronous data memory pool, and accessing and processing the IO message by a processing module of the metering automation system server.
7. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 5 when the computer program is executed.
8. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 5.
CN202011420526.7A 2020-12-07 2020-12-07 Asynchronous communication method and device for mass terminals, computer equipment and storage medium Active CN112685148B (en)

Priority Applications (1)

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

Applications Claiming Priority (1)

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

Publications (2)

Publication Number Publication Date
CN112685148A CN112685148A (en) 2021-04-20
CN112685148B true CN112685148B (en) 2024-06-11

Family

ID=75446207

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN112685148B (en)

Families Citing this family (4)

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

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Family Cites Families (4)

* 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
WO2013016299A1 (en) * 2011-07-22 2013-01-31 Yilin Wang Event system and methods for using same
CN104754003B (en) * 2013-12-30 2019-01-08 腾讯科技(深圳)有限公司 Transmit the method and system of data
US9778963B2 (en) * 2014-03-31 2017-10-03 Solarflare Communications, Inc. Ordered event notification

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 (5)

* Cited by examiner, † Cited by third party
Title
Linux下基于epoll机制的海量配电终端信息采集C/S模型;付学良;李德军;;华电技术(第05期) *
基于Nginx高性能Web服务器的理论研究与性能改进;戴伟;中国优秀硕士学位论文全文数据库 信息科技辑;20200215(第2期);I137-180 *
基于异步多线程机制的实时通信研究;王华伟;;铁路通信信号工程技术;20170625(03);18-22 *
高性能I/O完成端口服务器的实现与优化;林强;刘暾东;蔡建立;江灏;;电脑知识与技术(第33期) *
高性能服务器底层网络通信模块的设计方法;王文武 等;计算机工程;20090205(03);103-105 *

Also Published As

Publication number Publication date
CN112685148A (en) 2021-04-20

Similar Documents

Publication Publication Date Title
CN112685148B (en) Asynchronous communication method and device for mass terminals, computer equipment and storage medium
CN107729139B (en) Method and device for concurrently acquiring resources
CN107241281B (en) Data processing method and device
WO2021088641A1 (en) Data transmission method, data processing method, data reception method and device, and storage medium
CN111400246B (en) Asynchronous file import method, device, computer equipment and storage medium
CN111666145A (en) Message processing method and system of message queue and computer equipment
CN112698952A (en) Unified management method and device for computing resources, computer equipment and storage medium
CN112463290A (en) Method, system, apparatus and storage medium for dynamically adjusting the number of computing containers
CN110706148B (en) Face image processing method, device, equipment and storage medium
CN111541762A (en) Data processing method, management server, device and storage medium
CN213876703U (en) Resource pool management system
CN113220432B (en) Multi-cloud interconnection method, device, equipment, storage medium and product
CN108259605B (en) Data calling system and method based on multiple data centers
CN111399999B (en) Computer resource processing method, device, readable storage medium and computer equipment
CN110941681B (en) Multi-tenant data processing system, method and device of power system
CN117435335A (en) Computing power dispatching method, computing power dispatching device, computer equipment and storage medium
CN115982133A (en) Data processing method and device
CN117633102A (en) Block chain data integration method, device, computer equipment and storage medium
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
CN110768855B (en) Method and device for testing linkmzation performance
CN112463748A (en) Storage system file lock identification method, system, terminal and storage medium
CN105376273A (en) Standard cloud service interface and standard cloud service method
CN111459981A (en) Query task processing method, device, server and system

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
GR01 Patent grant
GR01 Patent grant