A chain code resource scheduling method and device
Patent Information
- Application Number
- CN202611046937.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-14
- Publication Date
- 2026-10-30
AI Technical Summary
面对参数规模巨大、涉及海量状态读写的提案交易,系统往往在瞬间被拖垮,导致节点阻塞甚至崩溃,影响了系统运行的稳定性
本公开实施例提供的链码资源调度方法,通过在链码执行前对提案交易请求进行语义解析并据此生成资源预算参数,从而实现了在资源消耗之前预判风险,同时结合系统实时负载进行资源调度,有效避免了高负载提案交易在系统负载高时执行的问题,保证了系统运行的稳定性。
Smart Images

Figure CN123011491A_ABST
Abstract
Description
Technical Field
[0001] This disclosure belongs to the field of blockchain technology, and in particular relates to a chaincode resource scheduling method and apparatus. Background Technology
[0002] Blockchain technology, as a decentralized and tamper-proof distributed ledger technology, has been widely applied in recent years in areas such as government data sharing, supply chain finance, and cross-border payments. Based on differences in node access mechanisms and permission controls, blockchains are mainly divided into three categories: public blockchains, private blockchains, and consortium blockchains. Among them, a consortium blockchain is a blockchain system jointly managed by several specific institutions with business connections. Each institution operates one or more nodes, and the transaction and consensus processes are only open to members within the consortium, offering privacy, high performance, and regulatory oversight. Therefore, consortium blockchains have become the mainstream choice for enterprise-level applications.
[0003] In a consortium blockchain architecture, chaincode (smart contracts) is the carrier of business logic. Execution nodes (peer nodes) are responsible for receiving transaction proposals initiated by clients, simulating the execution of the chaincode, generating a read-write set (RWSet) containing state change information, and submitting it to the consensus network. Since execution nodes need to process a large number of proposals in parallel with limited computing, storage, and I / O resources, resource scheduling and stability assurance during the chaincode execution phase become crucial factors determining the overall system performance.
[0004] Currently, mainstream blockchain platforms mainly adopt the following two technical solutions for resource control during chaincode execution: (1) Ex-post control mechanism based on resource metering Public blockchains, such as Ethereum, typically employ a Gas mechanism. This mechanism pre-determines a resource consumption unit (Gas) for each operation instruction in the chaincode (smart contract), deducting the corresponding fee in real time during chaincode execution. Execution terminates immediately when the account balance is insufficient or Gas is exhausted. This mechanism is primarily used to prevent malicious code such as infinite loops from consuming network resources. However, in consortium blockchain scenarios, its essence is "consume first, then intervene" ex-post control, making it impossible to predict risks before execution.
[0005] (2) Hard circuit breaker mechanism based on execution constraints Consortium blockchain platforms, such as Hyperledger Fabric, typically employ execution timeout and container resource isolation mechanisms. Specific measures include setting a maximum timeout for chaincode execution and limiting the CPU and memory limits available to the chaincode via Docker containers. When the chaincode execution time exceeds a preset threshold or reaches the container resource limit, the executing node will directly and forcibly terminate the chaincode container. This method is simple to implement, but its control granularity is extremely coarse, only allowing for two extreme strategies: "execution complete" or "forced termination."
[0006] Therefore, both the Gas mechanism and the timeout mechanism can only react after the chaincode has started running and consuming resources. When faced with proposal transactions involving massive parameter scales and huge amounts of state reads and writes, the system is often dragged down instantly, causing node blockage or even crashes, affecting the stability of the system. Moreover, in existing technologies, once a proposal is judged to have timed out or exceeded resource limits, execution is directly terminated, easily leading to proposal transaction execution failures. Summary of the Invention
[0007] To address the aforementioned issues, this disclosure provides a chaincode resource scheduling method and apparatus to improve system resource utilization efficiency and increase the success rate of proposal transaction execution while ensuring system stability.
[0008] This invention provides a chaincode resource scheduling method, comprising: Receive a proposal transaction request, perform semantic parsing on the proposal transaction request, extract semantic features representing resource consumption, and generate a semantic feature vector; Based on the semantic feature vector, resource budget parameters are generated, including a maximum operation frequency threshold. Based on the resource budget parameters and real-time resource load information, determine the execution method of the proposal transaction request; When executing the proposal transaction request according to the execution method, if it is determined that the current operation frequency of the chaincode is greater than the maximum operation frequency threshold, a delay injection time is generated based on the maximum operation frequency threshold and the current operation frequency. Execution is delayed according to the aforementioned delayed injection time.
[0009] Furthermore, the semantic features include chaincode identifiers, function call names, and parameter lists; Receiving a proposal transaction request, performing semantic parsing on the proposal transaction request, extracting semantic features representing resource consumption to generate a semantic feature vector, including: Obtain the array length or byte size of the parameter list to determine the parameter operation scale of the proposal transaction request; Based on the function name or parameter keyword, match and identify the parameter operation type of the proposal transaction request; Based on the chaincode identifier, query the historical execution data of the corresponding chaincode; The parameter operation scale, parameter operation type, and historical execution data are encoded into semantic feature vectors.
[0010] Furthermore, the resource budget parameters also include the maximum allowed execution time and the maximum read / write set size; Based on the semantic feature vector, resource budget parameters are generated, including: A resource scoring function is constructed based on a predefined set of weight parameters, wherein the weight parameters include one or more of the following: parameter size weight, operation type weight, read / write intensity weight, and historical execution data weight. Based on the semantic feature vector and the resource scoring function, the resource score of the proposal transaction request is determined, and resource budget parameters are generated by mapping the numerical range of the resource score.
[0011] Furthermore, based on the resource budget parameters and real-time resource load information, the execution method of the proposal transaction request is determined, including: If the current resource load is determined to be lower than the preset resource load threshold based on real-time resource load information, the proposal transaction request is allowed to directly enter the execution phase. If, based on real-time resource load information, it is determined that the current resource load is not lower than the resource load threshold and the resource score is greater than the preset first resource score threshold, then the proposal transaction request is added to the scheduling queue. If, based on real-time resource load information, it is determined that the current resource load is not lower than the resource load threshold and the resource score is greater than a preset second resource score threshold, then the proposal transaction request is rejected.
[0012] Furthermore, the scheduling queue is arranged for execution in order of resource score from low to high or in order of business priority from high to low.
[0013] Furthermore, when executing the proposal transaction request according to the aforementioned execution method, the current operation frequency is determined according to the following process: A sliding window is used to count the cumulative number of status read requests or status write requests within a set time window; The current operation frequency is defined as the number of status read requests or status write requests per unit of time.
[0014] Furthermore, the process of executing the proposed transaction request also includes: Real-time monitoring of chaincode execution status, wherein the chaincode execution status includes at least one of the following: read / write set size, execution time, and resource usage trend; If the execution state of the chaincode is determined to be abnormal, the execution of the chaincode is interrupted.
[0015] The present invention also provides a chaincode resource scheduling device for implementing the above method, comprising: The semantic analysis module is used to receive proposal transaction requests, perform semantic parsing on the proposal transaction requests, extract semantic features representing resource consumption, and generate semantic feature vectors. The resource assessment module is used to generate resource budget parameters based on the semantic feature vector, wherein the resource budget parameters include a maximum operating frequency threshold. The entry scheduling module is used to determine the execution method of the proposal transaction request based on the resource budget parameters and actual resource load information. The execution monitoring module is used to determine whether the current operation frequency of the chaincode is greater than the maximum operation frequency threshold when the proposal transaction request is executed according to the execution method. The dynamic adjustment module is used to generate a delay injection time based on the maximum operation frequency threshold and the current operation frequency when the execution monitoring module determines that the current operation frequency of the chaincode is greater than the maximum operation frequency threshold; and to delay execution based on the delay injection time.
[0016] The present invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor implements the above method when executing programs stored in memory.
[0017] The present invention also provides a computer storage medium storing a computer program, which, when executed by a processor, implements the above-described method.
[0018] Compared with the prior art, this disclosure has the following advantages: The chaincode resource scheduling method provided in this disclosure performs semantic parsing on the proposal transaction request before chaincode execution and generates resource budget parameters accordingly. This enables risk prediction before resource consumption and resource scheduling in conjunction with real-time system load. It effectively avoids the problem of high-load proposal transactions being executed when the system load is high, thus ensuring the stability of system operation.
[0019] Furthermore, based on the generated resource budget parameters, when the chaincode operation frequency is detected to be greater than the maximum operation frequency threshold, a waiting time proportional to the excess is injected before the next chaincode operation by delaying execution. Compared with the simple and crude control method of terminating execution after resources are exhausted in the existing technology, the chaincode execution rate is dynamically adjusted according to the difference between the chaincode operation frequency and the maximum operation frequency threshold by delaying execution, which realizes smooth resource use and ensures the success rate of proposal transaction execution while ensuring the stability of system operation.
[0020] By generating unique resource budget parameters for each proposal transaction request based on semantic analysis results, and then performing differentiated resource scheduling for different proposal transactions accordingly, refined resource allocation is achieved, avoiding resource waste or under-allocation caused by a one-size-fits-all approach, and improving resource utilization.
[0021] In this embodiment of the disclosure, all proposal transaction requests are allowed to enter the execution phase when the system is under low load, while the execution of proposal transactions with extremely high resource requirements is blocked when the system is under high load. At the same time, an execution queue is established for proposal transactions with high resource requirements, and they are executed in order of resource score or business priority. This prevents execution nodes from being blocked or crashing due to excessive instantaneous load, thereby improving the reliability of system operation.
[0022] Other features and advantages of this disclosure will be set forth in the following description and will be apparent in part from the description or may be learned by practicing the disclosure. The objects and other advantages of this disclosure may be realized and obtained by means of the structures pointed out in the description, claims and drawings. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 A schematic diagram of the structure of the chaincode resource scheduling device according to an embodiment of the present disclosure is shown; Figure 2 A flowchart illustrating a chaincode resource scheduling method according to an embodiment of the present disclosure is shown; Figure 3 A flowchart illustrating another chaincode resource scheduling method according to an embodiment of the present disclosure is shown. Detailed Implementation
[0025] This disclosure provides a blockchain chaincode resource scheduling method based on execution semantic prediction. It is applicable to scenarios where resource consumption during chaincode execution is dynamic, uncertain, or related to input parameters. It is particularly suitable for chaincode call scenarios with high-frequency state access, batch data processing, and unpredictable execution complexity, so as to improve system stability and resource utilization efficiency during the chaincode execution phase.
[0026] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0027] To better understand this invention, the technical terms involved in this invention are explained below: Chaincode: A business logic program deployed on a blockchain, used to process transaction requests and generate read / write sets.
[0028] Proposal: A transaction request initiated by the client to the execution node, which includes the function name and parameters of the chaincode to be called.
[0029] Executor: The core component of the execution node responsible for chaincode invocation, transaction simulation execution, and resource scheduling.
[0030] Semantic Analysis Engine: A module used to parse proposal content and extract resource features.
[0031] Resource Score: A quantitative indicator of resource demand calculated based on the semantic features of the proposal.
[0032] Soft Throttling: Controls the execution speed of chaincode by injecting delays or reducing execution priority, instead of directly terminating execution.
[0033] Read-Write Set (RWSet): The set of read and write operations generated during chaincode execution.
[0034] Sliding Window Counter: A counting mechanism used to count the frequency of operations per unit of time.
[0035] Injected Delay: A control method that artificially increases the waiting time during chaincode execution.
[0036] Admission Control: The process of prioritizing and scheduling transactions before chaincode execution.
[0037] Figure 1 A schematic diagram of the chaincode resource scheduling device according to an embodiment of the present disclosure is shown, which includes a semantic analysis module, a resource evaluation module, an entry scheduling module, an execution monitoring module, a dynamic adjustment module, and an anomaly interception module, wherein: The semantic analysis module, located within the executor, processes proposal transaction requests received from the client by the execution node. Its core function is to parse the call semantics carried in the proposal transaction request before the chaincode is actually executed, thereby extracting structured information reflecting resource consumption characteristics. Specifically, the semantic analysis module parses each item in the proposal transaction request, including the chaincode identifier, the method name, and the parameter list, and performs structured analysis on the parameter data, including but not limited to statistical parameter length, nesting level analysis, and data type identification.
[0038] The resource assessment module is used to quantify the semantic feature vector output by the semantic analysis module to obtain the resource requirement score of the proposed transaction request, and further generate the corresponding resource budget parameters. The role of the resource assessment module is to transform abstract semantic information into numerical indicators that can be used for resource scheduling decisions.
[0039] The entry scheduling module, located at the entry point of chaincode execution, has the core function of making scheduling decisions for proposal transaction requests based on resource scores and the current system load before chaincode execution. By introducing scheduling strategies, the entry scheduling module pre-controls high-risk proposal transaction requests, preventing them from directly entering the execution phase when the system load is high.
[0040] The execution monitoring module is used to monitor the interaction between the chaincode and the executor in real time during chaincode execution. It obtains the actual resource usage of the chaincode through statistical analysis of the execution operations, providing data support for the dynamic adjustment module.
[0041] By implementing the monitoring module, fine-grained awareness of chaincode execution behavior can be achieved, enabling the system to make dynamic adjustments based on actual operating conditions, rather than relying solely on pre-execution predictions.
[0042] The dynamic adjustment module's main function is to adjust the chaincode execution rate based on real-time data provided by the execution monitoring module during chaincode execution, thereby achieving soft rate limiting control.
[0043] The anomaly interception module, as a system security mechanism, is used to detect and handle extreme anomalies during chaincode execution. Its core function is to promptly terminate abnormal proposal transaction requests when the soft rate limiting mechanism fails to effectively control resource consumption, thus preventing system crashes.
[0044] based on Figure 1 The chaincode resource scheduling device shown in this disclosure provides a chaincode resource scheduling method, such as... Figure 2 As shown, it includes the following steps: S21. Receive proposal transaction requests, perform semantic parsing on the proposal transaction requests, extract semantic features representing resource consumption, and generate semantic feature vectors.
[0045] Step S21 is implemented by the semantic analysis module. Specifically, the semantic analysis module receives the proposal transaction request submitted by the client and extracts the following semantic features from the proposal transaction request: ChaincodeID (chaincode identifier), Function (call function name, such as BatchTransfer), and Args (parameter list).
[0046] For the parameter list, obtain its array length or byte size to determine the scale of parameter operations in the proposal transaction request. Based on the function call name or parameter keywords, match and identify the parameter operation type of the proposal transaction request, where the parameter operation type includes at least one of the following: "write-intensive operation", "read-intensive operation", and "batch operation"; and query the historical execution data of the corresponding chaincode based on the chaincode identifier, including information such as the historical read / write set size, average execution time, and historical resource consumption level.
[0047] Furthermore, the parameter operation scale, parameter operation type, and historical execution data are encoded into semantic feature vectors. In one embodiment, the generated semantic feature vector has the following format:
[0048] The semantic analysis module performs structured analysis on a JSON array containing 100,000 accounts in the parameter list: First, the array length is calculated to be 100,000 and the byte size is 20MB, thus determining the parameter scale as "large-scale input". Second, through keyword matching, it is identified that BatchTransfer belongs to "write-intensive operation" and "batch operation". Finally, by using the chain code identifier to query the local cache, it is found that the average execution time of the corresponding chain code in the past week is 5 seconds and the average size of the generated read-write set is 50MB.
[0049] Based on the above information, the semantic analysis module generates a four-dimensional semantic feature vector:
[0050] The generated semantic feature vector is used as input to the resource assessment module to characterize the potential characteristics of the proposed transaction request in terms of resource consumption.
[0051] The semantic analysis module can make a preliminary judgment on the resource requirements of a proposed transaction request without actually executing the chaincode, thereby achieving proactive control before chaincode execution.
[0052] S22. Generate resource budget parameters based on semantic feature vectors.
[0053] Step S22 is implemented by the resource assessment module. Specifically, the resource module predefines a set of weight parameters, including parameter size weights. Operation type weight Read / write intensity weight Weighting of historical execution data One or more of these. Based on the defined weight parameters, a resource scoring function can be constructed according to the following formula: = / O+
[0054] The resource scoring function calculates a weighted score based on parameter size, operation type, I / O intensity, and historical behavior characteristics. The higher the score, the greater the potential resource consumption of the proposed transaction request, and thus the higher the execution risk of the proposed transaction request.
[0055] After obtaining the resource score, the resource assessment module generates corresponding resource budget parameters based on the score range mapping, including constraints such as maximum allowed execution time, maximum read / write set size, and maximum operation frequency threshold. For example, for proposal transaction requests with higher scores, a lower operation frequency threshold or a more stringent execution time limit can be assigned. An example is shown below: Maximum allowed execution time: =30s Maximum read / write set size: =100MB Maximum operating frequency threshold: / s means that a maximum of 1000 status read and write operations are allowed per second.
[0056] In step S22, the executor transforms abstract semantic information into quantifiable resource constraints, achieving the transition from "prediction" to "control" and providing a basis for subsequent resource scheduling and control. S23. Determine the execution method for the proposal transaction request based on resource budget parameters and real-time resource load information.
[0057] Step S23 is implemented by the entry scheduling module. In practice, the entry scheduling module first obtains real-time resource load information of the execution node through the system interface, including indicators such as CPU utilization, memory utilization, and disk I / O load; then, it performs joint analysis on the above system load information and the resource score output by the resource evaluation module.
[0058] If the real-time resource load information determines that the current resource load is lower than the preset resource load threshold, i.e., the system is in a low-load state, then the proposal transaction request is allowed to directly enter the execution stage. If the real-time resource load information determines that the current resource load is not lower than the preset resource load threshold, i.e., the system is in a high-load state, then it is further determined whether the resource score is greater than the preset first resource score threshold. If it is greater than the first resource score threshold, i.e., the current proposal transaction request is determined to be a high-risk proposal, then it is added to the scheduling queue and its execution is delayed. If the resource score is greater than the preset second resource score threshold, i.e., the current proposal transaction request is determined to be an extremely high-risk proposal, then execution is rejected or an error message is returned.
[0059] In one embodiment, the entry scheduling module maintains a priority-based scheduling queue, and sorts the proposal transaction requests that have entered the waiting state in order of resource score from low to high or business priority from high to low, thereby achieving more refined resource allocation.
[0060] The entry scheduling mechanism effectively prevents high-risk proposal transactions from being executed in a concentrated manner under high system load. Compared to existing technologies that forcibly terminate execution only after resources are exhausted or time expires, this embodiment of the disclosure, by performing semantic analysis and resource scoring before chaincode execution, can predict risks before transactions actually consume resources and perform entry scheduling in conjunction with real-time system load. This proactive control effectively prevents high-risk proposal transaction requests from flooding in when the system is under high load, ensuring system stability from the source.
[0061] S24. When executing the proposal transaction request according to the determined execution method, determine whether the current operation frequency of the chaincode is greater than the maximum operation frequency threshold. If yes, execute step S25; otherwise, execute step S26.
[0062] Once the proposal transaction request passes the entry scheduling, the executor initiates the chaincode execution process and simultaneously enters the execution monitoring phase. Step S24 is implemented by the execution monitoring module. During chaincode execution, the execution monitoring module intercepts interaction messages between the chaincode and the executor to identify and statistically analyze key operations.
[0063] For example, for state read and state write operations, the execution monitoring module records the operation each time the chaincode initiates a state read or state write operation, and uses a sliding window counting mechanism to count the number of operations per unit time, thereby calculating the current operation frequency of the chaincode. The executor continuously updates this statistical data and uses it as a reflection of the real-time resource usage of the chaincode.
[0064] If a high frequency of similar operations is detected within a unit of time (e.g., the frequency of similar operations exceeds a preset threshold), and the operation sequence exhibits continuous characteristics, it is determined that the current chaincode execution contains cyclical or batch processing behavior. This determination does not depend on the chaincode source code, but is based on the chaincode execution behavior characteristics detected at runtime, thus making it suitable for scenarios where the chaincode execution logic is not visible.
[0065] For example, within a preset sliding window, if the number of status read operations is continuously increasing, it can be determined that the chaincode is in a high-frequency I / O state. The execution monitoring module will transmit the statistical results to the dynamic adjustment module in real time to determine whether soft rate limiting is required.
[0066] S25. Generate a delayed injection time based on the maximum operation frequency threshold and the current operation frequency; execute the operation with a delay based on the delayed injection time.
[0067] Based on the monitoring, the actuator enters the dynamic adjustment stage, and step S25 is implemented by the dynamic adjustment module.
[0068] In practice, the dynamic adjustment module compares the current operation frequency provided by the execution monitoring module with the maximum operation frequency threshold in the resource budget parameters. If the current operation frequency exceeds the maximum operation frequency threshold, a soft rate limiting mechanism is triggered, reducing the chaincode execution speed by injecting a delay into the execution flow. Specifically, when the current operation frequency is determined to be greater than the maximum operation frequency threshold, the dynamic adjustment module introduces delay control logic into the chaincode execution flow. Each time the chaincode initiates a status operation request, a delay time is calculated based on the difference between the current operation frequency and the maximum operation frequency threshold, and the corresponding time is paused before the next operation. This delay injection mechanism causes the chaincode to wait for a certain period before the next operation. This delay time can be dynamically adjusted according to the degree to which the current operation frequency exceeds the maximum operation frequency threshold, thereby achieving adaptive adjustment of the chaincode execution rate.
[0069] Unlike traditional control methods that terminate execution upon resource exhaustion, this embodiment employs a non-terminating adjustment mechanism. When resource usage exceeds a preset threshold, a delay signal is injected into the chaincode execution flow to continuously adjust the chaincode execution rate. The delay time is dynamically calculated based on the difference between the current resource usage level and the maximum operating frequency threshold, thus forming an adaptive adjustment mechanism that transforms the chaincode execution process from "sudden resource consumption" to "smooth resource usage." In this way, the actuator can effectively reduce the resource consumption rate without terminating chaincode execution, enabling reasonable allocation of system resources.
[0070] S26. Continue executing the chain code and return to step S24.
[0071] During chaincode execution, the executor continuously performs anomaly detection, a function implemented by the anomaly interception module. Specifically, the anomaly interception module continuously monitors the chaincode execution status, including metrics such as read / write set size, execution time, and resource usage trends. When any of the following anomalies are detected, the interception mechanism is triggered: the read / write set size exceeds a preset threshold, the execution time exceeds the maximum limit, or resource consumption shows an abnormal growth trend. Once the interception condition is triggered, the anomaly interception module immediately interrupts the chaincode execution process, returns an error result to the client, and records an anomaly log for subsequent analysis and optimization.
[0072] The anomaly interception module serves as the system's last line of defense, addressing extreme situations that the soft rate limiting mechanism cannot effectively control. It complements the dynamic adjustment module, working together to ensure the stable operation of the system.
[0073] If no exception is triggered, after the chaincode is executed, the executor generates the corresponding read / write set and execution result, and returns the result to the client, thus completing the proposed transaction request.
[0074] Figure 3 As shown, it is a schematic diagram of the specific implementation process of the present disclosure embodiment. Its implementation process is the same as the chaincode resource scheduling method described above, and will not be repeated here.
[0075] This invention achieves closed-loop control of the entire chaincode execution process by performing semantic analysis and resource requirement prediction before chaincode execution, real-time monitoring and dynamic adjustment during chaincode execution, and timely interception in abnormal situations. This enables the actuator to have active scheduling and adaptive adjustment capabilities, thereby significantly improving the system's stability and resource utilization efficiency.
[0076] This invention achieves a shift from passive control to proactive governance by performing semantic-level resource prediction before chaincode execution and implementing dynamic adjustments during execution. Compared to existing technologies, this invention effectively avoids the impact of high-load transactions on execution nodes, improving system stability. Simultaneously, by replacing forced termination with a soft rate-limiting mechanism, chaincode execution becomes smoother, improving resource utilization efficiency. Furthermore, this invention combines real-time system load scheduling to achieve more rational resource allocation.
[0077] To better understand the present invention, the implementation process of this disclosure will be described below in conjunction with specific embodiments.
[0078] (1) Basic scenario When the execution node receives a proposal transaction request, it will proceed according to the following process: ① The semantic analysis module parses the parameters and identifies that this proposal transaction request is a batch write operation; ② The resource assessment module calculates high resource scores; ③ The entry scheduling module detects that the system load is 80% and proposes to delay the execution of the transaction request; ④ During execution, the monitoring module detected frequent read and write operations; ⑤ Dynamically adjust module injection delay to reduce execution speed; ⑥ The execution was successfully completed.
[0079] (2) Abnormal scenario: high frequency of chain code reading ① The sliding window detected that the operating frequency domain exceeded the maximum frequency operating threshold within 100ms; ② The dynamic adjustment module continuously injects delay; ③ If the threshold is still exceeded, the exception interception module will terminate execution.
[0080] (3) High concurrency scenario: Multiple highly complex proposals enter simultaneously ① The system sorts resources based on their scores; ② High-risk transactions are queued; ③ Prioritize low-load transactions; ④ The system as a whole remains stable.
[0081] It should be noted that the executor in this embodiment does not parse or modify the chaincode source code. Instead, it analyzes the interactive behaviors generated during chaincode execution to perceive and control the chaincode execution state. Therefore, this embodiment is applicable to chaincode implemented in different programming languages and chaincode environments with different deployment methods.
[0082] The resource regulation mechanism in this invention can be implemented in various ways. For example, the delayed injection strategy can be replaced by a rate limiting method based on token bucket, leaky bucket, or priority scheduling; the resource scoring model can be implemented using a rule-based model, machine learning model, or historical statistical model; and the execution monitoring mechanism can also be implemented through time windows or sampling strategies of different granularities. All of the above alternatives fall within the scope of protection of this invention.
[0083] Based on the above method, this disclosure also provides a chaincode resource scheduling apparatus corresponding to the above method, used to implement the above method, including: The semantic analysis module is used to receive proposal transaction requests, perform semantic parsing on the proposal transaction requests, extract semantic features representing resource consumption, and generate semantic feature vectors. The resource assessment module is used to generate resource budget parameters based on the semantic feature vector, wherein the resource budget parameters include a maximum operating frequency threshold. The entry scheduling module is used to determine the execution method of the proposal transaction request based on the resource budget parameters and actual resource load information. The execution monitoring module is used to determine whether the current operation frequency of the chaincode is greater than the maximum operation frequency threshold when the proposal transaction request is executed according to the execution method. The dynamic adjustment module is used to generate a delay injection time based on the maximum operation frequency threshold and the current operation frequency when the execution monitoring module determines that the current operation frequency of the chaincode is greater than the maximum operation frequency threshold; and to delay execution based on the delay injection time.
[0084] Based on the same inventive concept as the above disclosure, this disclosure also provides an electronic device. The electronic device of this disclosure includes at least one processor and at least one memory electrically connected to the processor. The memory is electrically connected to the processor, wherein the memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method described above.
[0085] It should be noted that the electrical connection between the above-mentioned units does not necessarily mean the connection between lines. The indirect connection method can be applied to the embodiments of this disclosure as long as it achieves the purpose of this disclosure.
[0086] Based on the same inventive concept, this disclosure also provides a computer storage medium storing a computer program, which, when executed by a processor, implements the above-described method.
[0087] Although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A chaincode resource scheduling method, characterized in that, include: Receive a proposal transaction request, perform semantic parsing on the proposal transaction request, extract semantic features representing resource consumption, and generate a semantic feature vector; Based on the semantic feature vector, resource budget parameters are generated, including a maximum operation frequency threshold. Based on the resource budget parameters and real-time resource load information, determine the execution method of the proposal transaction request; When executing the proposal transaction request according to the execution method, if it is determined that the current operation frequency of the chaincode is greater than the maximum operation frequency threshold, a delay injection time is generated based on the maximum operation frequency threshold and the current operation frequency. Execution is delayed according to the aforementioned delayed injection time.
2. The method according to claim 1, characterized in that, The semantic features include chaincode identifier, function call name, and parameter list; Receiving a proposal transaction request, performing semantic parsing on the proposal transaction request, extracting semantic features representing resource consumption to generate a semantic feature vector, including: Obtain the array length or byte size of the parameter list to determine the parameter operation scale of the proposal transaction request; Based on the function name or parameter keyword, match and identify the parameter operation type of the proposal transaction request; Based on the chaincode identifier, query the historical execution data of the corresponding chaincode; The parameter operation scale, parameter operation type, and historical execution data are encoded into semantic feature vectors.
3. The method according to claim 2, characterized in that, The resource budget parameters also include the maximum allowed execution time and the maximum read / write set size; Based on the semantic feature vector, resource budget parameters are generated, including: A resource scoring function is constructed based on a predefined set of weight parameters, wherein the weight parameters include one or more of the following: parameter size weight, operation type weight, read / write intensity weight, and historical execution data weight. Based on the semantic feature vector and the resource scoring function, the resource score of the proposal transaction request is determined, and resource budget parameters are generated by mapping the numerical range of the resource score.
4. The method according to claim 3, characterized in that, Based on the resource budget parameters and real-time resource load information, the execution method of the proposal transaction request is determined, including: If the current resource load is determined to be lower than the preset resource load threshold based on real-time resource load information, the proposal transaction request is allowed to directly enter the execution phase. If, based on real-time resource load information, it is determined that the current resource load is not lower than the resource load threshold and the resource score is greater than the preset first resource score threshold, then the proposal transaction request is added to the scheduling queue. If, based on real-time resource load information, it is determined that the current resource load is not lower than the resource load threshold and the resource score is greater than a preset second resource score threshold, then the proposal transaction request is rejected.
5. The method according to claim 4, characterized in that, The scheduling queue is used to execute tasks in order of resource score from low to high or in order of business priority from high to low.
6. The method according to claim 1, characterized in that, When executing the proposal transaction request according to the aforementioned execution method, the current operation frequency is determined according to the following process: A sliding window is used to count the cumulative number of status read requests or status write requests within a set time window; The current operation frequency is defined as the number of status read requests or status write requests per unit of time.
7. The method according to any one of claims 1-6, characterized in that, The process of executing the proposed transaction request also includes: Real-time monitoring of chaincode execution status, wherein the chaincode execution status includes at least one of the following: read / write set size, execution time, and resource usage trend; If the execution state of the chaincode is determined to be abnormal, the execution of the chaincode is interrupted.
8. A chaincode resource scheduling device, characterized in that, include: The semantic analysis module is used to receive proposal transaction requests, perform semantic parsing on the proposal transaction requests, extract semantic features representing resource consumption, and generate semantic feature vectors. The resource assessment module is used to generate resource budget parameters based on the semantic feature vector, wherein the resource budget parameters include a maximum operating frequency threshold. The entry scheduling module is used to determine the execution method of the proposal transaction request based on the resource budget parameters and actual resource load information. The execution monitoring module is used to determine whether the current operation frequency of the chaincode is greater than the maximum operation frequency threshold when the proposal transaction request is executed according to the execution method. The dynamic adjustment module is used to generate a delay injection time based on the maximum operation frequency threshold and the current operation frequency when the execution monitoring module determines that the current operation frequency of the chaincode is greater than the maximum operation frequency threshold. Execution is delayed according to the aforementioned delayed injection time.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.
10. A computer storage medium, characterized in that, The computer storage medium stores a computer program, which, when executed by a processor, implements the method described in any one of claims 1-7.
