Message processing method and device
By employing an interval-based message queue discarding strategy in the real-time control system, the problem of queue congestion caused by network jitter and untimely processing was solved, achieving continuity of controlled end actions and real-time control accuracy, and reducing the risk of system anomalies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CORE MOTION MEDICAL ROBOT (SHENZHEN) CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-17
AI Technical Summary
In real-time control systems, message queues at the controlled end become congested due to network latency jitter and untimely processing, leading to message tails being dropped and affecting the system's real-time control performance.
The message queue is processed using an interval discarding strategy. By discarding some control commands and retaining valid commands between adjacent commands, the continuity of the controlled end's actions is ensured. This includes discarding mapping rules and random discarding strategies. The congestion flag is updated according to the queue depth to adapt to different congestion states.
This avoids queue function failure, ensures the continuity of controlled actions and real-time control accuracy, and reduces the risk of system anomalies.
Smart Images

Figure CN121887741A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of medical device control technology, and in particular to a message processing method and apparatus. Background Technology
[0002] Real-time control systems typically use message queues to buffer control commands. The controller generates real-time control commands and places them in the message queue. The controlled end retrieves the control commands from the message queue for processing. The message queue serves to buffer and absorb latency jitter during the transmission of control commands, avoiding control problems caused by asynchrony between the controller and the controlled end.
[0003] In existing technologies, in order to ensure the latency performance of real-time control commands, the controlled end usually limits the length of the queue to a relatively small fixed value. However, when the network latency jitter is too large or the controlled end does not process in time, it may cause message queue congestion. If the messages accumulated in the queue reach the maximum queue depth (the queue is full), message tail dropping behavior will occur.
[0004] In real-time control systems, the controlled end processes messages at a fixed pace. Even if the queue is full, it cannot speed up message processing. As a result, the queue will continue to be congested and the tail will drop messages. The queue's function of buffering messages and absorbing latency jitter will fail. Continuous tail dropping will cause drastic jumps between adjacent messages that are actually being processed, which will seriously affect real-time control. Summary of the Invention
[0005] Therefore, it is necessary to provide a message processing method and apparatus to address the aforementioned technical problems, which can improve the real-time control performance of a real-time control system.
[0006] In a first aspect, this application provides a message processing method, which is applied to a controlled end in a real-time control system, comprising:
[0007] Obtain the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0008] When the congestion identifier is the first identifier, an interval discarding strategy is used to process instructions for the message queue. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0009] In one embodiment, when the congestion identifier is a first identifier, an interval-based discarding strategy is used to process instructions for the message queue, including:
[0010] If the first identifier is a first value, then the message queue is processed by the interval discarding strategy of the discarding mapping rule. The discarding mapping rule includes a first number of instruction processing cycles included in a discarding processing cycle, a second number of instruction processing cycles that need to discard control instructions in the first number, and a processing identifier of the first number of control instructions. The processing identifier is used to indicate whether the instruction processing cycle discards control instructions.
[0011] If the second identifier is the second value, then the message queue is processed by the interval discarding strategy of the candidate discarding strategy, wherein the candidate discarding strategy includes a discarding mapping rule and a random discarding strategy.
[0012] In one embodiment, the instruction processing of the message queue using the interval discarding strategy with discarding mapping rules includes:
[0013] Within the current discard processing cycle, for the first number of instruction processing cycles, the control instructions are processed according to the processing identifier of each control instruction within the first number of instruction processing cycles.
[0014] In one embodiment, instruction processing involves retrieving control instructions to be executed from the message queue, and processing the control instructions according to their processing identifiers within a first number of instruction processing cycles, including:
[0015] For each processing identifier, if the processing identifier indicates that the control instruction should be discarded, two control instructions are retrieved from the message queue within the current instruction processing cycle. The two control instructions include the target control instruction corresponding to the processing identifier, and the control instruction before or after the target control instruction.
[0016] The target control command is discarded, and another control command is responded to.
[0017] In one embodiment, the instruction processing involves writing received control instructions to the message queue, and the instruction processing of the control instructions according to the processing identifier of each control instruction in a first number of instruction processing cycles includes:
[0018] For each processing identifier, if the processing identifier indicates that the control command should be discarded, the control command corresponding to the processing identifier should be discarded.
[0019] If the processing identifier indicates that the control command should not be discarded, the control command corresponding to the processing identifier is added to the message queue.
[0020] In one embodiment, the instruction processing involves writing the received control instruction into the message queue. If the candidate discarding strategy is a random discarding strategy, then the message queue is processed using an interval discarding strategy of the candidate discarding strategy, including:
[0021] Obtain the reception identifier of the previous control command;
[0022] If the receive identifier of the previous control instruction indicates that the previous control instruction was discarded, then the current control instruction is added to the message queue, and the receive identifier of the current control instruction is set to an identifier indicating that it was written.
[0023] If the reception identifier of the previous control instruction indicates that the previous control instruction has been written, then the reception result of the current control instruction is determined according to a random algorithm, and the current control instruction is written or discarded according to the reception result, and the reception identifier of the current control instruction is set according to the reception result.
[0024] In one embodiment, the method further includes:
[0025] The congestion identifier is updated based on the queue depth of the message queue.
[0026] In one embodiment, updating the congestion identifier based on the queue depth of the message queue includes:
[0027] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to a second flag, wherein the second flag is used to characterize the message queue congestion elimination;
[0028] If the queue depth is greater than or equal to the congestion threshold, then the congestion flag is set to the first value;
[0029] If the queue depth is greater than the recovery threshold and less than the congestion threshold, then the congestion flag is set to the second value.
[0030] In one embodiment, updating the congestion identifier based on the queue depth of the message queue includes:
[0031] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to a second flag, wherein the second flag is used to characterize the message queue congestion elimination;
[0032] If the queue depth is greater than or equal to the congestion threshold, then the congestion flag is set to the first value;
[0033] If the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion identifier is the second identifier, then the congestion identifier is updated to the second identifier; if the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion identifier is the first value or the second value, then the congestion identifier is set to the second value.
[0034] Secondly, this application also provides a message processing apparatus, comprising:
[0035] The acquisition module is used to acquire the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0036] The processing module is configured to process instructions on the message queue using an interval discarding strategy when the congestion identifier is a first identifier. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0037] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0038] Obtain the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0039] When the congestion identifier is the first identifier, an interval discarding strategy is used to process instructions for the message queue. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0040] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0041] Obtain the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0042] When the congestion identifier is the first identifier, an interval discarding strategy is used to process instructions for the message queue. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0043] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0044] Obtain the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0045] When the congestion identifier is the first identifier, an interval discarding strategy is used to process instructions for the message queue. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0046] The aforementioned message processing method and apparatus obtain the congestion identifier of the message queue at the controlled end, wherein the message queue is used to cache control commands from the controlling end; when the congestion identifier is a first identifier, an interval discarding strategy is adopted to process commands on the message queue, wherein the first identifier is used to indicate that the message queue is in a congested state, and the interval discarding strategy includes discarding some control commands, and at least one undiscarded control command exists between two adjacent discarded control commands. This scheme retains valid commands through interval discarding, preventing queue function failure; and retains valid commands between adjacent discarded commands, ensuring continuous action at the controlled end, guaranteeing real-time control accuracy, and reducing the risk of system anomalies. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1A This is an application environment diagram of a message processing method in one embodiment;
[0049] Figure 1B This is an application environment diagram of the message processing method in another embodiment;
[0050] Figure 2 This is a flowchart illustrating a message processing method in one embodiment;
[0051] Figure 3 This is a schematic diagram of the recovery threshold and congestion threshold in one embodiment;
[0052] Figure 4 This is a structural block diagram of a message processing device in one embodiment;
[0053] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0055] The message processing method provided in this application embodiment can be applied to, for example, Figure 1A and Figure 1B The application environment shown.
[0056] Real-time control systems typically use message queues to cache control commands or messages. Message producers (controllers) generate real-time control messages and place them in the message queue. Message consumers (controlled devices) retrieve messages from the message queue for processing. The message queue serves to cache and absorb latency jitter during message transmission, avoiding control problems caused by asynchrony between message producers and consumers.
[0057] For example, a surgical robot is a typical real-time control system. A complete surgical robot system includes a main control console, a master hand, an operating table, a robotic arm (slave hand), and other related hardware. The master hand acts as the control end, while the robotic arm and instruments act as the controlled ends. The control end and the controlled ends belong to different hardware entities, which communicate with each other via a network to form a real-time control system. During surgery, the surgeon operates the master hand on the main control console, and the movements of the master hand are mapped in real time to the movements of the robotic arm and instruments, realizing the function of remote surgery (also known as teleoperation).
[0058] In this system, the control unit generates real-time control commands or messages at a fixed pace, such as one message every 1 millisecond (i.e., a message frequency of 1000Hz). The controlled unit, upon receiving the message, processes it at the same frequency as the control unit. Ideally, the control unit completes message generation, transmission, and processing at the same frequency, forming a perfect pipeline. However, in practical applications, due to the instability of the controlled unit, the control unit, and the communication network between them, both the control and controlled units use a message queue to buffer messages, primarily to absorb network latency fluctuations. Despite the latency caused by network transmission and the buffer queue, the overall system still appears to the outside world as a real-time control system.
[0059] In addition, such as Figure 1BAs shown, some real-time control systems are closed-loop real-time control systems with feedback data transmission and processing. Real-time control commands or messages are transmitted bidirectionally to ensure that control commands can be implemented and that the execution process can be monitored, corrected, and safely intervened in.
[0060] For motion control commands:
[0061] The doctor performs a "clamping with tweezers" operation through the main hand (control end - sending unit) → the main hand sensor collects the "target force 2.5N" and generates a control command → the command enters the control end message queue for buffering → the control command is retrieved from the control end message queue → the control end sending module sends the control command to the surgical platform (controlled end) via the network link.
[0062] The robot receiving module receives the "tweezers clamp" command → enters the controlled end message queue buffer (to absorb network jitter) → retrieves the control command from the controlled end message queue → executes the control command to control the motor to perform the clamping action.
[0063] Regarding force feedback data:
[0064] Force sensor (collects "actual clamping force 2N", generates feedback data → feedback data enters the controlled end message queue for caching → controlled end sending module packages "actual force of tweezers 2N" and transmits it back to the control end via network link).
[0065] The control terminal receiving module receives feedback data → enters the control terminal message queue buffer (to absorb reverse transmission jitter) → feeds it back to the master hand (control terminal - receiving unit) → the force feedback motor of the master hand simulates the resistance of "actual force 2N", the doctor feels "insufficient force", and then adjusts the operation of the master hand to generate a new instruction "tighten the forceps by 0.5N" → the new instruction will be sent to the surgical platform again through the forward network link.
[0066] Repeat the cycle of "send command → execute → provide feedback → call command" until the force of the tweezers precisely matches the surgical requirements.
[0067] In the above application scenarios, since the latency jitter of message transmission in the network is uncontrollable, the control end usually limits the length of the queue to a relatively small fixed value in order to ensure the real-time control of message latency performance. However, when the network latency jitter is too large or the message sending module does not process in time, it may cause message queue congestion. If the messages piled up in the queue reach the maximum queue depth (the queue is full), message tail dropping behavior will occur.
[0068] In real-time control systems, continuous message queue congestion and frequent, consecutive tail drops can cause the queue's message buffering and latency jitter absorption functions to fail, severely impacting the system's real-time performance. For surgical robots, continuous loss of real-time control messages can lead to a series of problems such as motion jitter, vibration, abnormal noise, and uncontrolled movement of the robotic arm.
[0069] In one exemplary embodiment, such as Figure 2 As shown, a message processing method is provided, which is applied to... Figure 1A and Figure 1B Taking the controlled end in the middle as an example, the following steps are included:
[0070] S201, obtain the congestion flag of the message queue on the controlled end.
[0071] In a real-time control system, the control end and the controlled end work synchronously at a fixed pace, and the transmission and processing of instructions must meet millisecond-level latency requirements. An example is a surgical robot system, where the main hand is the control end and the robotic arm is the controlled end. The controlled end is a device or module that receives and executes control commands sent by the control end, such as the robotic arm controller of a surgical robot.
[0072] Message queues are used to cache control commands from the control unit. For example, a memory queue based on a First-In, First-Out (FIFO) mechanism can have a maximum queue length equal to a preset maximum cache capacity (e.g., 10 commands). Control commands are instructions generated by the control unit to drive the controlled unit to perform specific actions, such as "move the robotic arm 1mm along the X-axis" or "clamp the instrument."
[0073] For example, the controlled processor can read the congestion flag stored in memory by calling the interface function of the queue management module (such as GetCongestionFlag). The queue management module synchronizes the queue depth and congestion flag every 1ms to ensure data real-time performance.
[0074] S202, when the congestion identifier is the first identifier, the message queue is processed according to the interval discarding strategy based on the congestion identifier.
[0075] The first identifier is used to identify that the message queue is in a congested state. The interval discarding policy includes discarding some control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0076] For example, when the congestion identifier is a first identifier, such as a first value "1" or a second value "2", the processor triggers interval discarding logic. For example, it executes the corresponding discarding rule according to the instruction processing scenario (enqueue or dequeue), so that at least one control instruction is not discarded between two discarded control instructions. For example, the message queue is processed using interval discarding logic of "discard-retain-discard" or "retain-discard-retain-discard".
[0077] The instruction processing includes at least one of writing received control instructions to the message queue and retrieving control instructions to be executed from the message queue.
[0078] In the above embodiments, valid instructions are discarded at intervals to avoid queue function failure; and valid instructions are retained between adjacent discarded instructions to ensure continuous action of the controlled end, guarantee real-time control accuracy, and reduce the risk of system anomalies.
[0079] In some optional implementations, if the first identifier is the first value, then the message queue is processed using an interval discarding strategy based on the discarding mapping rule. For example, if the congestion identifier is the first value "1", corresponding to "severe congestion", then the message queue is processed using an interval discarding strategy based on the discarding mapping rule.
[0080] The discard mapping rule includes a first number of instruction processing cycles within a discard processing cycle, a second number of instruction processing cycles from the first number that require discarding control instructions, and a processing identifier for the first number of control instructions. The processing identifier indicates whether the instruction processing cycle discards the control instructions. The first number is greater than the second number. For example, a discard mapping rule of <first number, second number, processing identifier sequence, such as <4, 1, [K, K, D, K]> (D = discard, K = keep), indicates that a discard processing cycle includes 4 instruction processing cycles, including 1 instruction processing cycle that requires discarding control instructions, executed in the order of "DKDK".
[0081] If the second identifier is the second value, then the message queue is processed using the interval discarding strategy of the candidate discarding policy. The candidate discarding policy includes a discard mapping rule and a random discarding policy. For example, if the congestion identifier is the second value "2", corresponding to "mild congestion", then either the discard mapping rule or the random discarding policy is used to process the message queue. The discard mapping rule is a fixed-interval discarding policy, and the random discarding policy is a probability-based discarding policy.
[0082] Based on this, the message queue is processed by an interval discarding strategy based on the discarding mapping rule. Within the current discarding processing cycle, for the first number of instruction processing cycles, the control instructions are processed according to the processing identifier of each control instruction within the first number of instruction processing cycles.
[0083] The discard processing cycle is the time window for executing a discard mapping rule once, including the processing cycles of each instruction in the first quantity. Each instruction processing cycle can be synchronized with the processing rhythm of the controlled end (e.g., 1ms / cycle) to ensure matching with the instruction processing frequency.
[0084] The processing identifier is a discard or retain flag corresponding to each instruction, such as "D" = discard, "K" = retain, assigned according to a preset sequence (e.g.,<D,K,D,K> ), stored in the discard mapping rule configuration table.
[0085] For example, the instruction processing cycle timer can be triggered according to the controlled end's processing tick (1ms). For instance, the first quantity (e.g., 4) corresponding to the current policy and the processing identifier sequence, such as [K, K, D, K], can be read from the configuration file. Then, control instructions are retrieved from the message queue one by one according to the processing identifier sequence and either discarded or retained.
[0086] In some optional implementations, if instruction processing involves retrieving control instructions to be executed from the message queue, and an interval discarding strategy based on discarding mapping rules is used to process instructions from the message queue, for each processing identifier, if the processing identifier indicates that the control instruction should be discarded, two control instructions can be retrieved from the message queue within the current instruction processing cycle. The two control instructions include the target control instruction corresponding to the processing identifier, and the control instruction preceding or following the target control instruction. The target control instruction is then discarded, and the other control instruction is responded to.
[0087] Among them, instruction processing (dequeue scenario) is the process by which the controlled end retrieves unexecuted instructions from the message queue and executes them, such as the robotic arm retrieving one instruction from the queue every 1ms and executing it.
[0088] The target control instruction is the instruction that indicates "discard" in the processing flag sequence. For example, in the processing flag sequence = [D, K], the instruction corresponding to flag D is the target instruction. The control instructions before or after the target control instruction refer to the instruction preceding or following the target instruction in the queue. For example, if the target instruction is the 3rd instruction in the queue, then the preceding instruction is the 2nd instruction, and the following instruction is the 4th instruction.
[0089] For example, the processing identifier sequence can be traversed to mark the target instruction marked with "D". The previous or next instruction can be obtained through the queue management module, and then the target instruction can be removed from the queue, not passed to the execution module, thus freeing up memory space; and the adjacent instruction can be passed to the controlled end execution module, such as the robotic arm drive module, to execute the corresponding action and return the execution result, such as "action completed".
[0090] In the surgical robot scenario, under mild congestion (congestion indicator is 2), the drop-out mapping rule is <4, 1, [K, K, D, K]>, that is, the first quantity is 4, the second quantity is 1, and the processing indicator sequence is [K, K, D, K].
[0091] The current discard processing cycle begins, and the processor retrieves instructions from the queue and executes them:
[0092] In the first instruction processing cycle, retrieve instruction A: "Robotic arm rotates 1°" → Processing flag = K → Reserve, and execute the instruction.
[0093] In the second instruction processing cycle, retrieve instruction B: "Robotic arm rotates 2°" → Processing flag = K → Keep, and execute the instruction.
[0094] In the third instruction processing cycle, retrieve instruction C and instruction D: Instruction C "Robot arm rotates 3°" → processing identifier = D → discard, do not execute; Instruction D "Robot arm rotates 4°" → processing identifier = K → retain, execute this instruction.
[0095] In the fourth instruction processing cycle, retrieve instruction E: "Robotic arm rotates 5°" → Processing flag = K → Keep, and execute the instruction.
[0096] Once this cycle is completed, control instructions are discarded within one instruction processing cycle and retained within three instruction processing cycles, with no consecutive discarding.
[0097] In the above embodiments, the processing cycle and the number of instructions are clearly defined, and a processing identifier sequence is preset to avoid continuous packet loss, ensure smooth operation, and solve the motion jitter problem caused by irregular packet loss in the prior art.
[0098] In some optional implementations, if the instruction processing involves writing the received control instruction to the message queue, and the message queue is processed using an interval discarding strategy based on the discard mapping rule, then for each processing identifier, if the processing identifier indicates that the control instruction should be discarded, the control instruction corresponding to the processing identifier can be discarded; and if the processing identifier indicates that the control instruction should not be discarded, the control instruction corresponding to the processing identifier can be added to the message queue.
[0099] Among them, instruction processing (enqueueing scenario) is the process by which the controlled end decides whether to write the instruction sent by the control end into the message queue after receiving it. It is a key step to avoid queue overflow. If the frequency of the control end sending instructions is higher than the frequency of the controlled end processing instructions, congestion can be alleviated by enqueuing and discarding instructions.
[0100] For example, the controlled end communication module (such as a gigabit Ethernet interface) listens on a network port (such as UDP port 5000). When it detects a command data packet sent by the control end, it parses the data packet (extracts the action type, parameters, and timestamp) and generates standardized control commands.
[0101] Then, the controlled terminal assigns a processing identifier to each instruction in the order of receipt, and takes values sequentially from the identifier sequence of the discard mapping rule. It then performs a discard operation or an add operation. For example, if the processing identifier is D, the memory occupied by the instruction is directly released without writing it to the queue; if it is K, the instruction is written to the message queue.
[0102] For example, in a surgical robot scenario, under mild congestion (congestion flag 2), the discard mapping rule is <3, 1, [K, D, K]>, that is, the first quantity is 3, the second quantity is 1, and the processing flag sequence is [K, D, K]), the instruction processing is enqueuing and writing.
[0103] Assume the controlled communication module receives three commands consecutively:
[0104] Instruction 1 (t=1ms): "Robotic arm rotates 5°" → Assign processing flag = K → Call Enqueue() to write to the queue.
[0105] Instruction 2 (t=2ms): "Robotic arm rotates 6°" → allocate processing flag = D → discard directly and release memory.
[0106] Instruction 3 (t=3ms): "Robotic arm rotates 7°" → Assign processing flag = K → Write to queue.
[0107] This cycle is complete: 1 record was discarded, 2 records were written, and there were no consecutive discards.
[0108] If the number of received instructions exceeds the first limit (e.g., 4 instructions):
[0109] Instruction 4 (t=4ms): "Robotic arm rotates 8°" → Retrieves value (K) from the head of the identifier sequence → Writes it to the queue.
[0110] In the above embodiments, some instructions are discarded in advance in the queuing scenario to avoid queue overflow from the source; and the instructions are discarded according to a preset identifier sequence, the rules are clear, and there will be no continuous queuing and discarding, ensuring that the instructions written to the queue are evenly distributed and guaranteeing the smoothness of subsequent execution.
[0111] In some optional implementations, if the first identifier is the second value and the candidate discarding strategy is the interval discarding strategy, the implementation process of processing instructions for the message queue using the interval discarding strategy is the same as the implementation process of processing instructions for the message queue using the interval discarding strategy with the first identifier as the first value and the discarding mapping rule, and will not be repeated here.
[0112] In some optional implementations, if the first identifier is the second value, i.e., under mild congestion, if the instruction processing involves writing the received control instruction to the message queue, and the candidate discarding strategy is a random discarding strategy, when processing the message queue using the interval discarding strategy of the candidate discarding strategy, the receiving identifier of the previous control instruction can be obtained; if the receiving identifier of the previous control instruction indicates that the previous control instruction was discarded, then the current control instruction is added to the message queue, and the receiving identifier of the current control instruction is set to the identifier indicating that it was written.
[0113] If the reception identifier of the previous control command indicates that the previous control command has been written, then the reception result of the current control command is determined according to a random algorithm, and the current control command is either written or discarded according to the reception result, and the reception identifier of the current control command is set according to the reception result.
[0114] The random drop strategy is one of the candidate strategies for mild congestion. It can achieve probabilistic packet loss of "discontinuous drop" based on a random algorithm and the previous instruction reception state. The reception identifier is a marker indicating whether an instruction has been written to the message queue, such as "W" = written, "N" = dropped, corresponding one-to-one with each instruction and stored in the instruction metadata. The random algorithm is used to generate probability values; this embodiment uses the MT19937 pseudo-random number generation algorithm, which can generate random numbers between 0 and 1. The reception result is the determination of whether the current instruction is "written to the queue" or "dropped," determined by the random number and a drop probability threshold. If the random number is less than or equal to the threshold, the instruction is written; otherwise, it is dropped.
[0115] For example, the processor can locate the previous instruction by its instruction sequence number (such as an incrementing integer ID) and read the receive identifier ("W" or "N") from its metadata. If it is the first instruction (without a parent instruction), the default previous identifier is "N" (forcing the first instruction to be written).
[0116] If the previous flag is "N" (discarded): Write the current instruction to the queue, set the current receive flag to "W", and increment the queue depth by 1. If the previous flag is "W" (written), calculate the discard probability threshold. For example, set the threshold as (current queue depth - recovery threshold) / (congestion threshold - recovery threshold). If the queue depth is 5, the recovery threshold is 3, and the congestion threshold is 8, then the threshold is (5-3) / (8-3) = 0.4.
[0117] Then, the MT19937 algorithm is invoked to generate a 0-1 random number (e.g., 0.3). The random number is compared with a threshold. If the random number is less than or equal to the threshold, the received result is determined to be written, the flag is set to "W", and the current control command is written to the queue. If the random number is greater than the threshold, the received result is determined to be discarded, the flag is set to "N", and the memory is released.
[0118] In the above embodiments, the random discard strategy retains more valid instructions during mild congestion, which improves control accuracy compared to fixed discard rules, such as the fine motion control of surgical robots.
[0119] In some optional implementations, the congestion flag can also be updated based on the message queue depth. The queue depth is the number of currently unprocessed control commands in the message queue; for example, if there are 6 unexecuted commands in the queue, the queue depth is 6.
[0120] For example, the value of the congestion flag can be modified based on the comparison results between the queue depth and the recovery threshold and congestion threshold.
[0121] For example, see Figure 3 , Figure 3 A schematic diagram of a recovery threshold and a congestion threshold is provided. The recovery threshold is less than the congestion threshold and greater than zero, the congestion threshold is less than or equal to the maximum queue length of the message queue, and the second identifier is used to characterize message queue congestion elimination.
[0122] For example, updating the congestion flag based on the message queue depth can be achieved in the following way. In this embodiment of the application, when setting the congestion flag, there is no need to consider the historical congestion flag.
[0123] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to the second flag, which is used to indicate that the message queue congestion has been eliminated; that is, it means that the message queue is not congested.
[0124] If the queue depth is greater than or equal to the congestion threshold, the congestion flag is set to the first value, indicating that the message queue is in a state of severe congestion. If the queue depth is greater than the recovery threshold but less than the congestion threshold, the congestion flag is set to the second value, indicating that the message queue is in a state of mild congestion.
[0125] In the above embodiments, the congestion states corresponding to different queue depths are clearly defined, so that the drop policy can be accurately adapted and the policy switching chaos can be avoided.
[0126] In some alternative implementations, updating the congestion flag based on the message queue depth can also be achieved in the following ways. In this embodiment, when setting the congestion flag, historical congestion flags need to be considered.
[0127] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to the second flag, which is used to indicate that the message queue congestion has been eliminated; that is, it means that the message queue is not congested.
[0128] If the queue depth is greater than or equal to the congestion threshold, the congestion flag is set to the first value, which means that the message queue is in a state of severe congestion.
[0129] If the queue depth is greater than the recovery threshold but less than the congestion threshold, and the congestion identifier is a second identifier, then the congestion identifier will be updated to the second identifier; that is, if the queue depth is not greater than the congestion threshold, even if the queue depth is greater than the recovery threshold, the message queue is considered not to be in a congested state.
[0130] If the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion flag is either the first or the second value, then the congestion flag will be set to the second value. That is, even if the queue depth recovers to less than the congestion threshold after the queue depth is greater than the congestion threshold, the message queue is considered to be in a state of mild congestion.
[0131] In the above embodiments, the frequent switching of congestion flags caused by queue depth fluctuations is suppressed, the repeated start and stop of the drop policy is avoided, and the consumption of system resources is reduced.
[0132] In some alternative implementations, if the first identifier is the first value, two control instructions can be retrieved from the message dequeue in each instruction processing cycle, one control instruction is discarded, and the other control instruction is processed. After the control instructions are dequeued, it is checked whether the queue depth has been reduced to the recovery threshold. If so, the congestion identifier is modified to the second identifier.
[0133] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0134] Based on the same inventive concept, this application also provides a message processing apparatus for implementing the message processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more message processing apparatus embodiments provided below can be found in the limitations of the message processing method described above, and will not be repeated here.
[0135] In one exemplary embodiment, such as Figure 4 As shown, a message processing apparatus is provided, comprising:
[0136] The acquisition module 10 is used to acquire the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end;
[0137] Processing module 20 is used to process instructions on the message queue using an interval discarding strategy when the congestion identifier is the first identifier. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
[0138] In the above embodiments, the congestion identifier of the message queue on the controlled end is obtained. The message queue is used to cache control commands from the control end. When the congestion identifier is a first identifier, an interval-based discarding strategy is used to process commands in the message queue. The first identifier indicates that the message queue is in a congested state. The interval-based discarding strategy includes discarding some control commands, and at least one undiscarded control command exists between two adjacent discarded control commands. This scheme retains valid commands through interval-based discarding, preventing queue function failure; and retains valid commands between adjacent discarded commands, ensuring continuous action on the controlled end, guaranteeing real-time control accuracy, and reducing the risk of system anomalies.
[0139] In one embodiment, when the congestion identifier is a first identifier, the processing module 20 is specifically used to:
[0140] If the first identifier is a first value, then the message queue is processed using an interval discarding strategy based on the discard mapping rule. The discard mapping rule includes a first number of instruction processing cycles included in a discard processing cycle, a second number of instruction processing cycles in the first number that require discarding control instructions, and a processing identifier for the first number of control instructions. The processing identifier is used to indicate whether the instruction processing cycle discards control instructions. If the first identifier is a second value, then the message queue is processed using an interval discarding strategy based on the candidate discarding strategy. The candidate discarding strategy includes a discard mapping rule and a random discarding strategy.
[0141] In one embodiment, the processing module 20 is specifically used for:
[0142] Within the current discard processing cycle, for the first number of instruction processing cycles, the control instructions are processed according to the processing identifier of each control instruction within the first number of instruction processing cycles.
[0143] In one embodiment, instruction processing involves retrieving control instructions to be executed from the message queue, and the processing module 20 is specifically used for:
[0144] For each processing identifier, if the processing identifier indicates that a control instruction should be discarded, two control instructions are retrieved from the message queue within the current instruction processing cycle. The two control instructions include the target control instruction corresponding to the processing identifier, and a control instruction preceding or following the target control instruction. The target control instruction is discarded, and the other control instruction is responded to.
[0145] In one embodiment, instruction processing involves writing the received control instruction to the message queue, and the processing module 20 is specifically used for:
[0146] For each processing flag, if the processing flag indicates that the control command should be discarded, the control command corresponding to the processing flag should be discarded; if the processing flag indicates that the control command should not be discarded, the control command corresponding to the processing flag should be added to the message queue.
[0147] In one embodiment, instruction processing involves writing the received control instruction into the message queue. If the candidate discard strategy is a random discard strategy, the processing module 20 is specifically used for:
[0148] Obtain the receive flag of the previous control command; if the receive flag of the previous control command indicates that the previous control command was discarded, add the current control command to the message queue and set the receive flag of the current control command to indicate that it was written; if the receive flag of the previous control command indicates that the previous control command was written, determine the reception result of the current control command according to a random algorithm, and write or discard the current control command according to the reception result, and set the receive flag of the current control command according to the reception result.
[0149] In one embodiment, the device further includes an update module for:
[0150] Update the congestion flag based on the message queue depth.
[0151] In one embodiment, the update module is specifically used for:
[0152] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to the second flag, which is used to indicate that the message queue congestion has been eliminated; if the queue depth is greater than or equal to the congestion threshold, the congestion flag is set to the first value; if the queue depth is greater than the recovery threshold but less than the congestion threshold, the congestion flag is set to the second value.
[0153] In one embodiment, the update module is specifically used for:
[0154] If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to the second flag, which is used to indicate that the message queue congestion has been eliminated; if the queue depth is greater than or equal to the congestion threshold, the congestion flag is set to the first value; if the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion flag is the second flag, the congestion flag is updated to the second flag; if the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion flag is either the first or the second value, the congestion flag is set to the second value.
[0155] Each module in the aforementioned message processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0156] In one exemplary embodiment, a computer device is provided, which may be a controlled terminal, and its internal structure diagram may be as follows: Figure 5 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores control instruction data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a message processing method.
[0157] Those skilled in the art will understand that Figure 5The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0158] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the message processing method described in any of the above embodiments.
[0159] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the message processing method described in any of the above embodiments.
[0160] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the message processing method described in any of the above embodiments.
[0161] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0162] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0163] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0164] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A message processing method, characterized in that, The method is applied to the controlled end in a real-time control system, and the method includes: Obtain the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end; When the congestion identifier is the first identifier, an interval discarding strategy is used to process instructions for the message queue. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.
2. The method according to claim 1, characterized in that, When the congestion identifier is the first identifier, the message queue is processed using an interval-based discarding strategy, including: If the first identifier is a first value, then the message queue is processed by the interval discarding strategy of the discarding mapping rule. The discarding mapping rule includes a first number of instruction processing cycles included in a discarding processing cycle, a second number of instruction processing cycles that need to discard control instructions in the first number, and a processing identifier of the first number of control instructions. The processing identifier is used to indicate whether the instruction processing cycle discards control instructions. If the first identifier is the second value, then the message queue is processed by the interval discarding strategy of the candidate discarding strategy, wherein the candidate discarding strategy includes a discarding mapping rule and a random discarding strategy.
3. The method according to claim 2, characterized in that, The interval discarding strategy using discarding mapping rules is used to process instructions for the message queue, including: Within the current discard processing cycle, for the first number of instruction processing cycles, the control instructions are processed according to the processing identifier of each control instruction within the first number of instruction processing cycles.
4. The method according to claim 3, characterized in that, Instruction processing involves retrieving control instructions to be executed from the message queue. The step of processing the control instructions according to their processing identifiers within a first number of instruction processing cycles includes: For each processing identifier, if the processing identifier indicates that the control instruction should be discarded, two control instructions are retrieved from the message queue within the current instruction processing cycle. The two control instructions include the target control instruction corresponding to the processing identifier, and the control instruction before or after the target control instruction. The target control command is discarded, and another control command is responded to.
5. The method according to claim 3, characterized in that, The instruction processing involves writing the received control instructions into the message queue. The step of processing the control instructions according to their processing identifiers within a first number of instruction processing cycles includes: For each processing identifier, if the processing identifier indicates that the control command should be discarded, the control command corresponding to the processing identifier should be discarded. If the processing identifier indicates that the control command should not be discarded, the control command corresponding to the processing identifier is added to the message queue.
6. The method according to claim 2, characterized in that, The instruction processing involves writing the received control instruction into the message queue. If the candidate discarding strategy is a random discarding strategy, then the message queue is processed using the interval discarding strategy of the candidate discarding strategy, including: Obtain the reception identifier of the previous control command; If the receive identifier of the previous control instruction indicates that the previous control instruction was discarded, then the current control instruction is added to the message queue, and the receive identifier of the current control instruction is set to an identifier indicating that it was written. If the reception identifier of the previous control instruction indicates that the previous control instruction has been written, then the reception result of the current control instruction is determined according to a random algorithm, and the current control instruction is written or discarded according to the reception result, and the reception identifier of the current control instruction is set according to the reception result.
7. The method according to claim 1, characterized in that, The method further includes: The congestion identifier is updated based on the queue depth of the message queue.
8. The method according to claim 7, characterized in that, The step of updating the congestion identifier based on the queue depth of the message queue includes: If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to a second flag, wherein the second flag is used to characterize the message queue congestion elimination; If the queue depth is greater than or equal to the congestion threshold, then the congestion flag is set to the first value; If the queue depth is greater than the recovery threshold and less than the congestion threshold, then the congestion flag is set to the second value.
9. The method according to claim 7, characterized in that, The step of updating the congestion identifier based on the queue depth of the message queue includes: If the queue depth is less than or equal to the recovery threshold, the congestion flag of the message queue is set to a second flag, wherein the second flag is used to characterize the message queue congestion elimination; If the queue depth is greater than or equal to the congestion threshold, then the congestion flag is set to the first value; If the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion identifier is a second identifier, then the congestion identifier is updated to the second identifier; if the queue depth is greater than the recovery threshold and less than the congestion threshold, and the congestion identifier is a first value or a second value, then the congestion identifier is set to the second value.
10. A message processing device, characterized in that, The device is used at the controlled end of a real-time control system, and the device includes: The acquisition module is used to acquire the congestion identifier of the message queue of the controlled end, wherein the message queue is used to cache control commands from the control end; The processing module is configured to process instructions on the message queue using an interval discarding strategy when the congestion identifier is a first identifier. The first identifier is used to identify that the message queue is in a congested state. The interval discarding strategy includes discarding some of the control instructions, and there is at least one undiscarded control instruction between two adjacent discarded control instructions.