A system blocking processing method and device based on Redis queue
By introducing instruction pools and local ordered queues into the Redis queue, instructions are dynamically scheduled to optimize instruction processing in high-concurrency environments, solving the performance bottlenecks and blocking problems of traditional systems, and improving system operating efficiency and ensuring stability.
Patent Information
- Application Number
- CN202410635011.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-05-22
AI Technical Summary
In a high-concurrency environment, traditional instruction processing systems face performance bottlenecks and blocking problems. A single Redis instance has limited performance when processing a large number of instructions, and the instruction queue blocking caused by device failure affects the instruction processing of other devices, resulting in system operating efficiency. Low.
By introducing an instruction pool and a local ordered queue into the Redis queue, the instructions with the highest priority are dynamically selected and transferred to the instruction pool for parallel or serial execution. Combined with priority sorting and scheduling strategies, a non-blocking execution strategy is implemented to improve the system. efficiency.
It effectively solves the problem of low operating efficiency caused by system blocking, improves the system's concurrent processing capability and response speed, and ensures rapid response to high-priority instructions and system stability.
Smart Images

Figure CN118227300B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of system management and control, and in particular to a system congestion processing method and device based on Redis queue. Background Art
[0002] In complex control systems, there is often a high-concurrency environment. A high-concurrency environment usually refers to a system environment in which a large number of requests or operations are performed simultaneously within a unit of time. In a high-concurrency environment, traditional instruction processing systems face significant performance bottlenecks and blocking problems, which are specifically manifested as follows:
[0003] 1. Performance bottleneck: The performance of a single Redis instance is limited when processing a large number of instructions. Although using multiple Redis clusters can increase storage capacity, it cannot fundamentally solve the limitation of concurrent processing capabilities.
[0004] 2. Blockage problem: When individual devices go offline due to a fault, the entire command queue may be blocked, affecting the command processing of other devices, and thus causing larger production accidents.
[0005] 3. Limitations of sequential execution: Instructions for a single device may need to be executed sequentially, which further exacerbates processing delays and limits the overall responsiveness and efficiency of the system.
[0006] There is currently no better solution to the above problems. Summary of the invention
[0007] The embodiment of the present invention provides a method and device for processing system congestion based on a Redis queue, so as to at least solve the problem of low system operation efficiency caused by system congestion in the related art.
[0008] According to an embodiment of the present invention, a system blocking processing method based on a Redis queue is provided, comprising:
[0009] Acquire a device instruction, and store the device instruction in a preset local ordered queue, wherein the local ordered queue corresponds to the device instruction;
[0010] The local ordered queue performs instruction processing operations on the device instructions to obtain a first instruction with the highest priority;
[0011] Dispatching the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions;
[0012] The first instructions in the instruction pool are sorted according to their priorities, and the first instructions are executed in parallel based on a non-blocking execution strategy according to the sorting results, or the first instructions are executed serially according to the sorting results.
[0013] In an exemplary embodiment, storing the device instructions in a preset local ordered queue includes:
[0014] Obtaining first level attributes of the device command;
[0015] According to the first level attribute, the device instruction is stored.
[0016] In an exemplary embodiment, the sorting the first instructions in the instruction pool according to their priorities comprises:
[0017] classifying the first instructions according to the priority of the first instructions;
[0018] The classified first instructions are batched according to the priorities of the first instructions to obtain first instructions of different batches, wherein the parallel execution of the first instructions according to the sorting results is based on the batch execution of the first instructions.
[0019] In an exemplary embodiment, after classifying the first instruction according to the priority of the first instruction, the method further includes:
[0020] Determining an execution scheduling strategy for the first instruction according to the instruction type of the classified first instruction;
[0021] According to the execution scheduling strategy, a parallel / serial execution mode of the first instruction is determined.
[0022] In an exemplary embodiment, sorting the first instructions in the instruction pool according to their priorities, and serially executing the first instructions according to the sorting results includes:
[0023] Determining a sorting attribute of the first instruction, wherein the sorting attribute includes at least one of a configuration priority, an instruction creation time, and an instruction expiration time of the first instruction;
[0024] According to the sorting attribute, the priority of the first instruction is determined, and the first instruction is sorted according to the first priority, and then the first instruction is executed serially according to the sorting result.
[0025] In an exemplary embodiment, after scheduling the first instruction to an instruction pool, the method further includes at least any one of the following:
[0026] Obtaining an instruction supplement message, and scheduling a second instruction to the instruction pool according to the instruction supplement message, wherein the second instruction includes other first instructions except the first instruction that has been executed;
[0027] or, according to the execution result of the first instruction executed in series, obtaining the first instruction active supplement message, and scheduling the second instruction to the instruction pool according to the first instruction active supplement message;
[0028] Or, according to the execution result of the first instruction executed in parallel, a plurality of second instruction active supplementary messages are continuously acquired, and the second instruction is scheduled to the instruction pool according to the second instruction active supplementary message.
[0029] In an exemplary embodiment, after executing the first instruction, the method further includes at least any one of the following:
[0030] Performing a timeout detection on the first instruction in the instruction pool within a preset inspection cycle, and removing a mark for the first instruction whose timeout detection result meets the timeout condition;
[0031] Or, based on a preset first message mechanism, the first instruction stored in the first local ordered queue is pushed to the instruction pool according to the received anti-blocking instruction, wherein the first local ordered queue is a non-empty local ordered queue.
[0032] According to another embodiment of the present invention, a system blocking processing device based on a Redis queue is provided, comprising:
[0033] An instruction acquisition module, used for acquiring device instructions and storing the device instructions in a preset local ordered queue, wherein the local ordered queue corresponds to the device instructions;
[0034] A first instruction determination module, configured for the local ordered queue to perform an instruction processing operation on the device instruction to obtain a first instruction with the highest priority;
[0035] An instruction scheduling module, used for scheduling the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions;
[0036] An instruction execution module is used to sort the first instructions in the instruction pool according to their priorities, and execute the first instructions in parallel based on a non-blocking execution strategy according to the sorting results, or execute the first instructions serially according to the sorting results.
[0037] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.
[0038] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0039] Through the present invention, by setting up an instruction pool, the current optimal instruction from each local ordered queue can be dynamically selected and transferred to the instruction pool to achieve concurrent execution. At the same time, by setting up local ordered queues and sorting the instructions according to priorities, instructions of different levels can be processed in order. Therefore, the problem of low system operation efficiency caused by system congestion can be solved, thereby achieving the effect of improving system operation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a hardware structure block diagram of a mobile terminal of a system blocking processing method based on a Redis queue according to an embodiment of the present invention;
[0041] Figure 2 is a flowchart of a system blocking processing method based on Redis queue according to an embodiment of the present invention;
[0042] Figure 3 It is a structural block diagram of a system congestion processing device based on Redis queue according to an embodiment of the present invention. DETAILED DESCRIPTION
[0043] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0044] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0045] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 1 is a hardware structure block diagram of a mobile terminal of a system blocking processing method based on a Redis queue according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0046] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a system blocking processing method based on a Redis queue in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0047] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0048] In this embodiment, a system blocking processing method based on Redis queue is provided. Figure 2 is a flowchart of a system blocking processing method based on Redis queue according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0049] Step S201, obtaining a device instruction, and storing the device instruction in a preset local ordered queue, wherein the local ordered queue corresponds to the device instruction;
[0050] In this embodiment, for each device, the system creates a local ordered queue corresponding to the device for storing instructions from the device, where the device instructions include instructions for performing related operations, such as information transmission, device switching actions, etc.
[0051] Whenever the system receives a command from a device, the system will decide to add the command to the local ordered queue corresponding to the device according to the attributes of the command. In the process of storing the device command, storing the device command in the preset local ordered queue includes:
[0052] Step S2011, obtaining the first level attribute of the device instruction;
[0053] Step S2012: storing the device instruction according to the first level attribute.
[0054] In this embodiment, when adding an instruction to a queue, the system will decide whether to add it to the head or tail of the queue based on the isVip attribute of the instruction (i.e., the aforementioned first-level attribute). If the instruction is marked as VIP (very important), the system will add it to the head of the queue for priority execution; otherwise, the system will add it to the tail of the queue and execute it in the order in which it was added.
[0055] Step S202, the local ordered queue performs instruction processing operations on the device instruction to obtain a first instruction with the highest priority;
[0056] In this embodiment, the instruction processing operation refers to the local ordered queue actively polling and selecting device instructions according to the poll scheduling algorithm to determine the instruction with the highest priority.
[0057] For each local ordered queue, the system will actively perform a poll operation, so that the highest priority instruction can be taken out of the queue; the poll operation specifically includes calling out instructions that meet the requirements from the queue, for example, for some timed instructions, the poll operation is used to remove the instruction from the head of the queue.
[0058] Step S203, dispatching the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions;
[0059] In this embodiment, instruction processing operations and instruction scheduling are dynamic and need to be adjusted according to the priority and real-time status of the instructions.
[0060] Among them, after the first instruction is scheduled to the instruction pool, in the current instruction pool, the system executes the instructions in sequence according to their position in the queue, that is, the instruction at the head of the queue is executed first, then the next instruction in the queue, and so on; before executing each instruction, the system will check whether the instruction has expired. If the instruction has expired, the system will remove it from the current instruction pool and issue an instruction abnormal completion event.
[0061] Step S204, sorting the first instructions in the instruction pool according to their priorities, and executing the first instructions in parallel based on a non-blocking execution strategy according to the sorting results, or executing the first instructions serially according to the sorting results.
[0062] In this embodiment, the scheduling algorithm in the instruction pool will classify instructions into three different priorities according to the instruction type, and execute the instructions in batches in parallel or serially according to the priority. This hierarchical execution strategy is designed to optimize execution efficiency and ensure that high-priority device operations can be responded to quickly; each instruction may contain multiple write point instructions. These sub-instructions will be executed sequentially in a request-response (req-resp) mode to ensure data consistency and operation accuracy.
[0063] In an optional embodiment, sorting the first instructions in the instruction pool according to their priorities includes:
[0064] Step S2041, classifying the first instruction according to the priority of the first instruction;
[0065] Step S2042, batch determining the classified first instructions according to the priority of the first instructions to obtain first instructions of different batches, wherein the parallel execution of the first instructions according to the sorting result is based on the batch execution of the first instructions.
[0066] In this embodiment, the instruction priority classification includes classifying the instructions into the following three different priorities:
[0067] Class 1 instructions: high priority, need to block the execution of Class 2 and Class 3 instructions, using serial execution, including:
[0068] 10) Emergency stop command, used for handling various emergency situations;
[0069] 11) Open the manual mode command of the device, which is used to switch back to the automatic mode after completing the remote control function; or restore the automatic control system execution;
[0070] Category 2 instructions: medium priority, serial execution.
[0071] 21) Adjust flow instructions. The system will gradually adjust the opening of the relevant valves to achieve the predetermined flow requirements. Such instructions usually do not require an immediate response, but need to be executed in sequence to ensure system stability and operating efficiency.
[0072] Category 3 instructions: low priority, parallel execution.
[0073] Batch parallel execution: The instructions in the instruction pool will be divided into different batches according to their priorities, and then the batches of the three types of instructions will be executed in batches in parallel according to their priorities.
[0074] In an optional embodiment, after classifying the first instruction according to the priority of the first instruction, the method further includes:
[0075] Step S20411, determining an execution scheduling strategy for the first instruction according to the instruction type of the classified first instruction;
[0076] Step S20412: Determine the parallel / serial execution mode of the first instruction according to the execution scheduling strategy.
[0077] In this embodiment, after determining the type and priority of each instruction, the instructions are respectively executed in parallel or serially according to the execution scheduling strategy. The specific execution scheduling strategy is as follows:
[0078] Class 1 instruction execution: When a Class 1 instruction needs to be executed, the system will suspend the execution of all Class 2 and Class 3 instructions and execute the Class 1 instructions in serial. This ensures that high-priority device operations can be responded to quickly.
[0079] Execution of Category 2 instructions: After Category 1 instructions are executed, the system will continue to execute Category 2 instructions and resume the execution of Category 3 instructions. Category 2 instructions are executed serially.
[0080] 3 types of instruction execution: The system will execute 3 types of instructions in parallel.
[0081] In an optional embodiment, sorting the first instructions in the instruction pool according to their priorities, and serially executing the first instructions according to the sorting results includes:
[0082] Step S20413, determining a sorting attribute of the first instruction, wherein the sorting attribute includes at least one of a configuration priority, an instruction creation time, and an instruction expiration time of the first instruction;
[0083] Step S20414: determine the priority of the first instruction according to the sorting attribute, sort the first instructions according to the first priority, and then execute the first instructions serially according to the sorting result.
[0084] In this embodiment, for each local ordered queue, the system will sort the instructions in the queue that need to be executed serially according to the following criteria:
[0085] Instruction priority: The configuration priority of the instruction. Instructions with higher priority will be processed first.
[0086] Instruction creation time: The earlier the instruction is created, the higher its priority.
[0087] Instruction expiration time: The closer the instruction expiration time is, the higher its priority. The system uses a constant to control the impact of the expiration time.
[0088] In an optional embodiment, after scheduling the first instruction to the instruction pool, the method further includes at least any one of the following:
[0089] Obtaining an instruction supplement message, and scheduling a second instruction to the instruction pool according to the instruction supplement message, wherein the second instruction includes other first instructions except the first instruction that has been executed;
[0090] or, according to the execution result of the first instruction executed in series, obtaining the first instruction active supplement message, and scheduling the second instruction to the instruction pool according to the first instruction active supplement message;
[0091] Or, according to the execution result of the first instruction executed in parallel, a plurality of second instruction active supplementary messages are continuously acquired, and the second instruction is scheduled to the instruction pool according to the second instruction active supplementary message.
[0092] In this embodiment, after the relevant first instruction is executed, the instruction pool scheduling algorithm will also be responsible for supplementing instructions according to the actual situation of the instruction pool to ensure the continuity and efficient operation of the instruction pool.
[0093] Specifically, the supplement method is as follows:
[0094] 1) Passive acceptance plus active pulling: The command pool can both passively accept the replenishment of commands and actively pull commands to replenish itself.
[0095] 2) Supplement mechanism after serial instruction execution: When the serial instruction is executed, the system will trigger the corresponding local queue to actively supplement the instruction. This means that the system will check whether the corresponding local queue has instructions to be executed (i.e. the second instruction mentioned above). If so, these instructions will be supplemented to the instruction pool until the local queue is empty.
[0096] 3) Supplementary mechanism after parallel instruction execution: When parallel instructions are executed, the system will trigger the method of pulling instructions from the corresponding local queue multiple times in a row. The system uses a non-blocking method when executing instructions, that is, while executing an instruction, the system can continue to execute other instructions without waiting for the current instruction to be executed. This can improve the execution efficiency and concurrency performance of the system.
[0097] 4) Send instruction consumption events: The system pushes instruction consumption events to the business system before and after instruction consumption. The business system can block the execution of instructions through the pre-instruction consumption events. It should be noted that when the local ordered queue receives the instruction completion consumption event, it will find and remove the corresponding instruction from the queue, and trigger the global instruction execution completion event to notify the business program to execute the corresponding business processing. This step ensures the smooth execution of instructions and the effective release of system resources.
[0098] In an optional embodiment, after executing the first instruction, the method further includes at least any one of the following:
[0099] Performing a timeout detection on the first instruction in the instruction pool within a preset inspection cycle, and removing a mark for the first instruction whose timeout detection result meets the timeout condition;
[0100] In this embodiment, the instruction pool scheduling algorithm includes a timer task, which regularly checks whether there are timed instructions in the instruction pool, removes them, marks them as execution failures, and continues to execute the next instruction to ensure smooth operation of the system.
[0101] Or, based on a preset first message mechanism, the first instruction stored in the first local ordered queue is pushed to the instruction pool according to the received anti-blocking instruction, wherein the first local ordered queue is a non-empty local ordered queue.
[0102] In this embodiment, in order to prevent blockage caused by errors in supplementing instructions in the instruction pool, the notifyAll message mechanism (i.e., the first message mechanism mentioned above) is used. That is, after receiving the message, each non-empty local ordered queue will try to push the latest instruction to the instruction pool, thereby solving possible blocking problems.
[0103] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0104] The following is an explanation through specific embodiments.
[0105] This method aims to optimize the instruction processing flow in a high-concurrency environment, ensure the independence of instructions between devices, and ensure that the device's point write instructions can be executed in a predetermined order. By ensuring that the instructions are successfully executed and confirmed before being removed from the queue, the stability of the system and the reliability of instruction execution are improved.
[0106] 4.1 Queueing
[0107] For each device, its instructions are added to a corresponding local ordered queue, which ensures that the instructions of the same device can be executed in a predetermined order without being affected by the processing rate of instructions in other local ordered queues.
[0108] Create a local ordered queue: For each device, the system creates a local ordered queue to store the device's instructions.
[0109] Instruction enqueuing: Whenever the system receives an instruction from a device, the system will decide to add the instruction to the local ordered queue corresponding to the device based on the attributes of the instruction.
[0110] Consider the isVip attribute: When adding an instruction to a queue, the system will decide whether to add it to the head or tail of the queue based on the isVip attribute of the instruction. If the instruction is marked as VIP (very important), the system will add it to the head of the queue for priority execution; otherwise, the system will add it to the tail of the queue and execute it in the order it was added.
[0111] 4.2 Instruction poll scheduling algorithm
[0112] The local ordered queue will actively poll the highest priority instruction and schedule it to the current instruction pool. This step is dynamic and is adjusted according to the priority and real-time status of the instruction. It specifically includes the following steps:
[0113] 1) Actively poll the highest priority instruction: For each local ordered queue, the system will actively perform the Poll operation to take out the highest priority instruction from the queue.
[0114] 2) Scheduled to the current instruction pool: The highest priority instruction taken out will be scheduled to the current instruction pool and wait for execution.
[0115] 3) Execute in sequence: In the current instruction pool, the system executes the instructions in sequence according to their position in the queue. That is, the instruction at the head of the queue is executed first, then the next instruction in the queue, and so on.
[0116] 4) Determine whether the instruction has expired: Before executing each instruction, the system will check whether the instruction has expired. If the instruction has expired, the system will remove it from the current instruction pool and issue an abnormal instruction completion event.
[0117] 4.3 Instruction Pool Scheduling (pollFirst)
[0118] The scheduling algorithm in the instruction pool divides instructions into three different priorities according to the instruction type, and executes the instructions in batches in parallel according to the priority. This hierarchical execution strategy is designed to optimize execution efficiency and ensure that high-priority device operations can be responded to quickly.
[0119] Instruction priority classification: Instructions are divided into three different priorities:
[0120] Class 1 instructions: high priority, need to block the execution of Class 2 and Class 3 instructions, using serial execution, including:
[0121] 1) Emergency stop command and various emergency situations;
[0122] 2) Turn on the manual mode of the device, complete the remote control function, and switch back to the automatic mode. Resume the automatic control system execution.
[0123] Category 2 instructions: medium priority, serial execution, including:
[0124] Adjust the flow command, the system will gradually adjust the opening of the relevant valve to achieve the predetermined flow requirement. Such instructions usually do not require an immediate response, but need to be executed in sequence to ensure the stability and efficiency of the system.
[0125] Category 3 instructions: low priority, parallel execution.
[0126] Batch parallel execution: The instructions in the instruction pool are divided into different batches according to their priorities, and then executed in batches in parallel according to their priorities.
[0127] Classification scheduling strategy:
[0128] Class 1 instruction execution: When a Class 1 instruction needs to be executed, the system will suspend the execution of all Class 2 and Class 3 instructions and execute the Class 1 instructions in serial. This ensures that high-priority device operations can be responded to quickly.
[0129] Execution of Category 2 instructions: After Category 1 instructions are executed, the system will continue to execute Category 2 instructions and resume the execution of Category 3 instructions. Category 2 instructions are executed serially.
[0130] 3 types of instruction execution: The system will execute 3 types of instructions in parallel.
[0131] The serial instruction sorting criteria include: for each local ordered queue, the system will sort the instructions in the queue according to the following criteria:
[0132] Instruction priority: The configuration priority of the instruction. Instructions with higher priority will be processed first.
[0133] Instruction creation time: The earlier the instruction is created, the higher its priority.
[0134] Instruction expiration time: The closer the instruction expiration time is, the higher its priority. The system uses a constant to control the impact of the expiration time.
[0135] 4.4 Specific instruction execution (exec)
[0136] Each instruction may contain multiple write bit instructions. These sub-instructions will be executed in sequence according to the request-response (req-resp) mode to ensure data consistency and operation accuracy.
[0137] 4.5 Instruction execution completion feedback (complete)
[0138] After the instruction is executed, its completion time will be pushed to the instruction pool scheduling algorithm. This information helps the instruction pool scheduling algorithm to perform the next step of instruction scheduling and management.
[0139] 4.6 Instruction pool supplement (completeEvent)
[0140] The instruction pool scheduling algorithm is responsible for supplementing instructions according to the actual situation of the instruction pool to ensure the continuity and efficient operation of the instruction pool.
[0141] Passive acceptance plus active pulling: The command pool can both passively accept the replenishment of commands and actively pull commands to replenish itself.
[0142] Supplement mechanism after serial instruction execution: When the serial instruction is executed, the system will trigger the corresponding local queue to actively supplement the instruction. This means that the system will check whether there are instructions to be executed in the corresponding local queue. If there are, these instructions will be supplemented to the instruction pool until the local queue is empty.
[0143] Supplementary mechanism after parallel instruction execution is completed: When parallel instructions are executed, the system will trigger the method of pulling instructions from the corresponding local queue multiple times in a row. The system uses a non-blocking method when executing instructions, that is, while executing an instruction, the system can continue to execute other instructions without waiting for the current instruction to be completed. This can improve the execution efficiency and concurrency performance of the system.
[0144] Send instruction consumption events: The system pushes instruction consumption events to the business system before and after instruction consumption. The business system can block the execution of instructions through the pre-instruction consumption events.
[0145] 4.7 Command Confirmation Consumption (remove&CmdCompleteEvent)
[0146] When the local ordered queue receives the instruction completion consumption event, it will find and remove the corresponding instruction from the queue, trigger the global instruction execution completion event, and notify the business program to execute the corresponding business processing. This step ensures the smooth execution of instructions and the effective release of system resources.
[0147] 4.8 Exception handling process
[0148] Exception handling in the instruction pool: The instruction pool scheduling algorithm includes a timer task that regularly checks whether there are timed instructions in the instruction pool, removes them, marks them as execution failures, and continues to execute the next instruction to ensure smooth operation of the system.
[0149] Local ordered queue blocking processing: To prevent blocking caused by errors in the instruction pool to supplement instructions, the notifyAll message mechanism is used. After receiving the message, each non-empty local ordered queue will try to push the latest instruction to the instruction pool, thereby solving possible blocking problems.
[0150] Through the above detailed description, the present invention not only optimizes the instruction processing flow and improves the efficiency and stability of the system, but also enhances the ability to handle abnormal situations and ensures the reliability and sustainability of the system in a high-concurrency environment.
[0151] 4.9 Horizontal Scaling
[0152] 4.9.1 Multiple Redis Instance Clusters
[0153] This method supports running in a multi-Redis instance cluster environment, with each Redis instance acting as an independent instruction queue storage node. This distributed architecture allows the algorithm to process instructions from different devices in parallel, effectively improving processing power and system scalability.
[0154] 4.9.2 Dynamic Instruction Routing
[0155] In order to achieve effective command distribution and load balancing, the algorithm introduces a dynamic command routing mechanism. Based on the characteristics of the command and the current system load, the algorithm can intelligently route the command to the most appropriate Redis instance. This not only ensures the efficiency of command processing, but also avoids the problem of overloading a single Redis instance.
[0156] 4.9.3 Distributed Management of Instruction Pool
[0157] The command pool no longer relies on a single Redis instance, but adopts a distributed management strategy. By sharing command pool information among multiple Redis instances, the algorithm can dynamically schedule commands across the entire cluster, further improving processing efficiency and system scalability.
[0158] 4.9.4 Horizontal Scaling Support
[0159] When the system needs to handle higher concurrency or larger data load, it can be horizontally expanded by simply increasing the number of Redis instances. The design of this algorithm ensures that the newly added Redis instances can be seamlessly integrated into the existing instruction processing flow without major adjustments to the business logic.
[0160] The core of the present invention is to introduce a highly flexible and efficient instruction processing mechanism, that is, by establishing an instruction pool and partially ordered queues, combined with the powerful data processing capabilities of the Redis queue, to optimize instruction processing in a high-concurrency environment. Specifically, the innovative points of the present invention include:
[0161] 1. Introduction of instruction pool: In order to fully utilize the concurrent processing capability of the system, the concept of instruction pool is introduced, so that the current optimal instruction from each local ordered queue can be dynamically selected and transferred to the instruction pool to achieve concurrent execution. As an intermediary layer, the instruction pool not only optimizes the speed and efficiency of instruction processing, but also improves the system's responsiveness to sudden high loads.
[0162] 2. Local ordered queues and local priorities: Each local ordered queue maintains its own set of instructions to ensure the execution order of instructions in key business processes. By implementing the local priority mechanism, the instructions within the queue are sorted according to predefined priority rules to ensure that high-priority instructions can be processed first and pushed to the instruction pool for execution at the appropriate time.
[0163] 3. Dynamic instruction scheduling strategy: Based on the real-time system load and the status of the instruction pool, the instruction transfer strategy from the local ordered queue to the instruction pool is dynamically adjusted. This flexible scheduling mechanism allows the system to maximize processing efficiency and throughput while ensuring the sequential execution of key instructions.
[0164] 4. High performance, high availability and horizontal scalability: In traditional Redis-based systems, the performance and capacity limitations of a single Redis instance often become a bottleneck for system scalability. As processing requirements increase, this architecture is difficult to effectively support higher concurrency and data loads. This method effectively breaks through this limitation by introducing the concept of instruction pools and an optimized scheduling mechanism, thus achieving the horizontal scalability of the system.
[0165] Through the above technical scheme, the present invention can effectively solve the performance bottleneck problem of traditional instruction processing systems in high-concurrency scenarios, especially for application scenarios that need to maintain the execution order of local instructions, such as financial transactions, real-time message processing, etc. The present invention provides a solution that can both ensure the execution order and improve processing efficiency and system stability.
[0166] In this embodiment, a system blocking processing device based on Redis queue is also provided, which is used to implement the above embodiments and preferred implementation modes, and will not be repeated hereafter. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0167] Figure 3 is a structural block diagram of a system blocking processing device based on a Redis queue according to an embodiment of the present invention. Figure 3 As shown, the device comprises:
[0168] An instruction acquisition module 31 is used to acquire device instructions and store the device instructions in a preset local ordered queue, wherein the local ordered queue corresponds to the device instructions;
[0169] A first instruction determination module 32, configured for the local ordered queue to perform instruction processing operations on the device instruction to obtain a first instruction with the highest priority;
[0170] An instruction scheduling module 33, configured to schedule the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions;
[0171] The instruction execution module 34 is used to sort the first instructions in the instruction pool according to their priorities, and execute the first instructions in parallel based on the sorting results based on a non-blocking execution strategy, or execute the first instructions serially based on the sorting results.
[0172] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0173] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0174] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0175] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0176] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0177] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0178] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0179] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A system blocking processing method based on Redis queue, characterized in that: include: Acquire a device instruction, and store the device instruction in a preset local ordered queue, wherein the local ordered queue corresponds to the device instruction; The local ordered queue performs instruction processing operations on the device instructions to obtain a first instruction with the highest priority; Dispatching the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions; sorting the first instructions in the instruction pool according to their priorities, and executing the first instructions in parallel based on a non-blocking execution strategy according to the sorting result, wherein the sorting result includes that the priority of the first instruction is a low priority; The first instructions are executed serially according to the sorting result, wherein the sorting result includes that the priority of the first instructions is high priority or medium priority.
2. The method according to claim 1, characterized in that The storing the device instructions in a preset local ordered queue comprises: Obtaining first level attributes of the device command; According to the first level attribute, the device instruction is stored.
3. The method according to claim 1, characterized in that: The sorting of the first instructions in the instruction pool according to their priorities comprises: classifying the first instructions according to the priority of the first instructions; The classified first instructions are batched according to the priorities of the first instructions to obtain first instructions of different batches, wherein the parallel execution of the first instructions according to the sorting results is based on the batch execution of the first instructions.
4. The method according to claim 3, characterized in that After classifying the first instruction according to the priority of the first instruction, the method further includes: Determining an execution scheduling strategy for the first instruction according to the instruction type of the classified first instruction; According to the execution scheduling strategy, a parallel / serial execution mode of the first instruction is determined.
5. The method according to claim 1, characterized in that The step of sorting the first instructions in the instruction pool according to their priorities, and serially executing the first instructions according to the sorting results includes: Determining a sorting attribute of the first instruction, wherein the sorting attribute includes at least one of a configuration priority, an instruction creation time, and an instruction expiration time of the first instruction; The priority of the first instruction is determined according to the sorting attribute, and the first instructions are sorted according to the priority of the first instruction, and the first instructions are executed serially according to the sorting result.
6. The method according to claim 1, characterized in that After scheduling the first instruction to the instruction pool, the method further includes at least any one of the following: Obtaining an instruction supplement message, and scheduling a second instruction to the instruction pool according to the instruction supplement message, wherein the second instruction includes other first instructions except the first instruction that has been executed; or, According to the execution result of the first instruction executed in series, obtaining the first instruction active supplement message, and scheduling the second instruction to the instruction pool according to the first instruction active supplement message; or, According to the execution result of the first instruction executed in parallel, a plurality of second instruction active supplementary messages are continuously acquired, and the second instruction is scheduled to the instruction pool according to the second instruction active supplementary message.
7. The method according to claim 1, characterized in that After executing the first instruction, the method further includes at least any one of the following: Performing a timeout detection on the first instruction in the instruction pool within a preset inspection cycle, and removing a mark for the first instruction whose timeout detection result meets the timeout condition; or, Based on a preset first message mechanism, a first instruction stored in a first local ordered queue is pushed to the instruction pool according to the received anti-blocking instruction, wherein the first local ordered queue is a non-empty local ordered queue.
8. A system blocking processing device based on Redis queue, characterized in that: include: An instruction acquisition module, used for acquiring device instructions and storing the device instructions in a preset local ordered queue, wherein the local ordered queue corresponds to the device instructions; A first instruction determination module, configured for the local ordered queue to perform instruction processing operations on the device instruction to obtain a first instruction with the highest priority; An instruction scheduling module, used for scheduling the first instruction to an instruction pool, wherein the instruction pool stores a plurality of first instructions; An instruction execution module is used to sort the first instructions in the instruction pool according to their priorities, and execute the first instructions in parallel based on a non-blocking execution strategy according to the sorting results, wherein the sorting results include that the priority of the first instruction is high priority or medium priority; and execute the first instructions serially according to the sorting results, wherein the sorting results include that the priority of the first instruction is low priority.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.
