Rule engine system and method

By designing a rule engine system, including rule analysis, network optimization, fact management and monitoring modules, the performance bottleneck problem of the Drools rule engine when dealing with a large number of complex rules is solved, and efficient rule matching, optimize memory management and strengthen dynamic rule update capabilities are achieved.

CN119940340APending Publication Date: 2025-05-06SHANGHAI HANSHUO ZHIRONG INFORMATION TECHNOLOGY TECHNOLOGY CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510024180.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The Drools rule engine has performance bottlenecks when processing a large number of complex rules, resulting in too long response time and excessive resource consumption, and insufficient dynamic rule update capabilities.

Method used

A rule engine system is designed, including rule analysis module, network optimization module, fact management module, rule execution module and monitoring module. Through syntax and semantic analysis, rule network construction, fact data management and dynamic optimization measures, the rule matching efficiency and memory management are improved, and the dynamic rule update capability is enhanced.

Benefits of technology

Improve rule matching efficiency, optimize memory management, enhance dynamic rule update capabilities, and improve overall system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119940340A_ABST
    Figure CN119940340A_ABST
Patent Text Reader

Abstract

The invention relates to a rule engine system and method. The method comprises the following steps: receiving a rule file, carrying out grammar and semantic analysis and verification on the rule file, and loading the rule file into a memory; the analyzed rule file is analyzed and recombined through the logic relation between the rules, and a rule network is constructed; obtaining the fact data from the external module, and analyzing the fact data to obtain the analyzed fact data; comparing the analyzed fact data with a rule in a rule network to obtain a corresponding rule, and executing a corresponding process according to rule definition; through collecting operation data and performance indexes of the rule analysis module, the network optimization module, the fact management module and the rule execution module, an operation state is analyzed according to the operation data and the performance indexes, existing problems and performance bottlenecks are determined, and corresponding optimization measures are taken. The method has the advantages of improving the rule matching efficiency, optimizing memory management, enhancing the dynamic rule updating capability and improving the overall performance of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet technology applications, and in particular to a rule engine system and method. Background Art

[0002] At present, there are many rule engines on the market, among which the Drools rule engine has attracted much attention for its powerful functions and flexibility. However, the traditional algorithms used by the Drools rule engine have gradually exposed some performance bottlenecks when facing large-scale rule sets and massive data. For example, when dealing with complex rule conditions, the rule matching efficiency may be significantly reduced, resulting in longer system response time; in terms of memory management, with the continuous increase of rules and fact data, the memory usage may be too high, affecting the stability and scalability of the system; in addition, the support for dynamic rule updates needs to be further improved to meet the needs of rapidly changing business.

[0003] In the prior art, when the Drools rule engine processes a large number of complex rules, performance bottlenecks may occur, resulting in problems such as long response time and high resource consumption.

[0004] At present, in the prior art, the Drools rule engine will encounter performance bottlenecks when processing a large number of complex rules, resulting in long response time and high resource consumption. No effective solution has been proposed yet. Summary of the invention

[0005] The purpose of the present invention is to provide a rule engine system and method to address the deficiencies in the prior art, so as to solve the technical problems in the prior art that the Drools rule engine may encounter performance bottlenecks when processing a large number of complex rules, resulting in long response time and high resource consumption.

[0006] To achieve the above object, the technical solution adopted by the present invention is:

[0007] The present invention provides a rule engine system, comprising: a rule parsing module, a network optimization module, a fact management module, a rule execution module, a monitoring module and an external module, wherein the rule parsing module is used to receive a rule file, parse and verify the rule file at the syntax and semantic levels, and load it into a memory; the network optimization module is used to analyze and reorganize the parsed rule file through the logical relationship between the rules to construct a rule network; the fact management module is used to obtain fact data from an external module, parse the fact data through the rule parsing module to obtain the parsed fact data; the rule execution module is used to compare the parsed fact data with the rules in the rule network to obtain the corresponding rules, and execute the corresponding process according to the rule definition; the monitoring module is used to collect the operation data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyze the operation status according to the operation data and performance indicators, determine the existing problems and performance bottlenecks, and take corresponding optimization measures.

[0008] Optionally, the rule parsing module includes: a syntax parsing unit, a semantic checking unit and a rule loading unit, wherein the syntax parsing unit is used to perform lexical analysis and syntax analysis on the rule file, convert the text form of the parsed rule file into a target format, and obtain a rule file in the target format; the semantic checking unit is used to perform semantic checking on the rule file in the target format, obtain a rule file after semantic checking, and verify the type compatibility of operators and operands of the rule file after semantic checking, and check the rationality of logical expressions of the rule file after semantic checking, to obtain a checked rule file; wherein the semantic checking includes: checking the definition and scope of variables; the rule loading unit is used to classify and store the checked rule file according to the attributes of the rules, and store them in the memory.

[0009] Optionally, the network optimization module includes: a pattern analysis unit, a clustering optimization unit and an index construction unit, wherein the pattern analysis unit is used to analyze the parsed rule file and identify the pattern corresponding to the parsed rule file; the clustering optimization unit is used to cluster rules with similar patterns according to the pattern using a preset clustering algorithm to obtain clustered rules, and generate a rule network based on the clustered rules; the index construction unit is used to construct an index structure based on key attributes of the rules in the rule network or the positional relationship of the rules in the rule network.

[0010] Optionally, the fact management module includes: a data source connection unit, a data cache unit and an incremental update unit, wherein the data source connection unit is used to communicate and read data with the data source through a preset connection interface and driver; the data cache unit is used to store the fact data obtained from the data source using a corresponding cache strategy; the incremental update unit is used to monitor changes in the fact data in real time, and when the data in the data source changes, only the changed part is obtained and processed.

[0011] Optionally, the rule execution module includes: a matching unit, an execution unit and a result processing unit, wherein the matching unit is used to match the fact data with the rules in the rule network, and compare the variable values ​​in the fact data with the conditional expressions according to the conditional part of the rules; the execution unit is used to execute the corresponding operation process according to the rules when the matching unit obtains the rules that meet the conditions; the result processing unit is used to process and feedback the results of the rule execution, store the results in a specified location, and transmit the results to the corresponding module.

[0012] Optionally, the monitoring module includes: a performance monitoring unit, an analysis and evaluation unit, and an optimization and adjustment unit, wherein the performance monitoring unit is used to collect performance data of each key node and module in real time, including: rule matching time, rule execution time, memory usage, CPU usage, data transmission rate, and data source connection response time; the analysis and evaluation unit is used to analyze and evaluate the collected performance data to determine whether the performance status of the system is normal and whether there are performance bottlenecks or potential risks; the optimization and adjustment unit is used to know and implement corresponding optimization strategies according to the analysis results of the analysis and evaluation unit, wherein the optimization strategies include: adjusting algorithm parameters, optimizing data structure, and improving the interaction process between modules.

[0013] Further, optionally, the monitoring module includes: an analysis and evaluation unit, which is also used to set thresholds according to business requirements and performance indicators, and when the performance data is greater than the threshold, an alarm is issued, wherein the alarm is used to indicate that there is a problem with the system.

[0014] Optionally, the monitoring module includes: an optimization and adjustment unit, which is also used to adjust the clustering algorithm parameters or index building strategy in the network optimization module; if the memory usage is too high, adjust the cache elimination strategy in the fact management module or optimize the memory allocation method in the rule execution module.

[0015] The present invention provides an application method based on a rule engine system, which is applied to the rule engine system, including: receiving a rule file, parsing and verifying the rule file at the syntax and semantic levels, and loading it into a memory; analyzing and reorganizing the parsed rule file through the logical relationship between the rules to construct a rule network; acquiring fact data from an external module, parsing the fact data, and obtaining the parsed fact data; comparing the parsed fact data with the rules in the rule network to obtain the corresponding rules, and executing the corresponding process according to the rule definition; collecting the operation data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyzing the operation status according to the operation data and the performance indicators, determining the existing problems and performance bottlenecks, and taking corresponding optimization measures.

[0016] Optionally, parsing and verifying the rule file at the syntax and semantic levels and loading it into the memory includes: performing lexical analysis and syntax analysis on the rule file, converting the text form of the parsed rule file into the target format, and obtaining a rule file in the target format; performing semantic checking on the rule file in the target format to obtain a rule file after the semantic check, and verifying the type compatibility of operators and operands of the rule file after the semantic check, and checking the rationality of the logical expressions of the rule file after the semantic check to obtain a checked rule file; wherein the semantic check includes: checking the definition and scope of variables; and classifying and storing the checked rule file according to the attributes of the rules and storing it in the memory.

[0017] The present invention adopts the above technical scheme, by receiving a rule file, parsing and verifying the rule file at the grammatical and semantic levels, and loading it into the memory; analyzing and reorganizing the parsed rule file through the logical relationship between the rules to construct a rule network; obtaining fact data from an external module, parsing the fact data, and obtaining parsed fact data; comparing the parsed fact data with the rules in the rule network to obtain corresponding rules, and executing corresponding processes according to the rule definitions; by collecting the operating data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyzing the operating status according to the operating data and performance indicators, determining the existing problems and performance bottlenecks, and taking corresponding optimization measures, compared with the prior art, it has the following technical effects: improving rule matching efficiency, optimizing memory management, enhancing dynamic rule updating capabilities, and improving the overall performance of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 is a schematic diagram of a rule engine system according to an embodiment of the present invention;

[0019] Figure 2is a schematic diagram of data processing in a rule engine system according to an embodiment of the present invention;

[0020] Figure 3 It is a flowchart of an application method based on a rule engine system according to an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0022] Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. In addition, it can also be understood that although the efforts made in this development process may be complicated and lengthy, for ordinary technicians in this field related to the content disclosed in this application, some changes in design, manufacturing or production based on the technical content disclosed in this application are just conventional technical means, and should not be understood as insufficient content disclosed in this application.

[0023] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0024] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or units (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" / "several" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0025] Example 1

[0026] An exemplary embodiment of the present invention is as follows Figure 1 As shown, Figure 1 is a schematic diagram of a rule engine system according to an embodiment of the present invention; a rule engine system provided by an embodiment of the present application includes:

[0027] The rule parsing module 11, the network optimization module 12, the fact management module 13, the rule execution module 14, the monitoring module 15 and the external module 16, wherein the rule parsing module 11 is used to receive the rule file, parse and verify the rule file at the syntax and semantic level, and load it into the memory; the network optimization module 12 is connected to the rule parsing module 11, and is used to analyze and reorganize the parsed rule file through the logical relationship between the rules to construct a rule network; the fact management module 13 is connected to the rule parsing module 11 and the external module 16 respectively, and is used to obtain fact data from the external module 16, parse the fact data through the rule parsing module 11, and obtain the solution. The analyzed fact data; the rule execution module 14 is connected to the network optimization module 12 and the fact management module 13 respectively, and is used to compare the analyzed fact data with the rules in the rule network to obtain the corresponding rules, and execute the corresponding process according to the rule definition; the monitoring module 15 is connected to the rule analysis module 11, the network optimization module 12, the fact management module 13 and the rule execution module 14 respectively, and is used to collect the operation data and performance indicators of the rule analysis module 11, the network optimization module 12, the fact management module 13 and the rule execution module 14, analyze the operation status according to the operation data and performance indicators, determine the existing problems and performance bottlenecks, and take corresponding optimization measures.

[0028] Optionally, the rule parsing module 11 includes: a syntax parsing unit, a semantic checking unit and a rule loading unit, wherein the syntax parsing unit is used to perform lexical analysis and syntax analysis on the rule file, convert the text form of the parsed rule file into a target format, and obtain a rule file in the target format; the semantic checking unit is used to perform semantic checking on the rule file in the target format to obtain a rule file after semantic checking, and verify the type compatibility of operators and operands of the rule file after semantic checking, and check the rationality of logical expressions of the rule file after semantic checking to obtain a checked rule file; wherein the semantic checking includes: checking the definition and scope of variables; the rule loading unit is used to classify and store the checked rule file according to the attributes of the rules, and store them in the memory.

[0029] Optionally, the network optimization module 12 includes: a pattern analysis unit, a clustering optimization unit and an index construction unit, wherein the pattern analysis unit is used to analyze the parsed rule file and identify the pattern corresponding to the parsed rule file; the clustering optimization unit is used to cluster rules with similar patterns according to the pattern using a preset clustering algorithm to obtain clustered rules, and generate a rule network based on the clustered rules; the index construction unit is used to construct an index structure based on key attributes of the rules in the rule network or the positional relationship of the rules in the rule network.

[0030] Optionally, the fact management module 13 includes: a data source connection unit, a data cache unit and an incremental update unit, wherein the data source connection unit is used to communicate and read data with the data source through a preset connection interface and driver; the data cache unit is used to store the fact data obtained from the data source using a corresponding cache strategy; the incremental update unit is used to monitor changes in the fact data in real time, and when the data in the data source changes, only the changed part is obtained and processed.

[0031] Optionally, the rule execution module 14 includes: a matching unit, an execution unit and a result processing unit, wherein the matching unit is used to match the fact data with the rules in the rule network, and compare the variable values ​​in the fact data with the conditional expressions according to the conditional part of the rules; the execution unit is used to execute the corresponding operation process according to the rules when the matching unit obtains the rules that meet the conditions; the result processing unit is used to process and feedback the results of the rule execution, store the results in a specified location, and transmit the results to the corresponding module.

[0032] Optionally, the monitoring module 15 includes: a performance monitoring unit, an analysis and evaluation unit, and an optimization and adjustment unit, wherein the performance monitoring unit is used to collect performance data of each key node and module in real time, including: rule matching time, rule execution time, memory usage, CPU usage, data transmission rate, and data source connection response time; the analysis and evaluation unit is used to analyze and evaluate the collected performance data to determine whether the performance status of the system is normal and whether there are performance bottlenecks or potential risks; the optimization and adjustment unit is used to know and implement corresponding optimization strategies according to the analysis results of the analysis and evaluation unit, wherein the optimization strategies include: adjusting algorithm parameters, optimizing data structures, and improving the interaction process between modules.

[0033] Further, optionally, the monitoring module 15 includes: an analysis and evaluation unit, which is also used to set thresholds according to business requirements and performance indicators, and issue an alarm when the performance data is greater than the threshold, wherein the alarm is used to indicate that there is a problem with the system.

[0034] Optionally, the monitoring module 15 includes: an optimization and adjustment unit, which is also used to adjust the clustering algorithm parameters or index construction strategy in the network optimization module 12; if the memory usage is too high, adjust the cache elimination strategy in the fact management module 13 or optimize the memory allocation method in the rule execution module 14.

[0035] In summary, the rule engine system provided in the embodiment of the present application is as follows: Figure 1 As shown, the details are as follows:

[0036] The rule parsing module 11 is responsible for receiving the rule files input from the outside, parsing and verifying them at the syntax and semantic level to ensure the correctness and validity of the rules. The parsed rules are converted into a format that can be processed by the system and loaded into the memory to provide basic data for the subsequent rule processing process.

[0037] Specifically, in terms of syntax parsing, it identifies various elements in the rules, such as conditions, actions, variables, operators, etc., and constructs the corresponding syntax structure representation. Semantic verification checks the logical rationality of the rules, such as whether variables are defined and whether operators are used correctly. When loading rules, reasonable memory layout is performed based on the characteristics of the rules (such as priority, type, etc.) for fast retrieval and use.

[0038] In the embodiment of the present application, the rule parsing module 11 includes: a syntax parsing unit, a semantic checking unit and a rule loading unit, wherein:

[0039] The syntax parsing unit performs lexical analysis and syntax analysis on the rule file, and converts the textual rules into an abstract syntax tree (AST) or other suitable intermediate representation (i.e., the target format in the embodiment of the present application). For example, for the rule "IF customer.age>18AND customer.balance>1000THEN offer.discount=0.1", it will identify the condition part (customer.age>18AND customer.balance>1000) and the action part (offer.discount=0.1), and construct the corresponding syntax structure, in which nodes represent rule elements and edges represent the relationship between elements.

[0040] The semantic checking unit performs semantic checking on the rules (i.e., the rule files in the target format in the embodiment of the present application) based on the result of the syntax parsing (i.e., the rule files in the target format in the embodiment of the present application). This includes checking the definition and scope of variables to ensure that the variables have been correctly defined before use; verifying the type compatibility of operators and operands, such as using the correct numerical comparison operator when comparing numerical variables; and checking the rationality of logical expressions, such as preventing logical contradictions or incomplete logical expressions.

[0041] The rule loading unit loads the rules after syntax parsing and semantic verification into the rule storage area in the memory. The rules (i.e., the rule files after inspection in the embodiment of the present application) are classified and stored according to the priority of the rules, applicable scenarios and other attributes, and data storage methods such as hash tables and index structures may be used to quickly locate and obtain the required rules during subsequent rule matching and execution. For example, high-priority security-related rules are stored in a memory location that is easy to access quickly to ensure timely response in critical business scenarios.

[0042] The rule parsing module 11 and the external module 16 receive the rule file. The external module 16 may be a file system, a configuration management system or other components that provide a rule source.

[0043] The rule parsing module 11 provides the parsed and loaded rules to the network optimization module 12 to provide basic data for building a rule network. At the same time, when the rule execution module 14 needs to execute the rules, it provides accurate rule content for it. The rule parsing module 11 also interacts with the monitoring module 15. The monitoring module 15 can monitor the parsing and loading performance of the rule parsing module 11, such as parsing time, loading efficiency, etc., and provide optimization suggestions based on the monitoring results, such as optimizing the syntax parsing algorithm or adjusting the rule loading strategy.

[0044] The network optimization module 12 builds an optimized rule network structure based on the rules provided by the rule parsing module 11 to improve the efficiency of rule matching. By analyzing and reorganizing the logical relationship between the rules, the search space and the amount of calculation in the rule matching process are reduced, and the memory usage is optimized to ensure that the rule network can run efficiently during operation and adapt to the processing requirements of large-scale rule sets and complex business logic.

[0045] In the embodiment of the present application, the network optimization module 12 includes: a pattern analysis unit, a clustering optimization unit and an index construction unit, wherein:

[0046] The pattern analysis unit conducts an in-depth analysis of the patterns of the rules (i.e., the rule files after parsing in the embodiment of the present application) to identify the conditional patterns, variable combination patterns, etc. (i.e., the patterns in the embodiment of the present application) that appear repeatedly in the rules. For example, if multiple rules involve conditional judgments on customer age and account balance, the pattern analysis unit will identify this pattern. By analyzing the patterns, the inherent connections and commonalities between the rules can be discovered, providing a basis for subsequent clustering and optimization.

[0047] The cluster optimization unit uses a clustering algorithm (i.e., a preset clustering algorithm in the embodiment of the present application) to cluster rules with similar patterns according to the results of the pattern analysis (i.e., the pattern in the embodiment of the present application). In this way, when matching rules, the corresponding cluster can be searched first, rather than traversing the entire rule set, which greatly narrows the search scope. For example, all rules related to customer credit assessment are clustered into one group. When processing customer credit-related business, only matching rules need to be found in the cluster, which improves the matching speed.

[0048] The index building unit builds a suitable index structure for the optimized rule network to quickly locate and access the rules. The index can be built based on the key attributes of the rules (such as the type of rule, the main variables involved, etc.) or the position relationship of the rules in the network. For example, a fast index is built for frequently used high-priority rules so that these rules can be quickly located during the rule matching process, reducing search time, while improving memory access efficiency and optimizing memory management.

[0049] The network optimization module 12 relies on the rule data provided by the rule parsing module 11 (i.e., the parsed rule file in the embodiment of the present application) to obtain detailed information of the rules (i.e., the parsed rule file in the embodiment of the present application) to perform pattern analysis and network construction.

[0050] The network optimization module 12 works in conjunction with the fact management module 13 to further optimize the rule network structure according to the characteristics and access patterns of the fact data. For example, according to the variable types and value ranges that often appear in the fact data, the clustering method and index structure in the rule network are adjusted to improve the matching efficiency between the rules and the fact data.

[0051] The network optimization module 12 provides the constructed optimized rule network to the rule execution module 14, and the rule execution module 14 uses the rule network structure to perform efficient rule search and matching operations when performing rule matching. At the same time, according to the execution results and performance data fed back by the rule execution module 14, the network optimization module 12 can further optimize the rule network, such as dynamically adjusting the clustering strategy or index structure.

[0052] The fact management module 13 is responsible for interacting with external data sources, obtaining fact data, and effectively managing and preprocessing the fact data to meet the rule engine system's demand for fact data during rule matching and execution. This includes operations such as data access, caching, and updating to ensure the timeliness, accuracy, and efficient availability of fact data, while optimizing memory usage and improving overall system performance.

[0053] In the embodiment of the present application, the fact management module 13 includes: a data source connection unit, a data cache unit and an incremental update unit, wherein:

[0054] The data source connection unit provides connection interfaces and drivers (i.e., the preset connection interfaces and drivers in the embodiments of the present application) with various external data sources (such as databases, file systems, message queues, sensors, etc.) to achieve communication with the data source and data reading. For example, for a database data source, it is possible to execute SQL query statements to obtain the required data; for a message queue, it is possible to subscribe to and receive real-time pushed data. The data source connection unit is responsible for establishing a stable and reliable connection, handling abnormal situations in the connection, and obtaining relevant factual data from different data sources according to system requirements.

[0055] The data cache unit performs cache management on the factual data obtained from the data source and adopts appropriate cache strategies (such as time-based expiration strategies, usage frequency-based elimination strategies, etc.) to improve data access speed. The cached data structure can be a hash table, in-memory database, etc., to facilitate fast search and retrieval. For example, for frequently accessed basic customer information data, it is cached in memory. When the data is needed for rule execution, it is directly obtained from the cache, reducing repeated queries to the data source, improving system response speed, and optimizing memory usage to avoid excessive memory resource occupation by cached data.

[0056] The incremental update unit monitors the changes of fact data in real time. When the data in the data source is updated, only the changed part of the data is obtained and processed instead of reloading the entire data set. For example, when a field of a customer record in the database is updated, the incremental update unit can detect the change and only update the updated field value to the corresponding fact data in the system, reducing the amount of data processing and network transmission overhead, improving the efficiency of data update, ensuring that the fact data based on which the rule execution is based is always the latest, and also helping to optimize memory management and avoid unnecessary memory operations.

[0057] The fact management module 13 is connected with external data sources, and establishes connections with various external data sources through a data source connection unit to obtain fact data.

[0058] The fact management module 13 provides the necessary fact data for the rule parsing module 11 so as to perform semantic verification during the rule parsing process, such as checking whether the key words "IF" and "THEN" used in the rules are used correctly and whether the variables have corresponding actual values ​​in the fact data.

[0059] The fact management module 13 provides the processed fact data to the rule execution module 14 for condition judgment and action execution during rule execution. The rule execution module 14 matches and executes operations based on the fact data and the rule network, and feeds back the execution results to the fact management module 13. The fact management module 13 may update the cache data or adjust the cache strategy based on the execution results. At the same time, the fact management module 13 cooperates with the monitoring module 15 to monitor the usage of fact data and cache performance, and optimizes according to the monitoring results, such as adjusting the cache size, updating the strategy, etc.

[0060] The rule execution module 14 is the core execution unit of the rule engine system in the embodiment of the present application, and is responsible for performing rule matching and action execution operations according to the fact data provided by the fact management module 13 and the rule network constructed by the network optimization module 12. In the rule matching process, the fact data is compared with the rules in the rule network to find the rules that meet the conditions, and the corresponding actions are executed according to the rule definition, such as updating data, triggering events, calling external services, etc., to finally realize the automated processing of business logic and promote the operation of the system and the advancement of business processes.

[0061] In the embodiment of the present application, the rule execution module 14 includes: a matching unit, an execution unit and a result processing unit, wherein:

[0062] The matching unit is responsible for matching the fact data with the rules in the rule network, traversing the rule network, and comparing the variable values ​​in the fact data with the conditional expression according to the conditional part of the rule. For example, for the rule "IFcustomer.age>18AND customer.balance>1000THEN offer.discount=0.1", the matching unit will obtain the values ​​of customer.age and customer.balance from the fact data and compare them with the conditional expression. Efficient matching algorithms (such as index-based search, pattern matching algorithms, etc.) are used to improve the matching speed and reduce the matching time, ensuring that matching rules can be found quickly in the environment of large-scale rule sets and massive fact data.

[0063] The execution unit is responsible for executing the action part of the rule after the matching unit finds a rule that meets the conditions. According to the action defined by the rule, such as updating data in the database, sending messages, calling the interface of other systems, etc., the corresponding operation is performed. The execution unit needs to ensure the accurate execution of the action, handle abnormal situations during the execution process, and interact effectively with other components in the system (such as database systems, message systems, etc.). For example, if the rule action is to update the status of a customer order, the execution unit will interact with the database of the order management system and execute the corresponding SQL update statement.

[0064] The result processing unit processes and feeds back the result of the rule execution, and stores the execution result in a specified location (such as a database, log file, etc.) for subsequent query and analysis. At the same time, the execution result is passed to other related modules in the system, such as the monitoring module 15 for performance analysis, or returned to the user interface for displaying the execution result to the user. For example, in an e-commerce system, the rule execution result may be the calculation result of the order discount. The result processing unit updates the result to the order information, feeds it back to the front-end interface to display it to the user, and records it in the log file for the system administrator to view and analyze.

[0065] The rule execution module 14 obtains the latest fact data from the fact management module 13 as the basis for rule matching. The accuracy and timeliness of the fact data provided by the fact management module 13 directly affect the correctness and effectiveness of rule execution.

[0066] The rule execution module 14 uses the rule network constructed by the network optimization module 12 to perform rule matching operations. The structure and optimization degree of the rule network determine the efficiency of rule matching. The rule execution module 14 adopts a suitable matching algorithm according to the characteristics of the rule network. At the same time, the execution performance data (such as matching time, execution success rate, etc.) of the rule execution module 14 is fed back to the network optimization module 12 so that it can further optimize the rule network.

[0067] The rule execution module 14 provides the process data of rule execution (such as the number of matched rules, execution time, execution results, etc.) to the monitoring module 15, which analyzes the process data, evaluates the performance of the rule execution module, finds potential performance bottlenecks and problems, and provides optimization suggestions, such as adjusting the matching algorithm, optimizing the execution process, etc. The rule execution module 14 makes corresponding improvements and optimizations based on the feedback from the monitoring module 15 to improve execution efficiency and accuracy.

[0068] The monitoring module 15 performs real-time monitoring, performance evaluation and optimization and adjustment of the operation process of the entire rule engine system. By collecting the operation data and performance indicators of each module (such as the rule parsing module 11, the network optimization module 12, the fact management module 13, and the rule execution module 14), the system's operating status is analyzed, potential problems and performance bottlenecks are discovered, and corresponding optimization measures are taken, such as adjusting algorithm parameters, optimizing data structures, and improving the interaction process between modules, so as to ensure that the system always maintains an efficient and stable operating state and continuously improves the system's overall performance and business processing capabilities.

[0069] In the embodiment of the present application, the monitoring module 15 includes: a performance monitoring unit, an analysis and evaluation unit, and an optimization and adjustment unit, wherein:

[0070] The performance monitoring unit is responsible for real-time collection of performance data of each key node and module of the system, including but not limited to rule matching time, rule execution time, memory usage, CPU usage, data transmission rate, data source connection response time, etc. For example, by embedding a timer in the rule execution module 14 to record the start and end time of rule execution, the rule execution time is obtained; the current memory usage and memory allocation are obtained through the memory management interface of the rule engine system in the embodiment of the present application. The performance monitoring unit collects and records the above data at a certain frequency (such as per second, per minute, etc.) to provide a data basis for subsequent performance analysis.

[0071] The analysis and evaluation unit conducts in-depth analysis and evaluation of the data collected by the performance monitoring unit, and uses data analysis techniques (such as statistical analysis, trend analysis, comparative analysis, etc.) to determine whether the system's performance is normal and whether there are performance bottlenecks or potential risks. For example, by comparing the average and standard deviation of rule matching time in different time periods, it can be determined whether the rule matching efficiency is stable; analyze the trend of memory usage to predict whether insufficient memory may occur. The analysis and evaluation unit can also set thresholds based on business needs and performance indicators, and issue an alarm when performance data exceeds the threshold, indicating that there may be problems with the system.

[0072] The optimization and adjustment unit formulates and implements corresponding optimization strategies based on the results of the analysis and evaluation unit. The optimization strategy may include adjusting algorithm parameters (such as search depth in the rule matching algorithm, cache size in the cache strategy, etc.), optimizing data structure (such as improving the storage structure of the rule network, the cache structure of the fact data, etc.), and improving the interaction process between modules (such as optimizing the data transmission method between the rule parsing module 11 and the network optimization module 12, the data synchronization mechanism between the fact management module 13 and the rule execution module 14, etc.). For example, if the analysis finds that the rule matching time is too long due to the unreasonable rule network structure, the optimization and adjustment unit may adjust the clustering algorithm parameters or index construction strategy in the network optimization module 12 to improve the rule matching efficiency; if the memory usage is too high, the cache elimination strategy in the fact management module 13 may be adjusted or the memory allocation method in the rule execution module 14 may be optimized.

[0073] The monitoring module 15 obtains performance data such as rule parsing time and rule loading time from the rule parsing module 11, and monitors the efficiency of the parsing and loading process of the rule parsing module 11. Based on the analysis results, optimization suggestions may be provided to the rule parsing module 11, such as optimizing the syntax parsing algorithm, adjusting the rule loading order, etc., to improve the initial speed of rule processing.

[0074] The connection between the monitoring module 15 and the network optimization module 12: obtain the rule network construction time, the structural characteristics of the rule network (such as the number of clusters, index size, etc.), and the performance data related to the rule network during the rule matching process (such as the time to search for rules in different clusters, etc.). Based on the above data, the optimization effect of the rule network is evaluated. If it is found that the rule matching efficiency in a certain cluster is low, it may be recommended that the network optimization module 12 re-analyze the pattern of the cluster or adjust the index structure to further improve the rule matching efficiency.

[0075] The connection between the monitoring module 15 and the fact management module 13: monitor the performance indicators such as the acquisition time, cache hit rate, and incremental update time of the fact data. According to the monitoring results, the data source connection strategy, cache strategy, incremental update strategy, etc. of the fact management module 13 are optimized. For example, if the cache hit rate is low, it may be recommended to adjust the cache replacement algorithm or increase the cache capacity; if the fact data acquisition time is too long, the connection parameters or query statements of the data source connection unit may be optimized.

[0076] The monitoring module 15 receives the rule execution time, execution results, number of matched rules and other data fed back by the rule execution module 14, and comprehensively analyzes the performance of the rule execution process. According to the analysis results, the matching algorithm, execution process, result processing method, etc. of the rule execution module 14 are optimized. For example, if it is found that the execution time of certain types of rules is too long, it may be recommended that the rule execution module 14 optimize the execution logic of the corresponding rules or adopt parallel execution and other technologies to improve the execution efficiency. At the same time, the optimized and adjusted strategies and parameters are fed back to each module to guide it to make corresponding improvements and optimizations, forming a closed-loop monitoring and optimization system to continuously improve the overall performance of the system.

[0077] The rule engine system provided in the embodiment of the present application is as follows: Figure 2 As shown, Figure 2 This is a schematic diagram of data processing in a rule engine system according to an embodiment of the present invention, which is as follows:

[0078] (I) Rule loading

[0079] 1. Rule acquisition and parsing

[0080] When the rule engine system provided in the embodiment of the present application is started, a rule file is obtained from a preset storage location (such as a specific folder in the local file system, a rule table in a remote database, etc.). The rule file contains predefined business rules, and the predefined business rules are stored in a specific format (such as a structured format such as XML, JSON, etc., which is convenient for system parsing and processing). The rule engine system provided in the embodiment of the present application uses a corresponding parser (such as an XML parser or a JSON parser) to parse the rule file and convert it into an internally recognizable data structure.

[0081] For example, for a rule "IF product.price>100AND product.stock<50THENorder.quantity=10", the parser will identify the condition part (product.price>100AND product.stock<50) and the action part (order.quantity=10) and store them in the rule object in memory, which may contain properties such as the rule name, priority, conditional expression tree, action execution logic, etc.

[0082] 2. Rule preprocessing and storage

[0083] After parsing is completed, the rule engine system provided in the embodiment of the present application will pre-process the rules. Pre-processing includes sorting the rules according to the priority attributes of the rules, placing high-priority rules in a position that is easy to access quickly, so that they can be processed first in subsequent processing.

[0084] For example, in a financial transaction system, rules involving risk control may have the highest priority, such as "IFtransaction.amount>10000AND customer.risk_level='high'THEN block_transaction". These rules will be given priority to ensure transaction security. At the same time, the rule engine system provided in the embodiment of the present application will build an index structure to quickly find and match rules. The index can be constructed based on the key features of the rules (such as the variable type in the rule conditions, the business areas involved, etc.). For example, for rules involving product prices, an index with the product price range as the index key can be constructed to facilitate the rapid location of related rules when matching rules.

[0085] (II) Factual Data Reception

[0086] 1. Data source connection and adaptation

[0087] The rule engine system provided by the embodiment of the present application needs to establish a connection with various external data sources to obtain factual data. Data sources include but are not limited to relational databases (such as MySQL, Oracle, etc.), non-relational databases (such as MongoDB, etc.), message queues (such as Kafka, RabbitMQ, etc.) and file systems (such as CSV files, log files, etc.). For different types of data sources, the rule engine system provided by the embodiment of the present application uses corresponding connection drivers and interfaces to connect. For example, when connecting to a database, the rule engine system provided by the embodiment of the present application loads a database-specific driver (such as JDBC driver) and establishes a connection according to the connection parameters (such as host address, port number, user name, password, database name, etc.) configured. For message queues, the rule engine system provided by the embodiment of the present application creates a consumer object, configures the topic or queue name of the subscription, and sets the parameters (such as message format, batch receiving size, etc.) of message reception.

[0088] 2. Data reading and conversion

[0089] After the connection is established, the rule engine system provided in the embodiment of the present application reads fact data from the data source. The fact data may exist in different formats and structures, and the rule engine system provided in the embodiment of the present application needs to convert the fact data into an internal unified data format.

[0090] For example, the data read from the database may be in the form of a relational table, and the rule engine system provided by the embodiment of the present application will convert the relational table form into an object model or a key-value pair form so that it can be processed in memory. The data read from the file system (such as a CSV file) needs to be parsed, and each row of data is converted into a corresponding data object. During the conversion process, the rule engine system provided by the embodiment of the present application will also verify the data to ensure the integrity and accuracy of the data. For example, check whether the numerical data is within a reasonable range, whether the string data conforms to the expected format, etc.

[0091] 3. Incremental fact update judgment

[0092] 1. Judgment based on timestamp (if applicable)

[0093] If the fact data has a timestamp attribute, the rule engine system provided in the embodiment of the present application will compare the timestamp of the newly received data with the timestamp of the last processed data. The rule engine system provided in the embodiment of the present application will maintain a variable that records the timestamp of the last processed data. When new data arrives, its timestamp is obtained and compared with the variable. For example, in a real-time monitoring system, the sensor sends data with a timestamp once a second. The rule engine system provided in the embodiment of the present application will compare the timestamp of the new data with the timestamp of the last processed data. If the timestamp of the new data is greater than the timestamp of the last processed data, then the rule engine system provided in the embodiment of the present application determines that the data has been updated and needs to perform subsequent incremental fact update processing; otherwise, it directly enters the rule matching step.

[0094] 2. Judgment based on data content comparison

[0095] The rule engine system provided in the embodiment of the present application will compare the data content to determine whether there is an update. In a preferred example, a hash calculation is performed on the data. For newly received data, the rule engine system provided in the embodiment of the present application calculates its hash value, and then compares it with the hash value of the last processed data. If the two hash values ​​are different, it is determined that the data content has changed, and the rule engine system provided in the embodiment of the present application determines that the data has been updated.

[0096] For example, for a customer information data object containing multiple fields, the rule engine system provided in the embodiment of the present application will calculate the hash value of the entire object. If a field (such as the customer's contact number or address) changes, even if other fields remain unchanged, the hash value will be different, thereby detecting the data update. The rule engine system provided in the embodiment of the present application can effectively detect subtle changes in data without having to compare each field one by one, thereby improving judgment efficiency.

[0097] 3. Judgment based on version number

[0098] If the factual data has a version number management mechanism, the rule engine system provided in the embodiment of the present application can determine whether the data is updated by checking the version number. The rule engine system provided in the embodiment of the present application obtains the version number of the newly received data and compares it with the version number of the last processed data. When the version number of the newly received data is greater than the version number of the last processed data, the rule engine system provided in the embodiment of the present application determines that the data is updated. For example, in a document management system, each time a document is modified, the version number will increase. The rule engine system provided in the embodiment of the present application determines whether the document data has been updated by comparing the version numbers, thereby deciding whether incremental processing is required.

[0099] (IV) Incremental fact update processing (if any)

[0100] 1. Database-related incremental updates

[0101] When an update to the factual data in the database is detected, the rule engine system provided in the embodiment of the present application will determine the updated data range, which can be achieved through the database transaction log (such as MySQL's binlog) or the update notification mechanism provided by the database driver.

[0102] For example, if data updates are detected through binlog, the system will parse the records in the binlog to determine which tables and rows have changed data.

[0103] For updated data, the rule engine system provided in the embodiment of the present application will take corresponding actions. If it is an insert operation, the new data will be added to the data cache and related data structures in the memory. During the addition process, the data index that may be affected will be updated to ensure the efficiency of subsequent queries.

[0104] For example, in an inventory management system, when new goods are put into storage, the rule engine system provided by the embodiment of the present application will add the product information to the inventory data structure in the memory, and update the index structure indexed by the commodity category or name. If it is a modification operation, the corresponding record will be found in the memory and its value will be updated, and the relevant associated data will be updated synchronously. For example, when the product price is modified in the database, the rule engine system provided by the embodiment of the present application will update the price field in the product data structure in the memory, and recalculate the statistical data (such as average price, total price, etc.) related to the price. If it is a deletion operation, the rule engine system provided by the embodiment of the present application will remove the corresponding record from the data set in the memory, and clean up the relevant indexes and references. For example, when deleting a customer record from a customer relationship management system, the system will delete the record from the customer list in the memory, and update the index of the associated data such as the order, contact person, etc. related to the customer.

[0105] 2. Incremental updates related to message queues

[0106] For data updates received from the message queue, the rule engine system provided in the embodiment of the present application will process according to the type and content of the message. The data in the message queue is usually event-driven. For example, if a message about a product inventory change is received, the rule engine system provided in the embodiment of the present application will parse the message content and extract key information such as product ID and inventory change.

[0107] Then, the rule engine system provided in the embodiment of the present application will perform corresponding update operations in the data structure in the memory based on this information. For example, in an e-commerce system, if a message is received that the inventory of a certain product has decreased, the rule engine system provided in the embodiment of the present application will find the product record in the inventory data structure in the memory and subtract the corresponding change from the inventory quantity. At the same time, the rule engine system provided in the embodiment of the present application may trigger other business logic based on inventory changes, such as checking whether the inventory is below a safety threshold. If it is below the threshold, the replenishment process is triggered or relevant personnel are notified. When processing message queue data updates, the rule engine system provided in the embodiment of the present application needs to ensure the sequence and reliability of messages to avoid data inconsistencies due to improper message processing.

[0108] 3. File system related incremental updates

[0109] When it is monitored that the data file in the file system is updated (such as the file content is modified or a new file is added), the rule engine system provided by the embodiment of the present application will reread the file content. For the modified file, the rule engine system provided by the embodiment of the present application will analyze the data changes in the file to determine which rows or fields have changed. If it is an incremental update of the data file (such as adding a few rows of data in a CSV file), the rule engine system provided by the embodiment of the present application will parse the newly added data rows and merge them into the corresponding data set in the memory.

[0110] When processing file updates, the rule engine system provided by the embodiment of the present application also needs to consider file locking and concurrent access issues to ensure data consistency and integrity. For example, in a multi-threaded environment, a file lock mechanism is used to prevent data conflicts caused by multiple threads writing to a file at the same time. At the same time, the rule engine system provided by the embodiment of the present application may record and audit file updates in order to track the history of data changes.

[0111] (V) Rule Matching

[0112] 1. Grouping based on priority and relevance

[0113] Priority Grouping

[0114] The rule engine system provided in the embodiment of the present application groups rules according to pre-set rule priorities. The priority is set based on the importance and urgency of the business. For example, in a medical system, rules related to patient life safety (such as emergency treatment rules, drug allergy warning rules, etc.) have the highest priority; while some rules related to the maintenance or auxiliary functions of the rule engine system provided in the embodiment of the present application (such as logging rules, interface display optimization rules, etc.) have a lower priority.

[0115] The rule engine system provided in the embodiment of the present application stores high-priority rules in a special data structure (such as a priority queue or an ordered list) so that they can be processed first when matching rules. For example, when using a priority queue, high-priority rules are placed at the head of the queue, and low-priority rules are placed in the back in sequence. In this way, when matching rules, the system first takes out rules from the head of the queue for matching, ensuring that key rules can be processed in a timely manner and ensuring the normal operation of the core business functions of the system.

[0116] Relevance Grouping

[0117] The rule engine system provided in the embodiment of the present application analyzes the condition and action parts of the rules and groups the rules involving the same business field, data object or operation type into one group. For example, in an enterprise resource planning (ERP) system, the rules related to procurement management (such as purchase order approval rules, supplier selection rules, procurement contract management rules, etc.) can be divided into one group; the rules related to financial management (such as financial report generation rules, cost accounting rules, budget control rules, etc.) can be divided into another group.

[0118] The implementation method of correlation grouping can be through keyword extraction and semantic analysis of the rule content. The rule engine system provided in the embodiment of the present application scans the text description of the rule, extracts key business keywords (such as "purchase order", "supplier", "financial statement", "cost", etc.) or data object identifiers (such as "product_id", "customer_id", "invoice_number", etc.), and then classifies the rules into corresponding groups according to the above keywords and identifiers, so that the grouping method helps to narrow the search scope of rule matching and improve matching efficiency, because in actual business processing, rules related to specific business fields or data objects are usually triggered at the same time.

[0119] 2. Rule matching process

[0120] For the grouped rules, the rule engine system provided in the embodiment of the present application compares the fact data with the condition part of the rule one by one. In this process, the rule engine system provided in the embodiment of the present application will obtain the fact data from the memory and perform logical judgment based on the variables and operators in the rule conditions. For example, for the rule "IFcustomer.age>18AND customer.balance>1000THEN offer.discount=0.1", the system will obtain the values ​​of customer.age and customer.balance from the fact data, and then perform a comparison operation.

[0121] If the factual data meets the conditional part of the rule, the rule matches successfully. When processing a large number of rules and factual data, the rule engine system provided in the embodiment of the present application may adopt an optimization algorithm (such as the RETE algorithm or its improved version) to speed up the matching process and reduce unnecessary comparison operations. The RETE algorithm shares and reuses the patterns in the rule conditions by constructing a rule network, avoiding repeated calculations of the same pattern. For example, when multiple rules involve the judgment of customer.age, the RETE algorithm will only calculate the value of customer.age once in the network, and share the result between related rules, thereby improving matching efficiency. The rule engine system provided in the embodiment of the present application will select a suitable optimization algorithm based on the characteristics of the rules and factual data, and adjust the algorithm parameters to achieve the best matching performance.

[0122] (VI) Whether optimization is needed

[0123] 1. Rule matching time monitoring and judgment

[0124] The rule engine system provided in the embodiment of the present application will record the time spent on each match during the rule matching process. This can be achieved by obtaining the system timestamp at the beginning and end of the matching operation. For example, when starting to match a rule, record the current time (you can use the high-precision time acquisition function provided by the rule engine system provided in the embodiment of the present application, such as using System.currentTimeMillis() or System.nanoTime() in Java), and when the match is completed, record the current time, then the matching time of the rule is.

[0125] The rule engine system provided in the embodiment of the present application maintains a statistical data structure of rule matching time, such as a sliding window averager. Through the above method, the average rule matching time within a certain time range (such as the past 1 minute, 5 minutes, etc.) can be calculated. If the average matching time exceeds a preset threshold (the threshold can be set according to system performance requirements and business needs, for example, in a real-time trading system, the average matching time may be required to be no more than 10 milliseconds), it is considered that the rule matching efficiency is low and optimization needs to be considered.

[0126] 2. Memory usage monitoring and judgment

[0127] The rule engine system provided in the embodiment of the present application will track the memory usage in real time, which can be achieved by calling the memory management interface provided by the operating system or using the memory management function in the programming language. For example, in Java, the memory management tools provided by the Java virtual machine (JVM) (such as ManagementFactory.getMemoryMXBean().getHeapMemoryUsage() and other methods) can be used to obtain the current heap memory usage, non-heap memory usage and other information; in C++, the memory management functions specific to the operating system (such as the VirtualQuery function under Windows or the / proc / meminfo file reading under Linux) can be used to obtain memory usage.

[0128] The rule engine system provided in the embodiment of the present application will set a threshold value for memory usage, and the threshold value can be determined according to the hardware configuration (such as the memory size of the server) and the operating environment of the rule engine system provided in the embodiment of the present application. For example, for a rule engine system running on a server with 8GB of memory, it can be set that when the heap memory occupancy exceeds 6GB, the memory occupancy is considered to be too high and needs to be optimized. When it is monitored that the current memory occupancy exceeds the threshold, the optimization process is triggered to avoid system performance degradation or crash due to insufficient memory.

[0129] The rule engine system provided in the embodiment of the present application classifies and prioritizes the rules to reduce unnecessary rule matching. According to the importance and frequency of use of the rules, the rules are divided into different categories, and different priorities are set for each category. In the rule matching process, high-priority rules are matched first, thereby improving matching efficiency.

[0130] By introducing a cache mechanism, repeated rule matching can be avoided. For facts and rules that have been matched, their results are cached. The next time the same situation occurs, the results can be directly obtained from the cache to avoid repeated calculations.

[0131] By optimizing the rule matching algorithm, a more efficient matching strategy can be adopted. For example, data structures such as hash tables can be used to store rules and facts to improve the search speed. At the same time, technologies such as parallel computing can be used to improve the efficiency of rule matching.

[0132] In order to further optimize the algorithm performance, the rule engine system provided in the embodiment of the present application also provides the following algorithm optimization formula:

[0133] The following are some relevant calculation and evaluation formula directions that may be involved in Drools rule engine optimization:

[0134] 1. Rule matching efficiency

[0135] Evaluation of conflict set computational complexity:

[0136] For a rule engine based on the RETE algorithm (one of the main algorithm types used by Drools), the conflict set calculation complexity can be estimated using the following formula:

[0137] C = O (r × p);

[0138] Among them, C is the computational complexity of the conflict set, r is the number of rules, and p is the number of patterns.

[0139] It should be noted that the above formula is a preferred example of the rule engine system provided in the embodiment of the present application, and is subject to the rule engine system provided in the embodiment of the present application, and is not specifically limited.

[0140] Rule matching time estimation formula (simplified model):

[0141] T match =T rete ×N facts ;

[0142] Among them, T match is the total time of rule matching, T rete is the average time for a single fact to pass through the RETE network, N facts is the number of input facts. And T rete It is also affected by the number of rules and patterns, network structure, etc.

[0143] 2. Memory usage optimization related

[0144] Regular network memory usage:

[0145]

[0146] Where M is the memory usage of the rule network, r is the number of rules, S i is the memory usage of the state related to the i-th rule (such as node status, etc.), and P1 is the memory usage of the i-th rule pattern (including the memory structure of each pattern, etc.). The actual memory calculation of the above formula needs to consider more underlying implementation details, such as object references, caches, etc.

[0147] 3. Optimize rule execution performance

[0148] Rule execution time estimate (single rule):

[0149] T exec rule -T condition check +T action exec ;

[0150] Among them, T exec_ruleis the single rule execution time, T condition_check is the rule condition checking time (including attribute acquisition, comparison and other operations), T action_exec It is the execution time of the rule action (such as modification of objects, method calls, etc.).

[0151] Overall rule execution time (multiple rules):

[0152]

[0153] Among them, T exec is the total time for all rules to execute, r is the number of rules, T exec_rulei is the execution time of the ith rule, F l is the triggering frequency of the i-th rule under the current input data.

[0154] The rule engine system provided in the embodiment of the present application improves the efficiency of rule matching. Through optimized network construction, a method based on pattern clustering is adopted. First, the patterns in the rules are analyzed, and the rules with similar pattern structures are classified into the same cluster. For example, for rules that all involve the judgment of the range of customer transaction amounts, they are clustered together. In this way, in the rule matching process, it is only necessary to search within the corresponding cluster, which greatly reduces the search space. After testing, in the scenario of processing 8,000 rules, the rule matching time is shortened by about 35% compared with the traditional construction method. In the real-time monitoring of financial transactions, each transaction involves many rule verifications. The optimized network construction enables the system to quickly locate the relevant rules. The original average time for rule matching of a transaction was 30 milliseconds, but now it has been reduced to 19.5 milliseconds, which significantly improves the real-time response speed, ensures that transactions can be processed in a timely manner, and effectively reduces the risks caused by delays, such as exchange rate fluctuations or market price changes.

[0155] The rule engine system provided in the embodiment of the present application realizes efficient fact processing by introducing a fact processing mechanism based on event stream processing. Fact data enters the system in the form of an event stream, and the rule engine system provided in the embodiment of the present application analyzes and processes the event stream in real time. When new fact data arrives, it is compared with the existing fact cache, and only the changed part is processed. For example, in a stock trading monitoring scenario, stock prices fluctuate constantly to generate new fact data. The rule engine system provided in the embodiment of the present application only focuses on the part where the price changes, rather than recalculating all stock data. This approach improves the efficiency of fact processing by about 45%, reduces the amount of data processing in the rule matching process, and further speeds up the rule matching speed, allowing the system to respond to market changes more promptly;

[0156] The rule engine system provided in the embodiment of the present application improves rule execution and adopts a rule execution algorithm based on dynamic compilation and cache optimization. During operation, for the rules executed for the first time, the system dynamically compiles and converts them into efficient machine code. The compiled code is directly called during subsequent execution, avoiding the overhead of repeated compilation. At the same time, the rule execution results are cached, and when the same input appears again, the cached results are directly returned. In the high-load business scenario test, the rule execution speed was increased by about 55%. Taking the order processing of the e-commerce platform as an example, it involves complex promotion rules and inventory rule execution. The optimized rule execution algorithm can quickly process a large number of orders, ensuring that customers can obtain accurate order information in a timely manner, such as order total price calculation, inventory deduction and other operations, which improves the user experience, and is particularly suitable for business scenarios such as real-time monitoring of financial transactions that require extremely high response speeds.

[0157] The rule engine system provided by the embodiment of the present application optimizes memory management, effectively merges nodes, deeply analyzes the nodes in the rule network, and merges logically mergeable nodes. For example, multiple nodes with the same judgment condition but slightly different execution actions can be merged into one node, and different execution actions are processed by adding branches. In this way, the number of nodes is reduced by about 30%. When processing large-scale rule sets and factual data, the space occupied by nodes in memory is significantly reduced. For example, in an enterprise-level customer relationship management (CRM) system, when processing a large amount of customer data and related rules, the original memory node occupancy is 1.5GB, which is reduced to 1.05GB after node merging, effectively releasing memory resources and providing the possibility for the system to process more data.

[0158] The rule engine system provided in the embodiment of the present application constructs an adaptive dynamic index structure through dynamic indexing. According to the access frequency and pattern changes of rules and fact data, the index construction method is dynamically adjusted. For example, for frequently accessed rules and fact data, a more efficient index path is created to improve access speed. According to actual monitoring, the memory reading efficiency has been improved by about 35%. In a business system that frequently queries customer order status and transaction history, dynamic indexing can quickly locate relevant data, reduce memory addressing time, and also reduce the generation of memory fragmentation. The reduction of memory fragmentation makes memory allocation more continuous and efficient, improves memory utilization, and ensures that the system maintains stable performance during long-term operation.

[0159] The rule engine system provided in the embodiment of the present application uses an intelligent caching strategy based on frequency of use and timeliness through an intelligent caching strategy. Not only the recent frequency of use of data is considered, but also the timeliness of the data is combined to manage the cache. For example, for transaction data with strong timeliness, it is kept in the cache during its validity period and cleared in time after expiration. The cache hit rate reaches more than 80%, which effectively avoids repeated calculations and data loading. In the enterprise resource planning (ERP) system, for frequently queried data such as product inventory data and purchase order data, the caching mechanism greatly improves the system response speed, enables the system to process more rules and fact data with limited memory resources, enhances the stability and scalability of the system, and reduces the risk of system performance degradation or crash due to insufficient memory.

[0160] The rule engine system provided in the embodiment of the present application enhances the dynamic rule updating capability, and develops an algorithm based on incremental rule updating through an improved algorithm. When business rules change, the rule engine system provided in the embodiment of the present application can accurately identify the affected rule parts and only update these parts instead of reloading the entire rule set. For example, when an enterprise adjusts its financial reimbursement rules, only some conditions or amount limits may change, and the rule engine system provided in the embodiment of the present application only updates the relevant parts. In this way, the time for rule updates is shortened by about 70%, from an average of 15 minutes to 4.5 minutes, which greatly improves the efficiency of rule updates and enables enterprises to adapt to changes in business rules more quickly.

[0161] The rule engine system provided in the embodiment of the present application optimizes the system architecture and designs a modular and plug-in system architecture. New rules can be easily added to the system in the form of plug-ins, and the system can automatically identify and integrate new rules. In the adjustment of promotional activity rules of an e-commerce platform, when launching new promotional activities or modifying existing activity rules, new rule plug-ins can be dynamically loaded without stopping the system operation. For example, during the "Double Eleven" shopping festival, promotional rules need to be adjusted frequently, and the system can adapt quickly to achieve seamless updates of business rules. This reduces the impact of rule updates on system operations, reduces system downtime and maintenance time, improves the flexibility and competitiveness of corporate business, and enables enterprises to respond to market changes in a timely manner and launch more attractive business strategies.

[0162] The rule engine system provided in the embodiment of the present application improves the overall performance of the system and realizes high-throughput processing. Combining the above-mentioned optimization measures, the system has significantly improved the throughput when processing large-scale rule sets (such as 100,000 rules) and massive data (such as 50 million factual data). In actual testing, the throughput has been increased from 8,000 business requests per hour to 14,400, an increase of about 80%. In the order processing system of the enterprise, a large number of orders can be processed efficiently to avoid order backlogs. For example, during the promotional activities of e-commerce, the order volume increased significantly, and the system was able to process orders quickly to ensure the timely delivery of orders and the improvement of customer satisfaction.

[0163] The rule engine system provided in the embodiment of the present application can meet complex business needs and can cope with the growing complex business needs of enterprises. Whether it is the complex risk assessment and compliance rules in the financial field, or the diversified promotion and inventory management rules in the e-commerce industry, the rule engine system provided in the embodiment of the present application can be executed accurately and efficiently. For example, in the investment portfolio management of financial institutions, involving risk calculations and investment strategy rules for multiple assets, the rule engine system provided in the embodiment of the present application can operate stably, provide strong support for the digital operation of enterprises, help enterprises improve operational efficiency, reduce costs, occupy an advantageous position in the fierce market competition, and achieve sustainable development. At the same time, the scalability of the rule engine system provided in the embodiment of the present application enables enterprises to easily cope with business expansion and rule changes without large-scale system transformation.

[0164] The present invention adopts the above technical scheme, by receiving a rule file, parsing and verifying the rule file at the grammatical and semantic levels, and loading it into the memory; analyzing and reorganizing the parsed rule file through the logical relationship between the rules to construct a rule network; obtaining fact data from an external module, parsing the fact data, and obtaining parsed fact data; comparing the parsed fact data with the rules in the rule network to obtain corresponding rules, and executing corresponding processes according to the rule definitions; by collecting the operating data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyzing the operating status according to the operating data and performance indicators, determining the existing problems and performance bottlenecks, and taking corresponding optimization measures, compared with the prior art, it has the following technical effects: improving rule matching efficiency, optimizing memory management, enhancing dynamic rule updating capabilities, and improving the overall performance of the system.

[0165] Example 2

[0166] An exemplary embodiment of the present invention is as follows Figure 3 As shown, Figure 3: is a flow chart of an application method based on a rule engine system according to an embodiment of the present invention, which is applied to the rule engine system in Example 1. The application method based on a rule engine system provided by the embodiment of the present application includes:

[0167] Step S300, receiving a rule file, parsing and verifying the rule file at the syntax and semantic levels, and loading the rule file into the memory;

[0168] Optionally, parsing and verifying the rule file at the syntax and semantic levels and loading it into the memory includes: performing lexical analysis and syntax analysis on the rule file, converting the text form of the parsed rule file into the target format, and obtaining a rule file in the target format; performing semantic checking on the rule file in the target format to obtain a rule file after the semantic check, and verifying the type compatibility of operators and operands of the rule file after the semantic check, and checking the rationality of the logical expressions of the rule file after the semantic check to obtain a checked rule file; wherein the semantic check includes: checking the definition and scope of variables; and classifying and storing the checked rule file according to the attributes of the rules and storing it in the memory.

[0169] Wherein, step S300 corresponds to the rule parsing module 11 in embodiment 1.

[0170] Step S302, analyzing and reorganizing the parsed rule file based on the logical relationship between the rules to construct a rule network;

[0171] Among them, step S302 corresponds to the network optimization module 12 in Example 1.

[0172] Step S304, obtaining fact data from an external module, parsing the fact data, and obtaining parsed fact data;

[0173] Among them, step S304 corresponds to the fact management module 13 in Example 1.

[0174] Step S306, comparing the parsed fact data with the rules in the rule network to obtain corresponding rules, and executing corresponding processes according to the rule definitions;

[0175] Among them, step S306 corresponds to the rule execution module 14 in embodiment 1.

[0176] Step S308, by collecting the operation data and performance indicators of the rule parsing module, network optimization module, fact management module and rule execution module, analyzing the operation status based on the operation data and performance indicators, determining the existing problems and performance bottlenecks, and taking corresponding optimization measures.

[0177] Wherein, step S308 corresponds to the monitoring module 15 in embodiment 1.

[0178] The present invention adopts the above technical scheme, by receiving a rule file, parsing and verifying the rule file at the grammatical and semantic levels, and loading it into the memory; analyzing and reorganizing the parsed rule file through the logical relationship between the rules to construct a rule network; obtaining fact data from an external module, parsing the fact data, and obtaining parsed fact data; comparing the parsed fact data with the rules in the rule network to obtain corresponding rules, and executing corresponding processes according to the rule definitions; by collecting the operating data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyzing the operating status according to the operating data and performance indicators, determining the existing problems and performance bottlenecks, and taking corresponding optimization measures, compared with the prior art, it has the following technical effects: improving rule matching efficiency, optimizing memory management, enhancing dynamic rule updating capabilities, and improving the overall performance of the system.

[0179] The above description is only a preferred embodiment of the present invention, and does not limit the implementation mode and protection scope of the present invention. For those skilled in the art, it should be aware that all solutions obtained by equivalent substitutions and obvious changes made using the description and illustrations of the present invention should be included in the protection scope of the present invention.

Claims

1. A rule engine system, characterized in that: include: Rule parsing module, network optimization module, fact management module, rule execution module, monitoring module and external module, among which, The rule parsing module is used to receive a rule file, parse and verify the rule file at the syntax and semantic level, and load it into the memory; The network optimization module is used to analyze and reorganize the parsed rule file according to the logical relationship between the rules to construct a rule network; The fact management module is used to obtain fact data from the external module, and parse the fact data through the rule parsing module to obtain the parsed fact data; The rule execution module is used to compare the parsed fact data with the rules in the rule network to obtain corresponding rules, and execute corresponding processes according to the rule definition; The monitoring module is used to collect the operating data and performance indicators of the rule parsing module, the network optimization module, the fact management module and the rule execution module, analyze the operating status based on the operating data and the performance indicators, determine the existing problems and performance bottlenecks, and take corresponding optimization measures.

2. The rule engine system according to claim 1, characterized in that: The rule parsing module includes: a syntax parsing unit, a semantic checking unit and a rule loading unit, wherein: The syntax parsing unit is used to perform lexical analysis and syntax analysis on the rule file, convert the parsed text form of the rule file into a target format, and obtain the rule file in the target format; The semantic checking unit is used to perform semantic checking on the rule file in the target format to obtain the rule file after semantic checking, and verify the type compatibility of the operator and operand of the rule file after semantic checking, and check the rationality of the logical expression of the rule file after semantic checking to obtain the checked rule file; wherein the semantic checking includes: checking the definition and scope of variables; The rule loading unit is used to classify and store the checked rule files according to the attributes of the rules, and store them in the memory.

3. The rule engine system according to claim 1 or 2, characterized in that: The network optimization module includes: a pattern analysis unit, a clustering optimization unit and an index construction unit, wherein: The pattern analysis unit is used to analyze the parsed rule file and identify the pattern corresponding to the parsed rule file; The clustering optimization unit is used to cluster the rules with similar patterns using a preset clustering algorithm according to the pattern to obtain clustered rules, and generate the rule network according to the clustered rules; The index building unit is used to build an index structure according to key attributes of the rules in the rule network or the position relationship of the rules in the rule network.

4. The rule engine system according to claim 1, characterized in that: The fact management module includes: a data source connection unit, a data cache unit and an incremental update unit, wherein: The data source connection unit is used to communicate with the data source and read data through a preset connection interface and driver; The data cache unit is used to store the fact data obtained by the data source using a corresponding cache strategy; The incremental update unit is used to monitor the changes of the fact data in real time, and when the data in the data source changes, only the changed part is obtained and processed.

5. The rule engine system according to claim 1, characterized in that: The rule execution module includes: a matching unit, an execution unit and a result processing unit, wherein: The matching unit is used to match the fact data with the rules in the rule network, and compare the variable value in the fact data with the conditional expression according to the condition part of the rule; The execution unit is used to execute a corresponding operation process according to the rule when the matching unit obtains a rule that meets the condition; The result processing unit is used to process and feedback the result of the rule execution, store the result in a specified location, and transmit the result to a corresponding module.

6. The rule engine system according to claim 1, characterized in that: The monitoring module includes: a performance monitoring unit, an analysis and evaluation unit, and an optimization and adjustment unit, wherein: The performance monitoring unit is used to collect performance data of each key node and module in real time, including: rule matching time, rule execution time, memory usage, CPU usage, data transmission rate and data source connection response time; The analysis and evaluation unit is used to analyze and evaluate the collected performance data to determine whether the performance status of the system is normal, and whether there is a performance bottleneck or potential risk; The optimization adjustment unit is used to know and implement corresponding optimization strategies according to the analysis results of the analysis and evaluation unit, wherein the optimization strategies include: adjusting algorithm parameters, optimizing data structures, and improving the interaction process between modules.

7. The rule engine system according to claim 6, characterized in that: The monitoring module comprises: The analysis and evaluation unit is also used to set a threshold value according to business requirements and performance indicators, and to issue an alarm when the performance data is greater than the threshold value, wherein the alarm is used to indicate that there is a problem with the system.

8. The rule engine system according to claim 6, characterized in that: The monitoring module comprises: The optimization and adjustment unit is also used to adjust the clustering algorithm parameters or index construction strategy in the network optimization module; if the memory usage is too high, adjust the cache elimination strategy in the fact management module or optimize the memory allocation method in the rule execution module.

9. An application method based on a rule engine system, characterized in that: Applied to rule engine systems, including: Receiving a rule file, parsing and verifying the rule file at the syntax and semantic level, and loading the rule file into the memory; Analyzing and reorganizing the parsed rule file based on the logical relationship between the rules to construct a rule network; Acquire fact data from an external module, and parse the fact data to obtain the parsed fact data; Compare the parsed fact data with the rules in the rule network to obtain corresponding rules, and execute corresponding processes according to the rule definitions; By collecting the operating data and performance indicators of the rule parsing module, network optimization module, fact management module and rule execution module, the operating status is analyzed based on the operating data and the performance indicators, the existing problems and performance bottlenecks are determined, and corresponding optimization measures are taken.

10. The application method based on the rule engine system according to claim 9, characterized in that: The parsing and verification of the rule file at the syntax and semantic level and loading it into the memory includes: Performing lexical analysis and grammatical analysis on the rule file, converting the parsed text form of the rule file into a target format, and obtaining the rule file in the target format; Performing semantic checking on the rule file in the target format to obtain a rule file after semantic checking, verifying the type compatibility of operators and operands of the rule file after semantic checking, and checking the rationality of the logical expression of the rule file after semantic checking to obtain a checked rule file; wherein the semantic checking includes: checking the definition and scope of variables; The checked rule files are classified and stored according to the attributes of the rules, and stored in the memory.

Citation Information

Cited By

  • Employee behavior evaluation method based on function engine and CRM system

    CN120672210A

  • Security APP real-time compliance detection system and method based on dynamic rule base

    CN121349831A