Real-time communication method and apparatus for distributed system, and distributed system
Patent Information
- Application Number
- CA3152842
- Authority / Receiving Office
- CA · CA
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2019-08-27
- Filing Date
- 2020-06-24
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2040-06-24
Abstract
Description
REAL-TIME COMMUNICATION METHOD AND APPARATUS FOR DISTRIBUTED SYSTEM, AND DISTRIBUTED SYSTEM BACKGROUND OF THE INVENTION Technical Field
[0001] The present invention relates to the field of distribution technology, and more particularly to a real-time communicating method within a distributed system, a real-time communicating device within a distributed system, and a distributed system. Description of Related Art
[0002] With the vigorous development of the artificial intelligence technology, more and more artificial intelligence techniques have come into applications. In the applications of artificial intelligence algorithms, hardware computational resources are also extremely relied besides the performance of the algorithms themselves. Currently a single equipment possesses multiple cores, and the performance is already very strong, but when a project requires computational resources that exceed the limit offerable by a single equipment, a distributed solving scheme is usually employed, namely to allocate the resources required by the computational capabilities to different equipments. The distributed solving scheme needs to divide the system into various nodes, each bearing certain calculation tasks, and these nodes intercommunicate through network. Usually when algorithms are operating, such as processing images and coding / decoding videos, these algorithms consume CPU or GPU resources of nodes, and such programs that mainly consume CPU or GPU resources are generally referred to as calculation-intensive tasks. The calculation-intensive tasks can be processed with multiple threads, but the more threads there are, the more time will be spent in switching the tasks, and the lower will be the efficiency in executing the CPU, so such programs cannot use too much threads. A distributed system possesses plural nodes, which are generally classified as master nodes and worker nodes, and network communication should be performed between the master nodes and the worker nodes. When it is required to perform real-time communication between these two types of nodes, if data concurrency is huge, great quantities of IOs will be produced, and such tasks that require great quantities of IOs are generally referred to as IO-intensive tasks. The IO-intensive tasks generally do not consume much CPUs, but would frequently interrupt the CPUs.
[0003] As the inventor found during the process of realizing the present invention, when an algorithm is deployed on a distributed system architecture to respond to outputs in real time, with respect to tasks that are not only calculation-intensive but also network IO- intensive on multi-core nodes, unduly much IOs in the network so frequently interrupts calculation tasks of the algorithm that efficiency in algorithm calculation is severely affected, whereby it is made impossible for the entire distributed system to respond to outputs in real time. SUMMARY OF THE INVENTION
[0004] In order to overcome the aforementioned technical problems, embodiments of the present invention provide a real-time communicating method within a distributed system, a corresponding device and a distributed system, whereby, under the distributed environment, with respect to tasks that are not only calculation-intensive but also network IO-intensive on multi-core nodes, calculation tasks are separated from communication tasks, so that is guaranteed that the entire distributed system can respond to outputs in real time.
[0005] Specific technical solutions provided by the embodiments of the present invention are as follows:
[0006] According to the first aspect, there is provided a real-time communicating method within a distributed system, the distributed system includes a master node and a worker node, on the worker node are deployed an algorithm task unit and a communication task unit, and the method comprises:
[0007] the communication task unit performing an initialization operation after the communication task unit has been started, and entering a monitor state after having completed the initialization operation, wherein the initialization operation includes initializing a shared memory and a network connection;
[0008] the algorithm task unit being started after the communication task unit has entered the monitor state, and processing a calculation task initiated by the master node after the algorithm task unit has been started;
[0009] the algorithm task unit writing a calculation result of the calculation task in the shared memory;
[0010] the communication task unit reading the calculation result when the communication task unit monitors that the calculation result is stored in the shared memory; and
[0011] the communication task unit returning the calculation result to the master node through the network connection.
[0012] Further, the step of the algorithm task unit being started after the communication task unit has entered the monitor state includes:
[0013] notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state, so as to make the algorithm task unit started.
[0014] Further, the step of the algorithm task unit writing a calculation result of the calculation task in the shared memory includes:
[0015] the algorithm task unit serializing the calculation result of the calculation task to obtain serialized data, and writing the serialized data in the shared memory; and
[0016] the step of the communication task unit reading the calculation result when the communication task unit monitors that the calculation result is stored in the shared memory includes:
[0017] the communication task unit obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data of the calculation result is stored in the shared memory, and descrializing the serialized data to obtain the calculation result.
[0018] Further, the initialization operation further includes creating a message queue, the method further comprises, prior to the step of the communication task unit returning the calculation result to the master node through the network connection:
[0019] the communication task unit adding the calculation result to the message queue; and
[0020] the step of the communication task unit returning the calculation result to the master node through the network connection includes:
[0021] the communication task unit extracting the calculation result from the message queue if the communication task unit receives a calculation result request initiated from the master node, and returning the calculation result to the master node through the network connection.
[0022] Further, the step of the communication task unit extracting the calculation result from the message queue if the communication task unit receives a calculation result request initiated from the master node, and returning the calculation result to the master node through the network connection includes:
[0023] the communication task unit enquiring, if it receives a calculation result request initiated from the master node, in the message queue whether there is any calculation result requested by the calculation result request;
[0024] if yes, returning the calculation result to the master node;
[0025] if not, obstructing the calculation result request, and waking up the calculation result request when there is a new calculation result in the message queue; and
[0026] judging whether the new calculation result is the calculation result requested by the calculation result request, if yes, returning the new calculation result to the master node, if not, continuing to obstruct the calculation result request.
[0027] According to the second aspect, there is provided a real-time communicating device within a distributed system, the distributed system includes a master node and a worker node, the device is located on the worker node, and the device comprises an algorithm task unit and a communication task unit, wherein:
[0028] the communication task unit is employed for performing an initialization operation after the communication task unit has been started, and entering a monitor state after having completed the initialization operation, wherein the initialization operation includes initializing a shared memory and a network connection;
[0029] the algorithm task unit is employed for being started after the communication task unit has entered the monitor state, and processing a calculation task initiated by the master node after the algorithm task unit has been started;
[0030] the algorithm task unit is further employed for writing a calculation result of the calculation task in the shared memory; and
[0031] the communication task unit is further employed for reading the calculation result when the communication task unit monitors that the calculation result is stored in the shared memory, and returning the calculation result to the master node through the network connection.
[0032] Further, the communication task unit is specifically employed for:
[0033] notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state, so as to make the algorithm task unit started.
[0034] Further, the algorithm task unit is specifically employed for:
[0035] serializing the calculation result of the calculation task to obtain serialized data, and writing the serialized data in the shared memory; and
[0036] the communication task unit is specifically employed for:
[0037] obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data of the calculation result is stored in the shared memory, and deserializing the serialized data to obtain the calculation result.
[0038] Further, the initialization operation further includes creating a message queue, and the communication task unit is further employed for:
[0039] adding the calculation result to the message queue; and
[0040] extracting the calculation result from the message queue if a calculation result request initiated from the master node is received, and returning the calculation result to the master node through the network connection.
[0041] Further, the communication task unit is specifically employed for:
[0042] enquiring, if it receives a calculation result request initiated from the master node, in the message queue whether there is any calculation result requested by the calculation result request;
[0043] if yes, returning the calculation result to the master node;
[0044] if not, obstructing the calculation result request, and waking up the calculation result request when there is a new calculation result in the message queue; and
[0045] judging whether the new calculation result is the calculation result requested by the calculation result request, if yes, returning the new calculation result to the master node, if not, continuing to obstruct the calculation result request.
[0046] According to the third aspect, there is provided a distributed system, the system comprises a master node and at least one worker node configured to include a real-time communicating device within a distributed system according to any item of the second aspect.
[0047] The technical solutions provided by the embodiments of the present invention bring about the following advantageous effects:
[0048] Communication tasks and calculation tasks are separated from each other by deploying an algorithm task unit and a communication task unit on multi-core nodes in a distributed environment, whereby it is not only guaranteed that calculation threads in calculation- intensive tasks are not frequently interrupted by too much network IOs, but also guaranteed that network IOs transmit data in real time, so that it is made possible for the distributed system to communicate in real time to ensure real-time output of algorithms.
[0049] The use of a shared memory between the communication task and the calculation task for communication makes it possible to greatly enhance the efficiency of inter-process communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] To more clearly explain the technical solutions in the embodiments of the present invention, drawings required for use in the following explanation of the embodiments are briefly described below. Apparently, the drawings described below are merely directed to some embodiments of the present invention, while it is further possible for persons ordinarily skilled in the art to base on these drawings to acquire other drawings, and no creative effort will be spent in the process.
[0051] Fig. 1 is a flowchart illustrating a real-time communicating method within a distributed system provided by an embodiment of the present invention;
[0052] Fig. 2 is a block diagram illustrating the structure of a real-time communicating device within a distributed system provided by an embodiment of the present invention; and
[0053] Fig. 3 is a block diagram illustrating the structure of a distributed system provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0054] To make more lucid and clear the objectives, technical solutions and advantages of the present invention, technical solutions in the embodiments of the present invention will be described more clearly and completely below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the embodiments described below are merely partial, rather than the entire, embodiments of the present invention. All other embodiments achievable by persons ordinarily skilled in the art on the basis of the embodiments in the present invention without creative effort shall all fall within the protection scope of the present invention.
[0055] The distributed solving scheme has been widely applied in the state of the art, for instance, it is required for the server to process multichannel cameras in an unmanned supermarket in the retail sector, and a single equipment cannot satisfy the requirements – if all tasks are entirely concentrated on one equipment, the equipment would become overburdened, so it is absolutely necessary to employ a distributed system consisting of plural equipments, and the plural equipments are classified into master nodes and worker nodes, of which the worker nodes bear great quantities of algorithm tasks that are calculation- intensive tasks, but outputs of these algorithm tasks should be output in real time to the master nodes, so the algorithm tasks contain therein communication tasks, while the network IOs produced by these communication tasks would affect the efficiency of algorithm operations, and make it impossible for the entire distributed system to respond to outputs in real time.
[0056] In view of this, embodiments of the present invention provide a real-time communicating method within a distributed system, the distributed system includes a master node and worker nodes, on each of which worker node are deployed an algorithm task unit and a communication task unit, of which the communication task unit is employed for real-time transmission of data of network IOs (namely for executing communication tasks), and the algorithm task unit is employed for executing a calculation task initiated by the master node and writing the calculation result of the calculation task in a shared memory, whereupon the communication task unit reads the calculation result of the calculation task from the shared memory, and returns the result to the master node. In the embodiments of the present invention, communication tasks and calculation tasks are separated from each other by deploying an algorithm task unit and a communication task unit on multi- core nodes in a distributed environment, whereby it is not only guaranteed that calculation threads in calculation-intensive tasks are not frequently interrupted by too much network IOs, but also guaranteed that network IOs transmit data in real time, so that it is made possible for the distributed system to communicate in real time to ensure real-time output of algorithms. In addition, the use of a shared memory between the communication task and the calculation task for communication makes it possible to greatly enhance the efficiency of inter-process communication.
[0057] In one embodiment, as shown in Fig. 1, there is provided a real-time communicating method within a distributed system, the distributed system includes a master node and a worker node, on the worker node are deployed an algorithm task unit and a communication task unit, and the method can comprise the following steps.
[0058] S11 - the communication task unit performing an initialization operation after the communication task unit has been started, and entering a monitor state after having completed the initialization operation, wherein the initialization operation includes initializing a shared memory and a network connection.
[0059] Specifically, the communication task unit is started on the worker node, the communication task unit starts to perform the initialization operation that includes initializing a network connection and a shared memory, after initialization has been completed, the communication task unit enters a monitor state to monitor the shared memory and the network connection, respectively.
[0060] The shared memory is mainly employed for the communication between the communication task unit and the algorithm task unit on the same and single worker node, and the network connection is mainly employed for the communication between the worker node and the master node.
[0061] As should be noted, since the shared memory would not disappear with the disappearance of the process, before the algorithm task unit of the worker node is started, it is better to clean the region of a previously created shared memory, during actual application, it is possible to perform a cleaning operation after the communication task unit has been started and before the shared memory is initialized.
[0062] S12 - the algorithm task unit being started after the communication task unit has entered the monitor state, and processing a calculation task initiated by the master node after the algorithm task unit has been started.
[0063] In this embodiment, there is a strict demand on the orders to start the communication task unit and the algorithm task unit, as the communication task unit must be started before the algorithm task unit is started.
[0064] In this embodiment, the master node initiates a calculation task to each worker node, and the algorithm task unit on the worker node performs a corresponding algorithm processing on the calculation task initiated by the master node after the algorithm task unit has been started.
[0065] In actual application, the master node can base on the operating state information of various worker nodes to determine a worker node that processes the calculation task, and sends the calculation task to this worker node. The operating state information includes one or more of CPU utilization rate, memory utilization rate, magnetic disk reading / writing and network uplink and downlink.
[0066] S13 - the algorithm task unit writing a calculation result of the calculation task in the shared memory.
[0067] Specifically, the algorithm task unit can write the calculation result of the calculation task according to a preset data structure in the shared memory.
[0068] S14 - the communication task unit reading the calculation result when the communication task unit monitors that the calculation result is stored in the shared memory.
[0069] Specifically, the communication task unit can read the data in the shared memory periodically or in real time, and starts to obtain the calculation result when it reads the calculation result of the calculation task stored in the shared memory.
[0070] S15 - the communication task unit returning the calculation result to the master node through the network connection.
[0071] Specifically, the communication task unit can proactively return the calculation result of the calculation task to the master node through the network connection, and can also base on a calculation result request of the master node to return the calculation result of the calculation task to the master node through the network connection after the network connection between the master node and the communication task unit on the worker node has been created.
[0072] As should be noted, the worker node in the distributed system in this embodiment must be multi-core; with respect to a single-core CPU machine, the total computational resources thereof are limited, it is therefore not necessary to separate the algorithm task unit from the communication task unit, so such case is not discussed in this embodiment.
[0073] The embodiments of the present invention provide a real-time communicating method within a distributed system, the distributed system includes a master node and worker nodes, on each of which worker node are deployed an algorithm task unit and a communication task unit, of which the communication task unit is employed for real-time transmission of data of network IOs, and the algorithm task unit is employed for executing a calculation task initiated by the master node and writing the calculation result of the calculation task in a shared memory, whereupon the communication task unit reads the calculation result of the calculation task from the shared memory, and returns the result to the master node. In the embodiments of the present invention, communication tasks and calculation tasks are separated from each other by deploying an algorithm task unit and a communication task unit on multi-core nodes in a distributed environment, whereby it is not only guaranteed that calculation threads in calculation-intensive tasks are not frequently interrupted by too much network IOs, but also guaranteed that network IOs transmit data in real time, so that it is made possible for the distributed system to communicate in real time to ensure real-time output of algorithms. In addition, the use of a shared memory between the communication task and the calculation task for communication makes it possible to greatly enhance the efficiency of inter-process communication.
[0074] In one embodiment, the aforementioned step S12 of the algorithm task unit being started after the communication task unit has entered the monitor state can specifically include:
[0075] notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state, so as to make the algorithm task unit started.
[0076] Specifically, after the communication task unit has completed initialization of the shared memory, it monitors the region of the shared memory, and the communication task unit and the algorithm task unit notify each other via a condition lock. The condition lock is also inter-process, so after the communication task unit has initialized the condition lock, the shared memory will be locked, thereafter the communication task unit monitors the condition lock, and releases the condition lock during the monitoring. After the algorithm task unit has been started, the condition lock should also be locked, if there is no any other process to release the condition lock, the algorithm task unit will not be started, and it is therefore required to firstly start the communication task unit before the algorithm task unit is started.
[0077] In one embodiment, in order to make more general the messages transmitted between the various tasks, the aforementioned step S13 of the algorithm task unit writing a calculation result of the calculation task in the shared memory can specifically include:
[0078] the algorithm task unit serializing the calculation result of the calculation task to obtain serialized data, and writing the serialized data in the shared memory.
[0079] Specifically, serializing the calculation result by the algorithm task unit is to transform the calculation result to an object with a preset data structure, this object is the serialized data, and the preset data structure is for example JSON data structure. After the serialized data has been obtained, the serialized data can be written in the shared memory in the form of a key-value pair, in which key stands for key name, and value stands for key value.
[0080] Correspondingly, step S14 of the communication task unit reading the calculation result when the communication task unit monitors that the calculation result is stored in the shared memory can specifically include:
[0081] the communication task unit obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data of the calculation result is stored in the shared memory, and descrializing the serialized data to obtain the calculation result.
[0082] In this embodiment, the transmitted object is made more general by serializing the object for inter-process communication, and message transmission efficiency is enhanced.
[0083] In one embodiment, on the basis of the aforementioned method embodiment, the initialization operation further includes creating a message queue, and the method can further comprise, prior to step S15:
[0084] the communication task unit adding the calculation result to the message queue.
[0085] Different types of message queues can be created in the initialization operation of the communication task unit, and the different types of message queues are employed to store calculation results of different types of calculation tasks, for instance, a first message queue is employed to store a calculation result of an image processing task, a second message queue is employed to store a calculation result of a video processing task, and so on.
[0086] Specifically, the communication task unit adds the calculation result of the calculation task to a message queue to which the type of the calculation task corresponds.
[0087] Correspondingly, step S15 can specifically include:
[0088] the communication task unit extracting the calculation result from the message queue if the communication task unit receives a calculation result request initiated from the master node, and returning the calculation result to the master node through the network connection.
[0089] Specifically speaking, the specific process for realizing step S15 can include the following steps:
[0090] S151 - the communication task unit enquiring, if it receives a calculation result request initiated from the master node, in the message queue whether there is any calculation result requested by the calculation result request, if yes, executing step S152, if not, executing step S153.
[0091] S152 – returning the calculation result to the master node.
[0092] Specifically, the communication task unit returns the calculation result requested by the calculation result request to the master node through the network connection.
[0093] S153 - obstructing the calculation result request, and waking up the calculation result request when there is a new calculation result in the message queue, and executing step S154 after step S153.
[0094] S154 – judging whether the new calculation result is the calculation result requested by the calculation result request, if yes, returning the new calculation result to the master node, if not, returning to execute step $153.
[0095] In this embodiment, calculation results of all calculation tasks initiated by the master node are temporarily stored on the worker node, and the worker node sends the calculation result to the master node only when a certain calculation result is required by the master node, thusly, memory load on the master node can be reduced by sharing the memory required for storing the calculation results of the calculation tasks by means of the worker node.
[0096] In one embodiment, as shown in Fig. 2, there is provided a real-time communicating device within a distributed system, the distributed system includes a master node and a worker node, the device is located on the worker node, and the device comprises an algorithm task unit and a communication task unit, wherein:
[0097] the communication task unit 21 is employed for performing an initialization operation after the communication task unit 21 has been started, and entering a monitor state after having completed the initialization operation, wherein the initialization operation includes initializing a shared memory and a network connection;
[0098] the algorithm task unit 22 is employed for being started after the communication task unit 21 has entered the monitor state, and processing a calculation task initiated by the master node after the algorithm task unit 22 has been started;
[0099] the algorithm task unit 22 is further employed for writing a calculation result of the calculation task in the shared memory; and
[0100] the communication task unit 21 is further employed for reading the calculation result when the communication task unit 21 monitors that the calculation result is stored in the shared memory, and returning the calculation result to the master node through the network connection.
[0101] Further, the communication task unit 21 is specifically employed for:
[0102] notifying the algorithm task unit 22 through a condition lock when the communication task unit 21 enters the monitor state, so as to make the algorithm task unit started.
[0103] Further, the algorithm task unit 22 is specifically employed for:
[0104] serializing the calculation result of the calculation task to obtain serialized data, and writing the serialized data in the shared memory; and
[0105] the communication task unit 21 is specifically employed for:
[0106] obtaining the serialized data from the shared memory when the communication task unit 21 monitors that the serialized data of the calculation result is stored in the shared memory, and deserializing the serialized data to obtain the calculation result.
[0107] Further, the initialization operation further includes creating a message queue, and the communication task unit 21 is further employed for:
[0108] adding the calculation result to the message queue; and
[0109] extracting the calculation result from the message queue if a calculation result request initiated from the master node is received, and returning the calculation result to the master node through the network connection.
[0110] Further, the communication task unit 21 is specifically employed for:
[0111] enquiring, if it receives a calculation result request initiated from the master node, in the message queue whether there is any calculation result requested by the calculation result request;
[0112] if yes, returning the calculation result to the master node;
[0113] if not, obstructing the calculation result request, and waking up the calculation result request when there is a new calculation result in the message queue; and
[0114] judging whether the new calculation result is the calculation result requested by the calculation result request, if yes, returning the new calculation result to the master node, if not, continuing to obstruct the calculation result request.
[0115] The real-time communicating device within a distributed system provided by the embodiment of the present invention pertains to the same inventive conception as the real-time communicating method within a distributed system provided by an embodiment of the present invention, can execute the real-time communicating method within a distributed system provided by an embodiment of the present invention, possesses corresponding functional modules to execute the real-time communicating method within a distributed system, and achieves advantageous effects. Technical details not comprehensively described in this embodiment can be inferred from the real-time communicating method within a distributed system provided by an embodiment of the present invention, and are not redundantly described in this context.
[0116] In one embodiment, as shown in Fig. 3, there is provided a distributed system, the system comprises a master node 31 and a worker node 32 configured to include a real-time communicating device within a distributed system according to the aforementioned embodiment.
[0117] In addition, an embodiment of the present invention further provides a computer equipment that comprises a memory, a processor and a computer program stored on the memory and operable on the processor, and the steps of the real-time communicating method within a distributed system according to the aforementioned embodiment is realized when the processor executes the computer program.
[0118] In addition, an embodiment of the present invention further provides a computer-readable storage medium storing a computer program thereon, and the steps of the real-time communicating method within a distributed system according to the aforementioned embodiment is realized when the computer program is executed by a processor.
[0119] As should be clear to persons skilled in the art, the embodiment of the present invention can be embodied as a method, a system or a computer program product. Accordingly, in the embodiments of the present invention can be employed the form of complete hardware embodiment, complete software embodiment, or embodiment combining software with hardware. Moreover, in the embodiments of the present invention can be employed the form of one or more computer program product(s) implemented on a computer available storage medium (including, but not limited to, a magnetic disk memory, a CD-ROM, an optical memory, etc.) containing computer available program codes.
[0120] The embodiments of the present invention are described with reference to flowcharts and / or block diagrams of the embodied method, device (system), and computer program product in the embodiments of the present invention. As should be understood, it is possible for computer program instructions to realize each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams. These computer program instructions can be supplied to a general computer, a dedicated computer, an embedded processor or the processor of any other programmable data processing device to generate a machine enabling the instructions executed by the computer or the processor of any other programmable data processing device to generate a device for realizing the functions specified in one or more flow(s) of the flowcharts and / or one or more block(s) of the block diagrams.
[0121] These computer program instructions can also be stored in a computer-readable memory capable of guiding a computer or any other programmable data processing device to operate in specific modes enabling the instructions stored in the computer-readable memory to generate a product containing instructing means that realizes the functions specified in one or more flow(s) of the flowcharts and / or one or more block(s) of the block diagrams.
[0122] These computer program instructions can also be loaded to a computer or any other programmable data processing device, enabling to execute a series of operational steps on the computer or the any other programmable device to generate computer-realized processing, so that the instructions executed on the computer or the any other programmable device supply steps for realizing the functions specified in one or more flow(s) of the flowcharts and / or one or more block(s) of the block diagrams.
[0123] Although preferred embodiments in the embodiments of the present invention have been described, it is still possible for persons skilled in the art to make additional modifications and amendments to these embodiments upon learning the basic inventive concept. Accordingly, the attached Claims are meant to subsume the preferred embodiments and all modifications and amendments that fall within the scope of the embodiments of the present invention.
[0124] Apparently, it is possible for persons skilled in the art to make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thusly, should such modifications and variations to the present invention fall within the range of the Claims and equivalent technology of the present invention, the present invention is also meant to cover such modifications and variations.
Claims
2. The device of claim 1, wherein the device is a multi-core worker node, and wherein each of the algorithm task unit and communication task unit are located on different cores of the multi- core worker node.
3. The device of any one of claims 1 to 2, wherein the master node and the worker node communicate via the network connection.
4. The device of any one of claims 1 to 3, wherein the algorithm task unit writes the result of the calculation into the shared memory according to a preset data structure in the shared memory.
5. The device of any one of claims 1 to 4, wherein the communication task unit reads data in the shared memory periodically.
6. The device of any one of claims 1 to 4, wherein the communication task unit reads data in the shared memory in real time.
7. The device of any one of claims 1 to 6, wherein the communication task unit obtains the result of the calculation when reading the result of the calculation as stored in the shared memory.
8. The device of claim 3, wherein the communication task unit returns the result of the calculation to the master node through the network connection without receiving the calculation result request.
9. The device of claim 3, wherein the communication task unit returns the result of the calculation to the master node based on the calculation result request of the master node received through the network connection.
10. The device of any one of claims 1 to 9, wherein the communication task unit reading the result of the calculation from the shared memory comprises the communication task unit obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data is stored in the shared memory and deserializing the serialized data to obtain the result.
11. The device of claim 10, wherein the algorithm task unit serializing the result of the calculation comprises the algorithm task unit transforming the result into an object with a preset data structure, and wherein the algorithm task unit writing the serialized data in the shared memory comprises the algorithm task unit writing the serialized data in the shared memory in the form of a key-value pair.
12. The device of claim 11, wherein the preset data structure is a JSON data structure.
13. The device of any one of claims 1 to 12, wherein the communication task unit initializing the shared memory and the network connection further comprises creating a message queue and adding the result of the calculation to the message queue.
14. The device of claim 13, wherein multiple message queues are created.
15. The device of claim 14, wherein each message queue is configured to store any one of a result of a calculation pertaining to an image processing task and a result of a calculation pertaining to a video processing task.
16. The device of claim 15, wherein the communication task unit adds the result of the calculation pertaining to each task to the message queue corresponding to a type of the task.
17. The device of any one of claims 13 to 16, wherein the communication task unit extracts the result from the message queue if the communication task unit receives the calculation result request from the master node.
18. The device of claim 17wherein the result of the calculation is temporarily stored on the worker node, and the communication task unit enquires, if receiving the calculation result request from the master node, in the message queue whether there is any result of a calculation as requested by the calculation result request, if so returning the result of the calculation to the master node, and if not, blocking the calculation result request and calling the calculation result request when there is a new calculation result request in the message queue, and judging whether the new result of the calculation is the result of the calculation as requested by the calculation result request, and if so, returning the new result of the calculation to the master node, and if not, continuing to block the calculation result request.
19. A device for real-time communication in a distributed system, the system comprising: a shared memory specific to the device for storing a result of a calculation; and a processor for calculating the result, the processor comprising: an algorithm task unit for performing the calculation a communication task unit for providing real-time transmission of the result of the calculation a memory comprising a computer program stored on the memory and operable on the processor, wherein when the program is executed on the processor, the algorithm task unit performs the calculation and writes the result of the calculation into the shared memory by serializing the result to obtain serialized data and writing the serialized data in the shared memory and the communication task unit reads the result from the shared memory, wherein a master node selects a worker node to perform the calculation according to any one or more of CPU utilization rate, memory utilization rate, magnetic disk reading or writing, network uplink, and network downlink and sends the calculation to the worker node, wherein after initializing the shared memory, the communication task unit and the algorithm task unit notify each other via a condition lock, wherein the condition lock locks the shared memory until the communication task unit releases the condition lock during monitoring, and wherein performing the calculation further comprises the communication task unit notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state so as to start the algorithm task unit.
20. The device of claim 19, wherein the device is a multi-core worker node, and wherein each of the algorithm task unit and communication task unit are located on different cores of the multi- core worker node.
21. The device of claim 20, wherein the master node and the worker node communicate via the network connection.
22. The device of any one of claims 19 to 21, wherein the algorithm task unit writes the result of the calculation into the shared memory according to a preset data structure in the shared memory.
23. The device of any one of claims 19 to 22, wherein the communication task unit reads data in the shared memory periodically.
24. The device of any one of claims 19 to 22, wherein the communication task unit reads data in the shared memory in real time.
25. The device of any one of claims 19 to 24, wherein the communication task unit obtains the result of the calculation when reading the result of the calculation as stored in the shared memory.
26. The device of claim 21, wherein the communication task unit returns the result of the calculation to the master node through the network connection without receiving the calculation result request.
27. The device of claim 21, wherein the communication task unit returns the result of the calculation to the master node based on the calculation result request of the master node received through the network connection.
28. The device of any one of claims 19 to 27, wherein the communication task unit reading the result of the calculation from the shared memory comprises the communication task unit obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data is stored in the shared memory and describilizing the serialized data to obtain the result.
29. The device of claim 28, wherein the algorithm task unit serializing the result of the calculation comprises the algorithm task unit transforming the result into an object with a preset data structure, and wherein the algorithm task unit writing the serialized data in the shared memory comprises the algorithm task unit writing the serialized data in the shared memory in the form of a key-value pair.
30. The device of claim 29, wherein the preset data structure is a JSON data structure.
31. The device of any one of claims 19to 30, wherein the communication task unit initializing the shared memory and the network connection further comprises creating a message queue and adding the result of the calculation to the message queue.
32. The device of claim 31, wherein multiple message queues are created.
33. The device of claim 32, wherein each message queue is configured to store any one of a result of a calculation pertaining to an image processing task and a result of a calculation pertaining to a video processing task.
34. The device of claim 33, wherein the communication task unit adds the result of the calculation pertaining to each task to the message queue corresponding to a type of the task.
35. The device of any one of claims 31to 34, wherein the communication task unit extracts the result from the message queue if the communication task unit receives the calculation result request from the master node.
36. The device of claim 35wherein the result of the calculation is temporarily stored on the worker node, and the communication task unit enquires, if receiving the calculation result request from the master node, in the message queue whether there is any result of a calculation as requested by the calculation result request, if so returning the result of the calculation to the master node, and if not, blocking the calculation result request and calling the calculation result request when there is a new calculation result request in the message queue, and judging whether the new result of the calculation is the result of the calculation as requested by the calculation result request, and if so, returning the new result of the calculation to the master node, and if not, continuing to block the calculation result request.
37. A distributed system for real-time communication, the system comprising: a master node for initiating a calculation via a calculation result request and outputting a result of a calculation; a multi-core worker node for performing the calculation to yield the result, the worker node comprising: an algorithm task unit for performing the calculation when requested by the master node and writing the result of the calculation into a shared memory specific to the multi-core worker node by serializing the result to obtain serialized data and writing the serialized data in the shared memory; and a communication task unit for initializing the shared memory and a network connection, entering a monitor state of monitoring the shared memory and the network connection, and providing real-time transmission of the result of the calculation to the master node via the network connection by reading the result of the calculation from the shared memory; wherein the master node selects the multi-core worker node to perform the calculation according to any one or more of CPU utilization rate, memory utilization rate, magnetic disk reading or writing, network uplink, and network downlink and sends the calculation to the worker node, wherein after initializing the shared memory, the communication task unit and the algorithm task unit notify each other via a condition lock, wherein the condition lock locks the shared memory until the communication task unit releases the condition lock during the monitoring, and wherein performing the calculation when requested by the master node further comprises the communication task unit notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state so as to start the algorithm task unit.
38. The distributed system of claim 37, wherein each of the algorithm task unit and communication task unit are located on different cores of the multi-core worker node.
39. The distributed system of any one of claims 37 to 38, wherein the master node and the worker node communicate via the network connection.
40. The distributed system of any one of claims 37 to 39, wherein the algorithm task unit writes the result of the calculation into the shared memory according to a preset data structure in the shared memory.
41. The distributed system of any one of claims 37 to 40, wherein the communication task unit reads data in the shared memory periodically.
42. The distributed system of any one of claims 37 to 40, wherein the communication task unit reads data in the shared memory in real time.
43. The distributed system of any one of claims 37 to 42wherein the communication task unit obtains the result of the calculation when reading the result of the calculation as stored in the shared memory.
44. The distributed system of claim 39, wherein the communication task unit returns the result of the calculation to the master node through the network connection without receiving the calculation result request.
45. The distributed system of claim 39, wherein the communication task unit returns the result of the calculation to the master node based on the calculation result request of the master node received through the network connection.
46. The distributed system of any one of claims 37 to 45, wherein the communication task unit reading the result of the calculation from the shared memory comprises the communication task unit obtaining the serialized data from the shared memory when the communication task unit monitors that the serialized data is stored in the shared memory and deserializing the serialized data to obtain the result.
47. The distributed system of claim 46, wherein the algorithm task unit serializing the result of the calculation comprises the algorithm task unit transforming the result into an object with a preset data structure, and wherein the algorithm task unit writing the serialized data in the shared memory comprises the algorithm task unit writing the serialized data in the shared memory in the form of a key-value pair.
48. The distributed system of claim 47, wherein the preset data structure is a JSON data structure.
49. The distributed system of any one of claims 37 to 48, wherein the communication task unit initializing the shared memory and the network connection further comprises creating a message queue and adding the result of the calculation to the message queue.
50. The distributed system of claim 49, wherein multiple message queues are created.
51. The distributed system of claim 50, wherein each message queue is configured to store any one of a result of a calculation pertaining to an image processing task and a result of a calculation pertaining to a video processing task.
52. The distributed system of claim 51, wherein the communication task unit adds the result of the calculation pertaining to each task to the message queue corresponding to a type of the task.
53. The distributed system of any one of claims 49 to 52, wherein the communication task unit extracts the result from the message queue if the communication task unit receives the calculation result request from the master node.
54. The distributed system of claim 53 wherein the result of the calculation is temporarily stored on the worker node, and the communication task unit enquires, if receiving the calculation result request from the master node, in the message queue whether there is any result of a calculation as requested by the calculation result request, if so returning the result of the calculation to the master node, and if not, blocking the calculation result request and calling the calculation result request when there is a new calculation result request in the message queue, and judging whether the new result of the calculation is the result of the calculation as requested by the calculation result request, and if so, returning the new result of the calculation to the master node, and if not, continuing to block the calculation result request.
55. A real-time communicating method within a distributed system comprising a master node and a multi-core worker node, the worker node comprising an algorithm task unit and a communication task unit, the method comprising: performing an initialization operation after the communication task unit has been started, the initialization operation comprising initializing a shared memory specific to the worker node and a network connection; entering a monitor state for monitoring the shared memory and the network connection; processing a calculation task initiated by the master node; writing a calculation result of the calculation task in the shared memory by serializing the result to obtain serialized data and writing the serialized data in the shared memory; reading the calculation result when monitoring that the calculation result is stored in the shared memory; and returning the calculation result to the master node through the network connection; wherein the master node selects the worker node to perform the calculation according to any one or more of CPU utilization rate, memory utilization rate, magnetic disk reading or writing, network uplink, and network downlink and sends the calculation to the worker node, wherein after initializing the shared memory, the communication task unit and the algorithm task unit notify each other via a condition lock, wherein the condition lock locks the shared memory until the communication task unit releases the condition lock during the monitoring, and wherein performing the calculation when requested by the master node further comprises the communication task unit notifying the algorithm task unit through a condition lock when the communication task unit enters the monitor state so as to start the algorithm task unit.
56. The method of claim 55, wherein processing a calculation task initiated by the master node and writing a calculation result of the calculation task in the shared memory is performed by the algorithm task unit in a first core of the multi-core worker node, and reading the calculation result when monitoring that the calculation result is stored in the shared memory and returning the calculation result to the master node through the network connection is performed by the communication task unit in a second core of the multi-core worker node.
57. The method of any one of claims 55 to 56, wherein the master node and the worker node communicate via the network connection.
58. The method of any one of claims 55 to 57, wherein writing the result of the calculation into the shared memory occurs according to a preset data structure in the shared memory.
59. The method of any one of claims 55 to 58, wherein reading data in the shared memory occurs periodically.
60. The method of any one of claims 55 to 58, wherein reading data in the shared memory occurs in real time.
61. The method of any one of claims 55 to 60, wherein obtaining the result of the calculation occurs when reading the result of the calculation as stored in the shared memory.
62. The method of claim 57, wherein returning the result of the calculation to the master node through the network connection occurs without the calculation result request of the master node.
63. The method of claim 57, wherein returning the result of the calculation to the master node occurs based on the calculation result request of the master node received through the network connection.
64. The method of any one of claims 55 to 63, wherein reading the result of the calculation from the shared memory comprises obtaining the serialized data from the shared memory when monitoring that the serialized data is stored in the shared memory and deserializing the serialized data to obtain the result.
65. The method of claim 64, wherein serializing the result of the calculation comprises transforming the result into an object with a preset data structure, and wherein writing the serialized data in the shared memory comprises writing the serialized data in the shared memory in the form of a key-value pair.
66. The method of claim 65, wherein the preset data structure is a JSON data structure.
67. The method of any one of claims 55 to 66, wherein initializing the shared memory and the network connection further comprises creating a message queue and adding the result of the calculation to the message queue.
68. The method of claim 67, wherein multiple message queues are created.
69. The method of claim 68, wherein each message queue is configured to store any one of a result of a calculation pertaining to an image processing task and a result of a calculation pertaining to a video processing task.
70. The method of claim 69, further comprising adding the result of the calculation pertaining to each task to the message queue corresponding to a type of the task.
71. The method of any one of claims 67 to 70, further comprising extracting the result from the message queue when receiving the calculation result request from the master node.
72. The method of claim 71, further comprising temporarily storing the result of the calculation on the worker node, and enquiring, if receiving the calculation result request from the master node, in the message queue whether there is any result of a calculation as requested by the calculation result request, if so returning the result of the calculation to the master node, and if not, blocking the calculation result request and calling the calculation result request when there is a new calculation result request in the message queue, and judging whether the new result of the calculation is the result of the calculation as requested by the calculation result request, and if so, returning the new result of the calculation to the master node, and if not, continuing to block the calculation result request.
73. A device for real-time communication within a distributed system comprising a master node and a multi-core worker node, the worker node comprising an algorithm task unit and a communication task unit, the device comprising: a processor; and a memory, associated with the processor, wherein the memory is used to store a program instruction, and the program instruction performs the following operations when it is read and executed by the processor: performing an initialization operation after the communication task unit has been started, the initialization operation comprising initializing a shared memory specific to the worker node and a network connection, wherein after initializing the shared memory, the communication task unit and the algorithm task unit notify each other via a condition lock, wherein a condition lock locks the shared memory until the communication task unit releases the condition lock; entering a monitor state for monitoring the shared memory and the network connection, wherein the communication task unit releases the condition lock during the monitoring; processing a calculation task initiated by the master node, wherein processing the calculation task further comprises the communication task unit notifying the algorithm task unit through the condition lock when the communication task unit enters the monitor state so as to start the algorithm task unit, and wherein the master node selects the worker node to perform the calculation according to any one or more of CPU utilization rate, memory utilization rate, magnetic disk reading or writing, network uplink, and network downlink and sends the calculation task to the worker node; writing a calculation result of the calculation task in the shared memory serializing the result to obtain serialized data and writing the serialized data in the shared memory; reading the calculation result when monitoring that the calculation result is stored in the shared memory; and returning the calculation result to the master node through the network connection.
74. The device of claim 73, wherein processing a calculation task initiated by the master node and writing a calculation result of the calculation task in the shared memory is performed by the algorithm task unit in a first core of the multi-core worker node, and reading the calculation result when monitoring that the calculation result is stored in the shared memory and returning the calculation result to the master node through the network connection is performed by the communication task unit in a second core of the multi-core worker node.
75. The device of any one of claims 73 to 74, wherein the master node and the worker node communicate via the network connection.
76. The device of any one of claims 73 to 75, wherein writing the result of the calculation into the shared memory occurs according to a preset data structure in the shared memory.
77. The device of any one of claims 73 to 76, wherein reading data in the shared memory occurs periodically.
78. The device of any one of claims 73 to 76, wherein reading data in the shared memory occurs in real time.
79. The device of any one of claims 73 to 78, wherein obtaining the result of the calculation occurs when reading the result of the calculation as stored in the shared memory.
80. The device of claim 75, wherein returning the result of the calculation to the master node through the network connection occurs without the calculation result request of the master node.
81. The device of claim 75, wherein returning the result of the calculation to the master node occurs based on the calculation result request of the master node received through the network connection.
82. The device of any one of claims 73 to 81, wherein reading the result of the calculation from the shared memory comprises obtaining the serialized data from the shared memory when monitoring that the serialized data is stored in the shared memory and deserializing the serialized data to obtain the result.
83. The device of claim 82, wherein serializing the result of the calculation comprises transforming the result into an object with a preset data structure, and wherein writing the serialized data in the shared memory comprises writing the serialized data in the shared memory in the form of a key-value pair.
84. The device of claim 83, wherein the preset data structure is a JSON data structure.
85. The device of any one of claims 73 to 84, wherein initializing the shared memory and the network connection further comprises creating a message queue and adding the result of the calculation to the message queue.
86. The device of claim 85, wherein multiple message queues are created.
87. The device of claim 86, wherein each message queue is configured to store any one of a result of a calculation pertaining to an image processing task and a result of a calculation pertaining to a video processing task.
88. The device of claim 87, further comprising adding the result of the calculation pertaining to each task to the message queue corresponding to a type of the task.
89. The device of any one of claims 85to 88, further comprising extracting the result from the message queue when receiving the calculation result request from the master node.
90. The device of claim 89, further comprising temporarily storing the result of the calculation on the worker node, and enquiring, if receiving the calculation result request from the master node, in the message queue whether there is any result of a calculation as requested by the calculation result request, if so returning the result of the calculation to the master node, and if not, blocking the calculation result request and calling the calculation result request when there is a new calculation result request in the message queue, and judging whether the new result of the calculation is the result of the calculation as requested by the calculation result request, and if so, returning the new result of the calculation to the master node, and if not, continuing to block the calculation result request.