A method, device, and storage medium for adjusting a rule engine
By configuring backup equipment for the rule engine and using the main and standby dual-machine method to monitor and adjust the load ratio and task distribution ratio, the problem of insufficient processing efficiency of the rule engine is solved, and the processing efficiency and system stability of the rule task are improved.
Patent Information
- Application Number
- CN202210476301.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2042-04-29
AI Technical Summary
The existing rule engines are inefficient in handling rule tasks, which affects the overall operational efficiency of the application.
The rule engine is configured with backup equipment, and the main and backup dual-machine method is used to monitor the load ratio between the target equipment and the backup equipment, adjust to the preset expected ratio, calculate the task distribution ratio, and share the rule tasks according to the proportion.
It improves the stability and availability of the rule engine, enhances the utilization rate of backup equipment, and improves the processing efficiency of rule tasks.
Smart Images

Figure CN115016930B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, device, and storage medium for adjusting a rule engine. Background Art
[0002] The rule engine evolved from the inference engine and is a component that can be embedded in an application. It realizes the separation of rule logic from application code and uses predefined semantic modules to write rule logic. The separated rule logic is maintained and run by the rule engine. In this way, the variable rule logic can be made to be adaptable as needed and can support the rapid implementation of complex rule logic.
[0003] Currently, after a rule task is assigned to a rule engine, there are often problems of insufficient processing efficiency, which has an adverse impact on the overall operating efficiency of the application. Summary of the Invention
[0004] Multiple aspects of this application provide a method, device, and storage medium for adjusting a rule engine to improve the processing efficiency of rule tasks.
[0005] An embodiment of this application provides a method for adjusting a rule engine. The rule engine runs on a target device. The method includes:
[0006] In response to a task distribution instruction, monitor the load ratio between a standby device configured for the target device and the target device;
[0007] Aim to adjust the load ratio to a preset desired ratio, and calculate the task distribution ratio between the standby device and the target device;
[0008] Distribute the to-be-processed rule tasks to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the to-be-processed rule tasks proportionally.
[0009] An embodiment of this application also provides a rule engine device, including a memory, a processor, and a communication component;
[0010] The memory is used to store one or more computer instructions;
[0011] The processor is coupled to the memory and the communication component and is used to execute the one or more computer instructions for:
[0012] In response to a task distribution instruction, monitor the load ratio between a standby device configured for the target device and the target device;
[0013] Taking the adjustment of the load ratio to a preset desired ratio as the goal, calculate the task distribution ratio between the standby device and the target device;
[0014] Distribute the to-be-processed rule tasks to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the to-be-processed rule tasks proportionally.
[0015] The embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the foregoing rule engine adjustment method.
[0016] In the embodiment of the present application, a standby device can be configured for the target device running the rule engine, and the rule engine is also enhanced with the ability to distribute rule tasks. In this way, the to-be-processed rule tasks can be shared by means of a primary and standby dual-machine mode. During the process of determining the sharing scheme, the load ratio between the standby device and the target device can be monitored; taking the adjustment of the load ratio to a preset desired ratio as the goal, calculate the task distribution ratio between the standby device and the target device; and distribute the to-be-processed rule tasks to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the to-be-processed rule tasks proportionally. Accordingly, in the embodiment of the present application, the rule engine is optimized, and a standby device is introduced to help the target device share the rule task processing work, thereby effectively improving the stability and / or availability of the rule engine, and improving the utilization rate of the standby device in the rule task processing work from the dimension of the load ratio, and further effectively improving the processing efficiency of the rule tasks. Description of the Drawings
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0018] Figure 1 It is a schematic flowchart of the adjustment of a rule engine provided by an exemplary embodiment of the present application;
[0019] Figure 2 It is a schematic diagram of the adjustment logic of the rule engine provided by an exemplary embodiment of the present application;
[0020] Figure 3 It is a schematic structural diagram of a rule engine device provided by another exemplary embodiment of the present application. Detailed Description of the Embodiment
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts shall fall within the scope of protection of this application.
[0022] Currently, after rule tasks are assigned to a rule engine, there are often problems with insufficient processing efficiency, which has an adverse impact on the overall operating efficiency of the application program. For this reason, in some embodiments of this application: A backup device can be configured for the target device running the rule engine, and the rule engine is also enhanced with the ability to distribute rule tasks. In this way, the rule tasks to be processed can be shared in a primary-backup dual-machine manner. During the process of determining the sharing scheme, the load ratio between the backup device and the target device can be monitored; with the goal of adjusting the load ratio to a preset desired ratio, calculate the task distribution ratio between the backup device and the target device; and according to the task distribution ratio, distribute the rule tasks to be processed to the target device and / or the backup device, so that the target device and the backup device share the rule tasks to be processed in proportion. Accordingly, in the embodiments of this application, the rule engine is optimized, and a backup device is introduced to help the target device share the rule task processing work, thereby effectively improving the stability and / or availability of the rule engine, and the utilization rate of the backup device in the rule task processing work can be increased from the dimension of the load ratio, thereby effectively improving the processing efficiency of the rule tasks.
[0023] The following will detail the technical solutions provided by the embodiments of this application in conjunction with the drawings.
[0024] Figure 1 It is a schematic flowchart of the adjustment of a rule engine provided for an exemplary embodiment of this application. Figure 2 It is a schematic diagram of the adjustment logic of the rule engine provided for an exemplary embodiment of this application. This method can be executed by the rule engine, and the rule engine can run in the target device. Refer to Figure 1 , this method may include:
[0025] Step 100: In response to a task distribution instruction, monitor the load ratio between the backup device configured for the target device and the target device;
[0026] Step 101: With the goal of adjusting the load ratio to a preset desired ratio, calculate the task distribution ratio between the backup device and the target device;
[0027] Step 102: According to the task distribution ratio, distribute the rule tasks to be processed to the target device and / or the backup device, so that the target device and the backup device share the rule tasks to be processed in proportion.
[0028] The rule engine adjustment method provided in this embodiment can be applied to the scenario of a stand-alone rule engine, that is, a scenario where only one device undertakes the rule task processing work. For example, a rule engine server deployed by an enterprise itself, etc. In this case, the rule task to be processed can be the rule task that the rule engine perceives and needs to process in the application scenario; it can also be applied to the distributed rule engine scenario. In this case, the rule task to be processed can be the rule task assigned to the rule engine in this embodiment after the scheduling work such as the existing load balancing method and task distribution method is completed.
[0029] Regardless of which scenario, in this embodiment, the processing efficiency of the rule task to be processed can be effectively improved through the adjusted rule engine.
[0030] In this embodiment, a rule task refers to a task that runs a rule logic, and processing a rule task can refer to running the rule logic corresponding to the specification task.
[0031] Among them, the rule engine can run on the target device. In this embodiment, it is innovatively proposed to configure a standby device for the target device and undertake the rule task based on the master-slave dual-machine structure. Refer to Figure 2 , the rule engine can be deployed on both the target device and the standby device. Refer to Figure 2 , the rule engine can include a rule task distribution module, a rule task execution module, and a rule logic library. Among them, the rule task distribution module is mainly used to undertake logical functions such as load index calculation, load ratio calculation, task distribution ratio calculation, and distributing the rule task to be processed according to the task distribution ratio involved in this embodiment; the rule task execution module is mainly used to undertake the rule task processing function; and the rule logic library can fully maintain the rule logic of the subtasks for the rule task execution module to call. The rule engines on the target device and the standby device can synchronize information through their communication components. The structures of the rule engines on both the target device and the standby device can be the same; of course, some necessary functions can also be trimmed from the rule engine running on the target device and only the trimmed partial comparison functions can be copied to the standby device for operation. This embodiment does not make any limitations in this regard. In this embodiment, it is mainly the rule engine running on the target device that Figure 1 the technical solution shown.
[0032] Based on this, refer to Figure 1, in step 100, in response to a task distribution instruction, the load ratio between the standby device and the target device can be monitored. The task distribution instruction in this embodiment can be triggered based on a period. For example, a task distribution instruction can be generated every 200 ms to distribute the rule tasks to be processed accumulated during a single period; of course, it can also be triggered based on an event. For example, when the number of rule tasks to be processed reaches a threshold, a task distribution instruction can be triggered to distribute the accumulated rule tasks to be processed. These are only exemplary, and this embodiment does not limit the triggering method of the task distribution instruction.
[0033] Among them, the rule engine running on the target device can calculate the load index corresponding to the target device, and the load index is used to represent the load condition of the device; the rule engine running on the standby device can calculate the load index corresponding to the standby device and synchronize it to the target device. In this way, the target device can obtain the load index corresponding to the standby device. Refer to Figure 2 , the load index between the standby device and the target device can be synchronized based on the communication components of both parties. Based on this, the ratio of the load indexes between the standby device and the target device can be used as the load ratio between the target device and the standby device configured for it. An exemplary scheme for calculating the load index can be: performing a weighted sum of one or more of the CPU load rate, memory usage rate, or I / O rate of the local machine to obtain the load index of the local machine. Among them, the value range of the CPU load rate can be 0 to 1, which can be calibrated according to the maximum number of CPU cores of the hardware; the value range of the memory usage rate can be 0 to 1, which can be calibrated according to the maximum memory of the hardware; the value range of the I / O rate can be 0 to 1, which can be calibrated according to the maximum I / O of the hardware. For example, the calculation scheme of the load index can be characterized as:
[0034] P = 0.4R cpu + 0.2R mem + 0.3R io
[0035] Among them, P represents the load index, and R cpu represents the CPU load rate, and the weight assigned to it is 0.4; R mem represents the memory usage rate, and the weight assigned to it is 0.2; R io represents the I / O rate, and the weight assigned to it is 0.3. It should be understood that the weight assignment here is exemplary.
[0036] On this basis, the load ratio can be characterized as:
[0037] R = P l / P r
[0038] Among them, R represents the load ratio, and Pl Indicates the load index of the standby device, P r Indicates the load index of the target device.
[0039] In this embodiment, the expected ratio between the standby device and the target device can also be preset, that is, the load ratio expected to be achieved between the standby device and the target device. For example, the expected ratio can be 1:1 or 2:1, etc. The expected ratio can be determined according to the expected usage rate of the standby device. Of course, it can also be determined according to the requirements of other dimensions, and the load ratio can be adaptively set according to actual needs.
[0040] Reference Figure 1 , in step 101, the load ratio can be adjusted to the preset expected ratio as the target, and the task distribution ratio between the standby device and the target device can be calculated. The task distribution ratio refers to the ratio of the amount of tasks distributed to the target device to the amount of tasks distributed to the standby device.
[0041] In an alternative implementation, the calculation process of the task distribution ratio can be abstracted into a closed-loop control process, and the task distribution ratio can be adjusted according to the deviation between the actual load ratio between the target device and the standby device and the aforementioned expected ratio to minimize this deviation. Optionally, an exemplary control scheme can be: adopting PID control technology, using the monitored load ratio as the actual value, the expected ratio as the expected value, and the task distribution ratio as the control value; by introducing a proportional coefficient, an integral coefficient, and a differential coefficient, calculate the task distribution ratio between the standby device and the target device. Accordingly, the calculation process of the task distribution ratio can be characterized as:
[0042] U k =U k-1 +K p [(R k -R t )-(R k-1 -R t )]+K i (R k -R t )+K d [(R k -R t )-2(R k-1 -R t )+(R k-2 -R t )]
[0043] Wherein, K p , K i and K dThey are the proportional parameter, integral parameter, and derivative parameter in the PID control technology respectively. An exemplary set of values can be 0.2, 0.1, and 0.3 respectively. Of course, this is only exemplary; R t represents the desired ratio, R k 、R k-1 and R k-2 represent the load ratios calculated in the most recent, previous, and penultimate calculations respectively; U k represents the task distribution ratio in the current distribution process, U k-1 represents the task distribution ratio calculated in the previous distribution process, U0 = R t .
[0044] In this implementation, in addition to using the PID control technology to calculate the task distribution ratio, other similar control technologies can also be used, such as fuzzy control, etc. This is not an exhaustive list here.
[0045] In addition, in this embodiment, the method of calculating the task distribution ratio is not limited to the above exemplary implementation. Other methods such as neural networks and machine learning can also be used to calculate the task distribution ratio between the standby device and the target device to achieve the goal of adjusting the load ratio to the preset desired ratio. This embodiment is not limited to this.
[0046] It should be emphasized here that the load ratio, task distribution ratio, etc. in this embodiment are not limited to the ratio of the target device to the standby device or the ratio of the standby device to the target device. In this embodiment, it can be flexibly selected as long as the comparison order adopted in each link is consistent. For example, each link can uniformly adopt [standby device: target device], that is, the standby device is used as the numerator and the target device is used as the denominator. The technical logic in other links will also be described according to this comparison order by default. It should be understood that this embodiment is not limited to this. When [target device: standby device] is adopted, only adaptive modifications need to be made in the relevant technical logic in the following text.
[0047] On this basis, referring to Figure 1 , in step 102, the to-be-processed rule tasks can be distributed to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the to-be-processed rule tasks proportionally. That is, the target device undertakes a part of the task volume, and the standby device undertakes another part of the task volume. It can be seen that in this embodiment, the standby device no longer only plays a role when the host fails as in the traditional standby machine, but actively shares a part of the rule task processing work for the target device. This can not only reduce the task processing pressure on the target device, improve the task processing efficiency, but also increase the utilization rate of the standby device and avoid the idle / waste of processing resources on the standby device.
[0048] In this embodiment, it is innovatively proposed that subtasks can be used as the distribution unit for distributing the to-be-processed rule tasks. For this purpose, in this embodiment, a single to-be-processed rule task can be split into a trigger subtask, a condition subtask, and an action subtask. Among them, the trigger subtask is used to configure the trigger source of the rule task and monitor whether a trigger event that can trigger the rule task occurs. It supports trigger forms such as timed trigger and event trigger. For example, when the target device receives specified data, a specified rule task can be triggered. When the system inside the target device reports specified data, a specified rule task can be triggered, etc. The condition subtask is used to configure the condition judgment logic and judge whether the data / status meets the conditions, so as to decide whether to execute the associated action subtask. The action subtask is used to configure the operation behavior and execute the operation behavior under the instruction of the condition subtask. An exemplary rule logic can be: the trigger source is the currently reported time, the condition is that the current time is Wednesday and December, and the action is to write an identification bit to the PLC and generate a log. In this way, the trigger subtask can be used to monitor whether the reported time is received. If received, the specification task corresponding to this rule logic can be triggered; the condition subtask can be used to judge whether the current event is Wednesday and December. If the condition is met, it can be decided to execute the operation behavior in the rule logic; the action subtask can be used to decide whether to execute the relevant operation behavior according to the output result of the condition subtask. In this embodiment, the trigger subtask, the condition subtask, and the action subtask can each contain multiple sub-logics, and the sub-logics can be logical relationships such as AND and OR. For example, in the previous example of the rule logic, the condition subtask contains two sub-logics: "whether the current time is Wednesday" and "whether the current event is December", and the two sub-logics are in an AND relationship. In this embodiment, the rule engine on the target device can perform operations such as adding, deleting, and modifying each sub-logic in each subtask of the to-be-processed rule task to maintain the rule logic of the to-be-processed rule task, and can synchronize the maintenance result to the standby device. Refer to Figure 2 , the rule logic maintenance result can be synchronized between the standby device and the target device through their communication components.
[0049] In addition, in this embodiment, the rule engine in the target device can determine the rule task to which the trigger subtask that monitors the corresponding trigger event belongs as the to-be-processed rule task. That is, when any trigger subtask in the rule engine monitors that the trigger event it is concerned about occurs, the rule engine can activate the rule task to which the trigger subtask belongs as the to-be-processed rule task. In practical applications, the activated rule task can be cached in the to-be-processed rule task queue. Of course, in the aforementioned distributed rule engine scenario, the trigger subtask may have been completed in other links, and the target device is assigned rule tasks that are already activatable. In this case, the rule engine in the target device does not need to execute the trigger subtask again, and the trigger subtask can be idled or deleted.
[0050] Moreover, in this embodiment, the subtasks distributed between the standby device and the target device generally do not include trigger subtasks, but mainly include conditional subtasks and behavioral subtasks. Moreover, during the distribution process of the subtasks, in this embodiment, the principle that tasks of the same rule are preferentially run on the same device can be followed. Therefore, in this embodiment, task identifiers can be configured for each subtask to reflect the association relationship between the subtasks, and the subtasks in the tasks of the same rule will have the same task identifier. In this embodiment, a processing location identifier can also be configured for each subtask respectively to indicate whether the subtask needs to be fixed on the target device for processing. That is to say, in this embodiment, according to actual needs, the processing location of each subtask can be specified to be fixed on the target device or the standby device. For example, if some subtasks must rely on the system data inside the target device, these subtasks can be specified to be fixed on the target device for processing; or, if some subtasks must rely on the operating environment of the standby device, these subtasks can be specified to be fixed on the standby device for processing, etc.
[0051] Based on this, in this embodiment, the rule engine running on the target device can distribute the conditional subtasks and behavioral subtasks to be processed to the target device and / or the standby device in units of subtasks according to the task distribution ratio. The following provides two exemplary distribution schemes in units of subtasks:
[0052] In an exemplary distribution scheme:
[0053] Calculate the ratio between the first type of rule tasks to be processed that do not need to be fixed on the target device for processing and the second type of rule tasks to be processed that need to be fixed on the target device for processing as the initial distribution ratio, where a single second type of rule task to be processed includes conditional subtasks and / or behavioral subtasks that need to be fixed on the target device for processing; if the initial distribution ratio is less than the task distribution ratio, then the first type of rule tasks to be processed and the first specified number of conditional subtasks and / or behavioral subtasks that do not need to be fixed on the target device for processing selected from the second type of rule tasks to be processed are handed over to the standby device for processing; where the first specified number is determined with the goal of adjusting the ratio between the number of subtasks distributed to the target device and the standby device to approach the task distribution ratio.
[0054] In this exemplary distribution scheme, the initial distribution ratio between the standby device and the target device can be characterized as:
[0055] U′ k =(N - N1) / N1
[0056] Where N represents the total number of rule tasks to be processed, N1 represents the number of the second type of rule tasks to be processed that need to be fixed on the target device for processing, and U k ’ represents the initial distribution ratio.
[0057] In this exemplary solution, the initial distribution scheme can be adjusted according to the magnitude relationship between the initial distribution ratio and the task distribution ratio calculated in step 101:
[0058] If the initial distribution ratio is less than the task distribution ratio, indicating that the amount of tasks initially distributed to the target device needs to be reduced, then the first type of to-be-processed rules and the first specified number of conditional subtasks and / or behavioral subtasks that do not need to be fixed on the target device and are selected from the second type of to-be-processed rules tasks can be handed over to the standby device for processing. Among them, the first specified number can be characterized as:
[0059] 2N1 - 2N / (1 + U k )
[0060] If the initial distribution ratio is greater than the task distribution ratio, then, taking the rule tasks as a unit, after selecting the second specified number of rule tasks from the first type of to-be-processed rule tasks, the remaining rule tasks in the first type of to-be-processed rule tasks are handed over to the standby device for processing; among them, the second specified number is determined with the goal of adjusting the ratio between the number of to-be-processed rule tasks distributed to the target device and the standby device to approach the task distribution ratio. In this case, directly taking the rule tasks as the adjustment unit mainly hopes to distribute the subtasks in the same rule task to the same device for processing. Among them, the second specified number can be characterized as:
[0061] N / (1 + U k ) - N1
[0062] Among them, if an integer cannot be calculated during the process of determining the first specified number and the second specified number above, a rounding operation can be performed to obtain the adjustment result. Through the task volume adjustment in the above two cases, the task volumes of the standby device and the target device can approach the task distribution ratio.
[0063] In another exemplary distribution scheme:
[0064] The ratio between the first type of subtasks that can be processed without being fixed to the target device and the second type of subtasks that need to be fixed to the target device is calculated as the initial distribution ratio, where both the first type of subtasks and the second type of subtasks include conditional subtasks and / or behavioral subtasks; if the initial distribution ratio is greater than the task distribution ratio, after selecting a third specified number of subtasks from the first type of subtasks, the remaining subtasks in the first type of subtasks are handed over to the standby device for processing; among them, the specified number of subtasks selected from the first type of subtasks preferably includes subtasks that have an associated relationship with any subtasks in the second type of subtasks; the third specified number is determined with the goal of making the ratio between the number of subtasks distributed to the target device and the standby device approach the task distribution ratio.
[0065] The difference between this exemplary distribution scheme and the previous exemplary distribution scheme lies in the different ways of defining the initial distribution ratio. In this exemplary distribution scheme, the initial distribution ratio is directly defined from the dimension of subtasks. Considering the principle of wanting to distribute the subtasks in the same rule task to the same device for processing, in this exemplary distribution scheme, during the process of reducing the subtasks initially distributed to the standby device, those subtasks that are in the same rule task as any subtasks initially distributed to the target device are preferentially selected to be redistributed to the target device, which enables the rule task to which the subtasks that need to be fixedly run on the target device belong to be processed as a whole by the target device.
[0066] In both of the above two exemplary distribution schemes, there are subtasks that need to be fixed to the target device for processing. In principle, this part of the subtasks will not be adjusted to be distributed to the standby device, and this may cause the distribution ratio generated after redistribution not to be exactly equal to the task distribution ratio calculated in step 101. It should be understood that in practical applications, this gap is acceptable.
[0067] Of course, the above two exemplary distribution schemes are exemplary. In this embodiment, other distribution schemes can also be used to determine the amount of tasks distributed to the target device and the standby device according to the task distribution ratio, which will not be enumerated here.
[0068] In this embodiment, after determining the subtasks that need to be distributed to the target device and the subtasks that need to be distributed to the standby device, the rule engine on the target device can provide the task information corresponding to the conditional subtasks and / or behavioral subtasks that need to be distributed to the standby device to the standby device, so that the standby device can call the relevant subtask rule logics from the rule logic library on it to process the relevant subtasks. Among them, the task information may include, but is not limited to, task identifiers, processing results of related subtasks that have been completed, input data, or timestamps, etc. Specifically, refer to Figure 2, the target device and the standby device can synchronize task information through their respective communication components. In addition to the target device providing task information to the standby device, the standby device may also need to provide task information to the target device. For example, if there are behavior subtasks associated with the conditional subtasks distributed to the standby device on the target device, the standby device needs to provide the task information of the conditional subtasks to the target device.
[0069] Accordingly, in this embodiment, a standby device can be configured for the target device running the rule engine, and the rule engine is also enhanced with the ability to distribute rule tasks. In this way, the rule tasks to be processed can be shared in the master-slave dual-machine mode. During the process of determining the sharing scheme, the load ratio between the standby device and the target device can be monitored; aiming to adjust the load ratio to a preset desired ratio, calculate the task distribution ratio between the standby device and the target device; and distribute the rule tasks to be processed to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the rule tasks to be processed proportionally. Accordingly, in this embodiment, the rule engine is optimized, and a standby device is introduced to help the target device share the rule task processing work, thereby effectively improving the stability and / or availability of the rule engine, and the utilization rate of the standby device in the rule task processing work can be improved from the dimension of the load ratio, and thus the processing efficiency of the rule tasks can be effectively improved.
[0070] It should be noted that in some of the processes described in the above embodiments and the accompanying drawings, there are multiple operations that appear in a specific order. However, it should be clearly understood that these operations can be executed not in the order in which they appear in this document or in parallel. The operation numbers such as 801 and 802 are only used to distinguish different operations, and the numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations can be executed sequentially or in parallel. It should be noted that the descriptions such as "first" and "second" in this document are used to distinguish different quantities, etc., and do not represent a sequence, nor do they limit that "first" and "second" are of different types.
[0071] Figure 3 This is a schematic structural diagram of a rule engine device provided for another exemplary embodiment of the present application. As Figure 3 shown, the rule engine device may include: a memory 30, a processor 31, and a communication component 32. Figure 3 The rule engine device shown can be used as Figure 2 the target device in
[0072] In this case, the processor 31 is coupled to the memory 30 and the communication component 32 and is used to execute the computer program in the memory 30 for:
[0073] In response to a task distribution instruction, monitor the load ratio between a standby device configured for a target device and the target device;
[0074] With the goal of adjusting the load ratio to a preset desired ratio, calculate the task distribution ratio between the standby device and the target device;
[0075] Distribute the to-be-processed rule tasks to the target device and / or the standby device according to the task distribution ratio, so that the target device and the standby device share the to-be-processed rule tasks proportionally.
[0076] In an optional embodiment, a single to-be-processed rule task includes a conditional subtask and an action subtask. When the processor 31 distributes the to-be-processed rule tasks to the target device and / or the standby device according to the task distribution ratio, it is used for:
[0077] Distribute the to-be-processed conditional subtasks and action subtasks to the target device and / or the standby device in units of subtasks according to the task distribution ratio.
[0078] In an optional embodiment, when the processor 31 distributes the to-be-processed conditional subtasks and action subtasks to the target device and / or the standby device, it is used for:
[0079] Calculate the ratio between the first type of to-be-processed rule tasks that do not need to be processed fixedly on the target device and the second type of to-be-processed rule tasks that need to be processed fixedly on the target device as the initial distribution ratio, where a single second type of to-be-processed rule task includes a conditional subtask and / or an action subtask that need to be processed fixedly on the target device;
[0080] If the initial distribution ratio is less than the task distribution ratio, hand over the first type of to-be-processed rule tasks and the first specified number of conditional subtasks and / or action subtasks that do not need to be processed fixedly on the target device selected from the second type of to-be-processed rule tasks to the standby device for processing;
[0081] Wherein, the first specified number is determined with the goal of making the ratio between the number of subtasks distributed to the target device and the standby device approach the task distribution ratio.
[0082] In an optional embodiment, the processor 31 is further used for:
[0083] If the initial distribution ratio is greater than the task distribution ratio, after selecting the second specified number of rule tasks from the first type of to-be-processed rule tasks in units of rule tasks, hand over the remaining rule tasks in the first type of to-be-processed rule tasks to the standby device for processing;
[0084] The second specified quantity is determined with the ratio between the number of to-be-processed rule tasks to be distributed to the target device and the standby device approaching the task distribution ratio as the adjustment target.
[0085] In an alternative embodiment, during the process of distributing the to-be-processed conditional subtasks and behavioral subtasks to the target device and / or the standby device, the processor 31 is configured to:
[0086] Calculate the ratio between the first type of subtasks that do not need to be processed fixedly on the target device and the second type of subtasks that need to be processed fixedly on the target device as the initial distribution ratio, where both the first type of subtasks and the second type of subtasks include conditional subtasks and / or behavioral subtasks;
[0087] If the initial distribution ratio is greater than the task distribution ratio, after selecting a third specified quantity of subtasks from the first type of subtasks, the remaining subtasks in the first type of subtasks are handed over to the standby device for processing;
[0088] Among them, the specified quantity of subtasks selected from the first type of subtasks preferably includes subtasks having an association relationship with any subtasks in the second type of subtasks.
[0089] In an alternative embodiment, during the process of handing over the conditional subtasks and / or behavioral subtasks to the standby device for processing, the processor 31 is configured to:
[0090] Provide the task information corresponding to the conditional subtasks and / or behavioral subtasks distributed to the standby device to the standby device through the communication component, so that the standby device can call the relevant subtask rule logic from the rule logic library thereon to process the relevant subtasks.
[0091] In an alternative embodiment, the task information includes one or more of a task identifier, the processing result of the relevant subtasks that have been processed, input data, and a timestamp.
[0092] In an alternative embodiment, the processor 31 is further configured to:
[0093] Pre-configure a processing location identifier for each subtask to indicate whether the subtask needs to be processed fixedly on the target device.
[0094] In an alternative embodiment, during the process of calculating the task distribution ratio between the standby device and the target device with the goal of adjusting the load ratio to a preset desired ratio, the processor 31 is configured to:
[0095] Adopt the PID control technology, use the monitored load ratio as the actual value, the desired ratio as the desired value, and the task distribution ratio as the control value; by introducing a proportional coefficient, an integral coefficient, and a differential coefficient, calculate the task distribution ratio between the standby device and the target device.
[0096] In an alternative embodiment, the single - rule task includes a trigger sub - task, and the processor 31 is further configured to:
[0097] Determine the rule task to which the trigger sub - task that monitors the corresponding trigger event belongs as the rule task to be processed.
[0098] In an alternative embodiment, when the processor 31 monitors the load ratio between the standby device configured for the target device and the target device, it is configured to:
[0099] Calculate the load metric corresponding to the target device, where the load metric is used to represent the load condition of the device;
[0100] Obtain the load metric corresponding to the standby device;
[0101] Take the ratio of the load metrics between the standby device and the target device as the load ratio.
[0102] Furthermore, as Figure 3 shown, the rule - engine device further includes: a power supply component 33 and other components. Figure 3 Only some components are schematically shown, and it does not mean that the rule - engine device only includes Figure 3 the components shown.
[0103] It should be noted that for the technical details in the above embodiments of the rule - engine device, reference can be made to the relevant descriptions of the rule engine running on the target device in the foregoing method embodiments. To save space, they will not be repeated here, but this should not cause loss of the protection scope of this application.
[0104] In addition, Figure 3 the rule - engine device shown can also be used as Figure 2 the standby device configured for the target device in Figure 3 In this case, the processor in Figure 3 can be used to execute technical logics such as load metric calculation and sub - task processing mentioned in the foregoing method embodiments, and the communication component in
[0105] can be used to synchronize task information, load metrics, etc. to the target device. For the relevant technical details, reference can be made to the relevant descriptions of the standby device in the foregoing method embodiments. To save space, they will not be repeated here, but this should not cause loss of the protection scope of this application.
[0106] Correspondingly, an embodiment of the present application further provides a computer - readable storage medium storing a computer program, and when the computer program is executed, it can implement the steps that can be executed by the rule - engine device in the above - mentioned method embodiments. Figure 3The memory therein is used to store computer programs and can be configured to store various other data to support operations on the computing platform. Examples of such data include instructions for any application or method operating on the computing platform, contact data, phone book data, messages, pictures, videos, etc. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disks or optical discs.
[0107] The above Figure 3 The communication component therein is configured to facilitate communication, in a wired or wireless manner, between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G / LTE, 5G and other mobile communication networks, or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component further includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0108] The above Figure 3 The power component therein provides power to various components of the device where the power component is located. The power component can include a power management system, one or more power sources, and other components associated with generating, managing and distributing power for the device where the power component is located.
[0109] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0110] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, as well as the combination of flows and / or blocks in the flowchart and / or block diagram. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing device generate means for implementing the specified functions in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the specified functions in one or more of the blocks.
[0111] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means for implementing the specified functions in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the specified functions in one or more of the blocks.
[0112] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the specified functions in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the specified functions in one or more of the blocks.
[0113] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0114] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash RAM. The memory is an example of computer-readable media.
[0115] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0116] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0117] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.
Claims
1. A method for adjusting a rule engine, where the rule engine runs on a target device, and the method includes: Responding to a task distribution instruction, monitoring the load ratio between a standby device configured for the target device and the target device; Taking the adjustment of the load ratio to a preset desired ratio as the goal, calculating the task distribution ratio between the standby device and the target device; According to the task distribution ratio, taking subtasks as the distribution unit, distributing the conditional subtasks and action subtasks included in the to-be-processed rule task to the target device and / or the standby device, so that the target device and the standby device share the to-be-processed rule task proportionally; Distributing the conditional subtasks and action subtasks included in the to-be-processed rule task to the target device and / or the standby device includes: Calculating the ratio between the first type of to-be-processed rule tasks that do not need to be fixed on the target device and the second type of to-be-processed rule tasks that need to be fixed on the target device as the initial distribution ratio, where a single second type of to-be-processed rule task includes conditional subtasks and / or action subtasks that need to be fixed on the target device; If the initial distribution ratio is less than the task distribution ratio, handing over the first type of to-be-processed rules and the first specified number of conditional subtasks and / or action subtasks that do not need to be fixed on the target device selected from the second type of to-be-processed rule tasks to the standby device for processing; Wherein, the first specified number is determined with the goal of making the ratio between the number of subtasks distributed to the target device and the standby device approach the task distribution ratio.
2. The method according to claim 1, further including: If the initial distribution ratio is greater than the task distribution ratio, after selecting the second specified number of rule tasks from the first type of to-be-processed rule tasks in units of rule tasks, handing over the remaining rule tasks in the first type of to-be-processed rule tasks to the standby device for processing; Wherein, the second specified number is determined with the goal of making the ratio between the number of to-be-processed rule tasks distributed to the target device and the standby device approach the task distribution ratio.
3. The method according to claim 1, distributing the conditional subtasks and action subtasks included in the to-be-processed rule task to the target device and / or the standby device includes: Calculating the ratio between the first type of subtasks that do not need to be fixed on the target device and the second type of subtasks that need to be fixed on the target device as the initial distribution ratio, where both the first type of subtasks and the second type of subtasks include conditional subtasks and / or action subtasks; If the initial distribution ratio is greater than the task distribution ratio, after selecting the third specified number of subtasks from the first type of subtasks, handing over the remaining subtasks in the first type of subtasks to the standby device for processing; Among them, the specified number of subtasks selected from the first type of subtasks preferably includes subtasks having an associated relationship with any subtask in the second type of subtasks; the third specified number is determined with the goal of adjusting the ratio between the number of subtasks distributed to the target device and the standby device to approach the task distribution ratio.
4. The method according to any one of claims 1-3, the process of handing the conditional subtask and / or the behavioral subtask to the standby device includes: Providing the task information corresponding to the conditional subtask and / or the behavioral subtask distributed to the standby device to the standby device, so that the standby device can call the relevant subtask rule logic from the rule logic library thereon to process the relevant subtasks.
5. The method according to claim 4, the task information includes one or more of a task identifier, the processing result of the relevant subtask that has been processed, input data, and a timestamp.
6. The method according to claim 1, further includes: Pre-configuring a processing location identifier for each subtask to indicate whether the subtask needs to be fixed for processing on the target device.
7. The method according to claim 1, the calculating the task distribution ratio between the standby device and the target device with the goal of adjusting the load ratio to a preset desired ratio includes: Adopting the PID control technology, using the monitored load ratio as the actual value, the desired ratio as the desired value, and the task distribution ratio as the control value; Calculating the task distribution ratio between the standby device and the target device by introducing a proportional coefficient, an integral coefficient, and a differential coefficient.
8. The method according to claim 1, the single rule task includes a trigger subtask, the method further includes: Determining the rule task to which the trigger subtask that monitors the corresponding trigger event belongs as the rule task to be processed.
9. The method according to claim 1, the monitoring the load ratio between the standby device configured for the target device and the target device includes: Calculating the load index corresponding to the target device, the load index is used to represent the load condition of the device; Obtaining the load index corresponding to the standby device; Taking the ratio of the load indexes between the standby device and the target device as the load ratio.
10. A rule engine device, including a memory, a processor, and a communication component; The memory is used to store one or more computer instructions; The processor is coupled to the memory and the communication component, and is used to execute the one or more computer instructions to execute the adjustment method of the rule engine according to any one of claims 1-9.
11. A computer-readable storage medium storing computer instructions, when the computer instructions are executed by one or more processors, causing the one or more processors to execute the adjustment method of the rule engine according to any one of claims 1-9.
Citation Information
Patent Citations
Background management device with project backup function
CN105162617A
Load balancing configuration method and device
CN110430278A
Rule task execution method and device and storage medium
CN113485774A
Self-adaptive task scheduling method and device for distributed rule engine and electronic equipment
CN114327807A