Algorithm scheduling method and device based on gRPC and priority message queue
By adopting the algorithm scheduling method of gRPC and priority message queue in the intelligent inspection platform, the problem of target recognition algorithm deployment and communication limitation is solved, efficient communication and priority task processing is achieved, and the stability of the production environment is improved. Emergency task handling capability.
Patent Information
- Application Number
- CN202411022785.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-12-13
AI Technical Summary
In the intelligent inspection platform, the deployment and communication of the target recognition algorithm are limited by the same server and cannot be deployed in a distributed manner, resulting in the stability of the production environment and the inability to handle target recognition tasks according to priority.
Using the algorithm scheduling method based on gRPC and priority message queue, the target identification type is obtained by receiving and parsing mqtt information, and added to the priority message queue. The processing thread of the target identification algorithm component is added based on the gRPC framework and priority message queue to perform target identification Algorithm that supports hot loading and priority processing.
It improves the communication efficiency between the platform and algorithm components, realizes the distributed deployment of algorithm components and priority task processing, simplifies the docking process, and supports the issuance of emergency tasks in the production environment.
Smart Images

Figure CN119127416A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent inspection, and in particular to an algorithm scheduling method and device based on gRPC and a priority message queue. Background Art
[0002] In the intelligent inspection platform or intelligent identification and early warning system, the target recognition algorithm is generally integrated into the system as a module. The communication between the algorithm and the platform is limited to the same server, and it is impossible to perform distributed deployment according to the needs of the production environment. Adding or deleting an algorithm requires restarting the platform component to take effect, which greatly affects the stability of the production environment. The distribution of target recognition tasks cannot be handled according to priority, and cannot meet the requirements of use in specific usage scenarios.
[0003] Generally speaking, there are two ways to deploy target recognition algorithms. One is to deploy them as a separate service and use TCP for communication. The other is to integrate them into the platform as a module component of the platform. The first deployment method can separate the algorithm and the platform and reduce coupling, but the communication uses the relatively low-level TCP, which requires the implementation of the upper-level application protocol and makes docking more difficult. The second deployment method uses the system interface for communication between platforms, which can quickly and efficiently complete the docking, but it is integrated into the system, has a high degree of coupling, and cannot perform local upgrades on the platform. Summary of the invention
[0004] In response to the above technical problems, the present invention provides an algorithm scheduling method and device based on gRPC and priority message queue, which can improve the communication efficiency between the platform and algorithm components.
[0005] A first aspect of the present invention provides an algorithm scheduling method based on gRPC and a priority message queue, comprising: receiving an mqtt message and parsing the mqtt message to obtain a target recognition type of a target recognition task;
[0006] If there is a target identification algorithm component corresponding to the target identification type, adding the mqtt information to the priority message queue;
[0007] Based on the gRPC framework and the priority message queue, a processing thread corresponding to the target recognition algorithm component is added, and based on the processing thread, the target recognition algorithm component is called to execute the target recognition algorithm.
[0008] In an optional implementation, the algorithm scheduling method based on gRPC and priority message queue further includes: if there is no target recognition algorithm corresponding to the target recognition type, generating an exception message. In an optional implementation, the receiving of mqtt information and parsing of mqtt information to obtain the target recognition type of the target recognition task includes at least one of the following target recognition types:
[0009] Helmet recognition, personnel recognition, and instrument recognition.
[0010] In an optional implementation, the newly added processing thread corresponding to the target recognition algorithm component based on the gRPC framework and the priority message queue includes:
[0011] The received mqtt information is obtained according to the priority message queue, the target recognition algorithm component is hot loaded based on the gRPC framework, and the target recognition algorithm component is distributed to a new processing thread.
[0012] In an optional implementation, a new processing thread corresponding to the target identification algorithm component is added based on the gRPC framework and the priority message queue, and also includes: obtaining and receiving the mqtt information based on the priority order according to the message priority in the priority message queue, and hot loading the target identification algorithm component based on the gRPC framework.
[0013] A second aspect of the present invention provides an algorithm scheduling device based on gRPC and a priority message queue, comprising: a parsing module, for receiving an mqtt message and parsing the mqtt message to obtain a target recognition type of a target recognition task;
[0014] A queue processing module, configured to add the mqtt information to a priority message queue if there is a target recognition algorithm component corresponding to the target recognition type;
[0015] The scheduling module is used to add a processing thread corresponding to the target recognition algorithm component based on the gRPC framework and the priority message queue, and call the target recognition algorithm component based on the processing thread to execute the target recognition algorithm.
[0016] In an optional implementation, the end module is further configured to generate an exception message and send an MQTT message if there is no target recognition algorithm corresponding to the target recognition type.
[0017] In an optional embodiment, the scheduling module is also used to obtain the received mqtt information based on the priority order according to the message priority in the priority message queue, hot load the target recognition algorithm component based on the gRPC framework, and distribute the target recognition algorithm component to a new processing thread.
[0018] According to a third aspect of the present invention, there is provided an electronic device, comprising:
[0019] At least one processor; and at least one memory communicatively connected to the processor, wherein: the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the method described in the first aspect of the embodiment of the present invention.
[0020] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a computer, the method according to the first aspect of the embodiment of the present invention is executed.
[0021] This paper uses gRPC as the communication between the scheduling service and the target recognition algorithm, which not only improves the communication efficiency between the platform and the algorithm components, but also simplifies the docking process. gRPC shields the implementation of data transmission and application layer protocols. Developers only need to focus on the parameters sent and received. At the same time, the use of priority queues to distribute target recognition tasks can effectively solve the urgent task distribution when used in production environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 The figure is a flow chart of an algorithm scheduling method based on gRPC and priority message queue in an embodiment of the present invention.
[0023] Figure 2 This is a flow chart of another algorithm scheduling method based on gRPC and priority message queue in an embodiment of the present invention.
[0024] Figure 3 A module schematic diagram of an algorithm scheduling device based on gRPC and priority message queue in an embodiment of the present invention. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0026] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0027] To facilitate understanding of the present invention, technical terms used in the present invention will be explained.
[0028] RPC: RPC (Remote Procedure Call), that is, remote procedure call, is simply a technology that can call methods in remote computer processes like calling local methods. In this call, we do not need to understand any details of network communication. The ultimate problem solved is to make calls between different services in a distributed or microservice system as simple as local calls.
[0029] gRPC: gRPC is a modern open source RPC framework originally developed by Google. It is a language-neutral, platform-neutral, and RPC system similar to many RPC systems.
[0030] Priority queue: A normal queue is a first-in, first-out data structure. Elements are added to the end of the queue and deleted from the head of the queue. In a priority queue, elements are assigned priorities. When accessing an element, the element with the highest priority is deleted first. The priority queue has the behavior of first in, largest out.
[0031] See also Figure 1 The present invention provides an algorithm scheduling method based on gRPC and priority message queue, comprising the following steps.
[0032] S10: Receive MQTT information and parse the MQTT information to obtain the target recognition type of the target recognition task.
[0033] The intelligent inspection platform will send MQTT information to the scheduling component, and the scheduling component will send and receive parameters according to the defined interface.
[0034] In some embodiments, it is necessary to define the input and output parameters of each gRPC interface for communication between the scheduling component and the algorithm component.
[0035] The priority and category of the mqtt message are specified by the task issued by the intelligent inspection platform, which contains the two fields of priority and category. The target recognition type and priority of the target recognition task are obtained by parsing the mqtt message.
[0036] In some embodiments, the target recognition type includes at least one of the following target recognition types:
[0037] Helmet recognition, personnel recognition, and instrument recognition.
[0038] The intelligent inspection platform or the collected video image data can perform different target recognition through the target recognition algorithm configuration, and different target recognition may have different target recognition models. Different target recognition algorithms can be called by parsing the target recognition type required by the target recognition task.
[0039] S20: If there is a target identification algorithm component corresponding to the target identification type, the mqtt information is added to the priority message queue.
[0040] For example, if the target identification type obtained through analysis is personnel identification or instrument identification, the intelligent inspection platform can use the scheduling component to call the target identification algorithm component for identifying personnel and for identifying instruments. Then add the task information (mqtt information) to the priority message queue so that the task information can be processed according to priority in the subsequent steps.
[0041] In some embodiments, if there is no target recognition algorithm corresponding to the target recognition type, an abnormal information is generated and an MQTT message is sent to feedback the abnormal information to the intelligent inspection platform.
[0042] S30: Based on the gRPC framework and the priority message queue, a processing thread corresponding to the target recognition algorithm component is added, and based on the processing thread, the target recognition algorithm component is called to execute the target recognition algorithm.
[0043] In some embodiments, based on the gRPC framework, the scheduling component obtains the received mqtt information according to the priority message queue, hot loads the target identification algorithm component, and distributes the target identification algorithm component to a new processing thread.
[0044] The hot loading of the target algorithm component can be synchronized with the scheduling component through the http interface. When a target recognition algorithm component is added, the scheduling component will add a processing thread of the category algorithm to distribute the category algorithm. When the specified target recognition algorithm component is deleted, the algorithm scheduling component will exit and destroy the corresponding processing thread. The external program will call the http interface of the scheduling component and specify whether to delete or add through parameters.
[0045] Furthermore, based on the gRPC framework, the scheduling component will obtain the received mqtt information based on the priority order according to the message priority in the priority message queue, for example, hot loading the target recognition algorithm component corresponding to the mqtt information with the highest priority. That is, target recognition is processed according to the priority of task information, and the target recognition algorithm is executed first. For example, the target recognition algorithm for personnel recognition is executed first, that is, a target recognition algorithm component for personnel recognition is added first, and a processing process is added to execute the algorithm for personnel recognition.
[0046] Based on the gRPC framework, each target recognition algorithm corresponds to an independent target recognition algorithm component. Since all data transmission is implemented through gRPC, deploying target recognition algorithm components on different servers can achieve effective communication.
[0047] In the present invention, the target recognition algorithm can be deployed separately using a container, and also supports distributed deployment on different servers. The addition and deletion of target recognition algorithm components supports hot loading without affecting the operation of the entire intelligent inspection platform.
[0048] Furthermore, the target recognition algorithm component is independent, and if an algorithm component is added or deleted, the program can be notified through the interface to add or delete the corresponding message processing thread.
[0049] Furthermore, after the target recognition algorithm is executed, the recognition results are fed back to the intelligent inspection platform through MQTT messages and business processing is performed, such as outputting the number of people recognized, the oil meter reading data recognized, etc.
[0050] The present invention uses gRPC as the communication between the scheduling service and the target recognition algorithm, which can not only improve the communication efficiency between the platform and the algorithm components, but also is very simple in the docking process. gRPC shields the implementation of data transmission and application layer protocols. Developers only need to focus on the sent parameters and the received parameters. At the same time, the use of priority queues to distribute target recognition tasks can effectively solve the emergency task distribution when used in a production environment.
[0051] See also Figure 2 , Figure 2 The present invention provides another algorithm scheduling method based on gRPC and priority message queue, including the following steps.
[0052] S21: Start.
[0053] S22: Receive mqtt information.
[0054] S23: Analyze the target identification type.
[0055] S24: Determine whether there is a category target recognition algorithm component.
[0056] S25: Add the task information to the priority queue.
[0057] S26: The target recognition algorithm component performs target recognition.
[0058] Determine whether to add a new target recognition algorithm component. If so, parse the target recognition algorithm component category and add a processing thread for the algorithm category.
[0059] S27: Generate recognition results.
[0060] S28: Send MQTT information.
[0061] S29: Generate exception information and go to step S28.
[0062] See also Figure 3 The present invention also provides an algorithm scheduling device based on gRPC and priority message queue, including: a parsing module 31, a queue processing module 32, a scheduling module 33, and an ending module 34.
[0063] The parsing module 31 is used to receive the MQTT information and parse the MQTT information to obtain the target recognition type of the target recognition task;
[0064] A queue processing module 32, configured to add the mqtt information to a priority message queue if there is a target identification algorithm component corresponding to the target identification type;
[0065] A scheduling module 33 is used to add a processing thread corresponding to the target recognition algorithm component based on the gRPC framework and the priority message queue, and call the target recognition algorithm component based on the processing thread to execute the target recognition algorithm;
[0066] In some embodiments, the end module is also included, which is used to generate abnormal information and send MQTT information if there is no target recognition algorithm corresponding to the target recognition type.
[0067] In some embodiments, the scheduling module 33 is also used to obtain the received mqtt information based on the priority order according to the message priority in the priority message queue, hot load the target recognition algorithm component based on the gRPC framework, and distribute the target recognition algorithm component to a new processing thread.
[0068] The functions or methods performed by the above modules can be referred to the description of the algorithm scheduling method based on gRPC and priority message queue, which will not be repeated here.
[0069] The present invention also provides an electronic device, comprising:
[0070] At least one processor; and at least one memory communicatively connected to the processor, wherein: the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the above-mentioned algorithm scheduling method based on gRPC and priority message queue.
[0071] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the algorithm scheduling method based on gRPC and priority message queue is implemented.
[0072] It can be understood that computer-readable storage media may include: any entity or device capable of carrying a computer program, recording media, USB flash drives, mobile hard disks, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), and software distribution media, etc. A computer program includes computer program code. The computer program code may be in source code form, object code form, executable file, or some intermediate form, etc. A computer-readable storage medium may include: any entity or device capable of carrying a computer program code, recording media, USB flash drives, mobile hard disks, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), and software distribution media, etc.
[0073] In certain embodiments of the present invention, the device may include a controller, which is a single-chip microcomputer chip that integrates a processor, a memory, a communication module, etc. The processor may refer to the processor included in the controller. The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
[0074] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present invention belong.
[0075] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0076] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An algorithm scheduling method based on gRPC and priority message queue, It is characterized in that include: Receive MQTT information and parse it to obtain the target recognition type of the target recognition task; If there is a target identification algorithm component corresponding to the target identification type, adding the mqtt information to the priority message queue; Based on the gRPC framework and the priority message queue, a processing thread corresponding to the target recognition algorithm component is added, and based on the processing thread, the target recognition algorithm component is called to execute the target recognition algorithm.
2. According to the algorithm scheduling method based on gRPC and priority message queue according to claim 1, It is characterized in that Also includes: If there is no target identification algorithm corresponding to the target identification type, an exception message is generated and an MQTT message is sent.
3. According to the algorithm scheduling method based on gRPC and priority message queue according to claim 1, It is characterized in that The receiving of MQTT information and parsing of MQTT information to obtain the target identification type of the target identification task includes at least one of the following target identification types: Helmet recognition, personnel recognition, and instrument recognition.
4. According to the algorithm scheduling method based on gRPC and priority message queue according to claim 1, It is characterized in that The newly added processing thread corresponding to the target recognition algorithm component based on the gRPC framework and the priority message queue includes: The received mqtt information is obtained according to the priority message queue, the target recognition algorithm component is hot loaded based on the gRPC framework, and the target recognition algorithm component is distributed to a new processing thread.
5. According to the algorithm scheduling method based on gRPC and priority message queue according to claim 4, It is characterized in that Based on the gRPC framework and the priority message queue, a new processing thread corresponding to the target identification algorithm component is added, which also includes: obtaining and receiving the mqtt information based on the priority order according to the message priority in the priority message queue, and hot loading the target identification algorithm component based on the gRPC framework.
6. An algorithm scheduling device based on gRPC and priority message queue, It is characterized in that include: A parsing module is used to receive MQTT information and parse it to obtain the target recognition type of the target recognition task; A queue processing module, configured to add the mqtt information to a priority message queue if there is a target recognition algorithm component corresponding to the target recognition type; The scheduling module is used to add a processing thread corresponding to the target recognition algorithm component based on the gRPC framework and the priority message queue, and call the target recognition algorithm component based on the processing thread to execute the target recognition algorithm.
7. The algorithm scheduling device based on gRPC and priority message queue according to claim 6, It is characterized in that It also includes an end module, which is used to generate abnormal information and send MQTT information if there is no target recognition algorithm corresponding to the target recognition type.
8. The algorithm scheduling device based on gRPC and priority message queue according to claim 6, It is characterized in that The scheduling module is also used to obtain and receive the mqtt information based on the priority order according to the message priority in the priority message queue, hot load the target recognition algorithm component based on the gRPC framework, and distribute the target recognition algorithm component to a new processing thread.
9. An electronic device, It is characterized in that include: at least one processor; And at least one memory communicatively connected to the processor, wherein: the memory stores program instructions executable by the processor, and the processor calls the program instructions to execute the algorithm scheduling method based on gRPC and priority message queue as described in any one of claims 1 to 5.
10. A computer-readable storage medium, It is characterized in that A computer program is stored thereon, and when the computer program is run by a computer, the algorithm scheduling method based on gRPC and priority message queue as described in any one of claims 1 to 5 is executed.
