Method for realizing service current-limiting fusing degradation based on Cangjie language element programming

By using the meta-programming function in Cangjie language, marking the fuse macro on the function and compiling the insert code, the implementation problems of current limiting, fuse and service downgrade in Cangjie language are solved, and the decoupling of the fuse function and flow control from the business system are realized, reducing the system complexity.

CN120491943APending Publication Date: 2025-08-15BEIJING BAOLANDE SOFTWARE CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510727672.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-03
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

In the Cangjie language ecosystem, the mechanisms of current limiting, circuit breaking and service downgrade have not yet been implemented, resulting in the microservice system being prone to hemorrhage effects when it fails, and the existing technology needs to be hard-coded with the business system to increase the system complexity.

Method used

Using the meta-programming function of Cangjie language, the function is marked with the macro calls related to the fuse on the function and the code is inserted during the compilation period to achieve the decoupling of the fuse function similar to the AOP section and the business system. By defining rules, collecting indicators, fuse and downgrade, service current limiting and fuse downgrade are achieved.

Benefits of technology

It realizes the decoupling of the circuit breaker function and the business system, reduces the system complexity, and realizes the AOP-like sectional capabilities in the Cangjie language, supporting flow control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120491943A_ABST
    Figure CN120491943A_ABST
Patent Text Reader

Abstract

The invention relates to a method for realizing service current-limiting fusing degradation based on Cangjie language element programming. The method comprises the following steps: defining a rule; limiting rules are preset, and responding limiting rules are preset for different indexes; index collection: collecting index real-time parameters with preset restriction rules; fusing, if the resource limiter is called in an sdk mode, a starting function of the resource limiter is called before an original service code, and whether fusing needs to be carried out or not is judged according to indexes; if the limited function is marked as a limited resource in a macro mode, fusing is automatically carried out when a resource limiter is called; and degradation: when monitoring that the index needs to be fused, not throwing out abnormity, but calling a configured degradation function in advance. According to the method, a meta-programming function of Cangjie language is utilized, in a business system programming process, only fusing related macro calling needs to be marked on a function, and a code is inserted in a compiling period, so that a using method similar to an AOP section is realized, and a fusing function and business system decoupling are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer software technology, and in particular to a method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming. Background Art

[0002] In microservice systems, rate limiting, circuit breaking, and downgrade mechanisms are common mechanisms for maintaining system stability. When a service in a cluster fails, all dependent services can experience issues because microservices often rely on each other. This phenomenon is commonly known as the "blood-smashing effect."

[0003] To deal with the service's bleeding effect and improve its robustness, the method generally adopted is to limit the flow of requests and perform circuit breaking and degradation of services according to certain indicators.

[0004] Currently, mature products for rate limiting, circuit breaking, and service degradation already exist in some language ecosystems. However, they have not yet been implemented and applied in the Cangjie language ecosystem.

[0005] Compared to implementations in other languages, for example, Sentinel in the Java ecosystem leverages Spring's AOP aspect programming capabilities to decouple circuit breaking functionality from business systems. However, AOP aspect functionality is not available in version 20240430 of Cangjie's current web development framework, Silo. Implementing circuit breaking and downgrade functionality would require hard-coding it into the business system code, significantly increasing the complexity of the business system. Summary of the Invention

[0006] In order to solve the above technical problems, the present application provides a method for implementing service flow limiting, circuit breaking and degradation based on Cangjie language metaprogramming. By utilizing the metaprogramming function of Cangjie language, it is only necessary to mark the circuit breaking related macro calls on the function during the business system programming process, and insert the code during the compilation period to achieve usage similar to AOP aspects, thereby realizing the decoupling of the circuit breaking function and the business system.

[0007] In a first aspect, the present invention provides a method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, which adopts the following technical solutions: A method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming includes the following steps: Define rules, including: Configuration rules include custom resource names and control indicators. Control indicators include maximum concurrency, TPS, average response time, number of exceptions within time period T, and custom expansion indicators. The definition rule includes code mode definition and / or configuration file mode definition; Preset restriction rules: preset response restriction rules for different indicators, including more intrusive and less intrusive rules; The most intrusive method is to add resource limiter code before and after the restriction code by calling the SDK; A less invasive method uses Cangjie language metaprogramming to mark attribute macros on restricted functions. The attributes are resource names. Macros are a source code marker and are automatically expanded during compilation. The expanded code is the same as the code called by the SDK method. Collecting indicators, collecting real-time parameters of indicators with preset restriction rules, and comparing the real-time parameters of the indicators with the preset restriction rules of the indicators; Circuit breaker: If you use the SDK to call the resource limiter, calling the resource limiter's start function before the original business code will determine whether circuit breaker is needed based on the indicators; if you use the macro method to mark the restricted function as resource restricted, the circuit breaker will be automatically triggered when the resource limiter is called; Degradation: When the monitored indicator needs to be circuit-breakered, no exception is thrown, but the configured degradation function is called in advance.

[0008] Preferably, the code definition is to write the rule code in a hard-coded manner during the project initialization phase or during operation, and then be loaded by the rule manager; The configuration file method is defined by writing the rule configuration into an XML configuration file. During project initialization or operation, the configuration file is loaded by the rule manager and parsed into rules.

[0009] Preferably, the downgraded function is required to have no parameters and the return value type is the same as that of the original function.

[0010] In a second aspect, the present invention provides a device for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, which adopts the following technical solutions: A device for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, comprising: The rule definition module is used to define rules, including: The rule configuration unit is used to configure rules, including custom resource names and control indicators. The control indicators include the maximum number of concurrent users, TPS, average response time, number of exceptions within time period T, and custom expansion indicators. A rule definition unit is used to define rules, wherein the rule definition includes code definition and / or configuration file definition; The restriction rule preset module is used to preset restriction rules. The restriction rules that respond to different indicators are preset. The rule methods include more intrusive methods and less intrusive methods. The intrusive comparison unit is used to implement the intrusive comparison method, adding resource limiter code before and after the restriction code in the form of SDK calls; The intrusive comparison unit is used to implement a less intrusive method. It uses the metaprogramming of the Cangjie language to mark the attribute macro on the restricted function. The attribute is the resource name. The macro is a source code marker and is automatically expanded during the compilation process. The expanded code is the same as the code called by the SDK method. An indicator collection module is used to collect indicators, collect real-time parameters of indicators with preset restriction rules, and compare the real-time parameters of the indicators with the preset restriction rules of the indicators; The circuit breaker module is used to implement circuit breaking. If the resource limiter is called using the SDK, the start function of the resource limiter is called before the original business code. The circuit breaker will determine whether circuit breaking is required based on the indicators. If the restricted function is marked as resource restricted using a macro, the circuit breaker will be automatically triggered when the resource limiter is called. The degradation module is used to implement degradation. When it detects that an indicator needs to be fused, it does not throw an exception but calls the configured degradation function in advance.

[0011] Preferably, the rule definition unit includes: The code definition component is used to implement code definition. During the project initialization phase or during operation, the rule code is written in a hard-coded manner and loaded by the rule manager. The configuration file method definition component is used to implement the configuration file method definition and write the rule configuration into the XML configuration file. During project initialization or at runtime, the configuration file is loaded by the rule manager and parsed into rules.

[0012] In a third aspect, the present application provides an electronic device, which adopts the following technical solution: An electronic device, comprising: one or more processors; Memory; One or more applications, wherein one or more applications are stored in a memory and configured to be executed by one or more processors, and the one or more programs are configured to: execute a method for implementing service flow limiting, circuit breaking and degradation based on Cangjie language metaprogramming as shown in any possible implementation of the first aspect.

[0013] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium, comprising: a computer program that can be loaded and executed by a processor to implement a method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming as shown in any possible implementation method of the first aspect.

[0014] In summary, the present invention has the following beneficial technical effects: 1. By utilizing the metaprogramming function of the Cangjie language, the present invention only needs to mark the circuit breaker-related macro calls on the function during the business system programming process, and insert the code during the compilation period to achieve usage similar to AOP aspects, thereby decoupling the circuit breaker function from the business system.

[0015] 2. The present invention uses the Cangjie language metaprogramming method to mark attribute macros on the target function. When the program is compiled, a code surrounding the target function will be generated. Indicators are collected before the target code is executed, and it is determined based on the indicators whether the target function can be executed or a fuse exception is thrown, thereby realizing the fuse function.

[0016] 3. In the implementation of Cangjie language, the present invention does not rely on any external library except the built-in function names of Cangjie language, and can use all functions. It is not even limited to web projects in use, and can still be used in console projects. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 is a flow chart of a method in an embodiment of the present invention. DETAILED DESCRIPTION

[0018] The present invention will be further described in detail below with reference to the accompanying drawings.

[0019] An embodiment of the present invention discloses a method for implementing service current limiting, fusing and degradation based on Cangjie language metaprogramming.

[0020] Reference Figure 1 The method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming includes the following steps: S1. Define rules, including the following steps: S11. Configuration rules include custom resource names and control indicators. Control indicators include providing maximum concurrency, TPS, average response time, number of exceptions within time period T, and support for custom expansion indicators.

[0021] S12. There are two ways to define rules: code definition and / or configuration file definition.

[0022] Code definition: During the project initialization phase or during operation, the rule code is hard-coded and loaded by the rule manager. The rule configuration is defined in the configuration file mode, and the rule configuration is written into the XML configuration file. During project initialization or operation, the configuration file is loaded by the rule manager and parsed into rules.

[0023] S2. Preset restriction rules: preset response restriction rules for different indicators. The rule methods include more intrusive methods and less intrusive methods. The most intrusive method is to add resource limiter code before and after the restriction code by calling the SDK; A less invasive method uses Cangjie language metaprogramming to mark attribute macros on restricted functions. The attributes are resource names. Macros are a source code marker and are automatically expanded during compilation. The expanded code is the same as the code called by the SDK method. S3. Collecting indicators: collecting real-time parameters of indicators with preset restriction rules, and comparing the real-time parameters of the indicators with the preset restriction rules of the indicators; For example, if the current function is configured to limit the number of threads based on the maximum number of threads, then when a request accesses the current function, the thread counter value is incremented and only the number of threads is counted. When the request ends, the thread counter value is decremented.

[0024] S4. Circuit breaking: If you use the SDK to call the resource limiter, calling the resource limiter's start function before the original business code will determine whether circuit breaking is needed based on the indicators. If you use the macro method to mark the restricted function as resource restricted, the circuit breaking will be automatically performed when the resource limiter is called. S5, downgrade; Downgrade means that when the circuit breaker module determines that a circuit breaker is needed based on monitoring indicators, it does not throw an exception. Instead, it pre-calls the configured downgrade function. The downgrade function must have no parameters and the same return value type as the original function.

[0025] The current microservice flow control, circuit breaking, and degradation solutions are strongly bound to specific programming languages. Existing technical implementations cannot be used directly in Cangjie language projects. This method makes up for the deficiency of Cangjie language projects in being unable to perform flow control. It implements the circuit breaking and degradation functions that are decoupled from the business system in the Cangjie language. In other languages, taking Java as an example, the existing circuit breaking framework uses the AOP aspect capability of Spring to decouple the circuit breaking and degradation functions from the business code. Currently, Cangjie's web framework does not have AOP capabilities. This method uses the metaprogramming capabilities at the Cangjie language level to implement capabilities similar to AOP, loosely coupling the circuit breaking and degradation functions with the business code.

[0026] The present application also discloses a device for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, which includes the following modules or units: The rule definition module is used to define rules, including: The rule configuration unit is used to configure rules, including custom resource names and control indicators. The control indicators include the maximum number of concurrent users, TPS, average response time, number of exceptions within time period T, and custom expansion indicators. A rule definition unit is used to define rules, wherein the rule definition includes code definition and / or configuration file definition; The rule definition unit includes: The code definition component is used to implement code definition. During the project initialization phase or during operation, the rule code is written in a hard-coded manner and loaded by the rule manager. The configuration file method definition component is used to implement the configuration file method definition and write the rule configuration into the XML configuration file. During project initialization or at runtime, the configuration file is loaded by the rule manager and parsed into rules.

[0027] The restriction rule preset module is used to preset restriction rules. The restriction rules that respond to different indicators are preset. The rule methods include more intrusive methods and less intrusive methods. The intrusive comparison unit is used to implement the intrusive comparison method, adding resource limiter code before and after the restriction code in the form of SDK calls; The intrusive comparison unit is used to implement a less intrusive method. It uses the metaprogramming of the Cangjie language to mark the attribute macro on the restricted function. The attribute is the resource name. The macro is a source code marker and is automatically expanded during the compilation process. The expanded code is the same as the code called by the SDK method. An indicator collection module is used to collect indicators, collect real-time parameters of indicators with preset restriction rules, and compare the real-time parameters of the indicators with the preset restriction rules of the indicators; The circuit breaker module is used to implement circuit breaking. If the resource limiter is called using the SDK, the start function of the resource limiter is called before the original business code. The circuit breaker will determine whether circuit breaking is required based on the indicators. If the restricted function is marked as resource restricted using a macro, the circuit breaker will be automatically triggered when the resource limiter is called. The downgrade module is used to implement downgrade. When it detects that an indicator needs to be circumvented, it does not throw an exception. Instead, it calls the configured downgrade function in advance. The downgrade function is required to have no parameters and the return value type is the same as the original function.

[0028] An embodiment of the present application provides an electronic device comprising a processor and a memory. The processor and the memory are connected, for example, via a bus. Optionally, the electronic device may further comprise a transceiver. It should be noted that in actual applications, there is not limited to one transceiver, and the structure of the electronic device does not constitute a limitation on the embodiments of the present application.

[0029] A processor can be a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. A processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, or a combination of a DSP and a microprocessor.

[0030] A bus may include a path for transmitting information between the components. A bus may be a Peripheral Component Interconnect (PCI) bus or an Extended Industrial Standard Architecture (EISA) bus. Buses may be categorized as address buses, data buses, and control buses.

[0031] The memory may be a read-only memory ROM or other type of static storage device that can store static information and instructions, a random access memory RAM or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory EEPROM, a read-only compact disc CD-ROM or other optical disc storage, an optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.

[0032] The memory is used to store application code for executing the solution of the present application, and the execution is controlled by the processor. The processor is used to execute the application code stored in the memory to implement the content shown in the embodiment of a method for implementing service flow limiting, circuit breaking and degradation based on Cangjie language metaprogramming.

[0033] Electronic devices include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. They may also include servers, etc.

[0034] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content of an embodiment of a method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming.

[0035] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0036] The above are all preferred embodiments of the present application, and are not intended to limit the scope of protection of the present application. Therefore, any equivalent changes made based on the structure, shape, and principle of the present application should be included in the scope of protection of the present application.

Claims

1. A method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, characterized in that: The following steps are involved: Define rules, including: Configuration rules include custom resource names and control indicators. Control indicators include maximum concurrency, TPS, average response time, number of exceptions within time period T, and custom expansion indicators. The definition rule includes code mode definition and / or configuration file mode definition; Preset restriction rules: preset response restriction rules for different indicators, including more intrusive and less intrusive rules; The most intrusive method is to add resource limiter code before and after the restriction code by calling the SDK; A less invasive method uses Cangjie language metaprogramming to mark attribute macros on restricted functions. The attributes are resource names. Macros are a source code marker and are automatically expanded during compilation. The expanded code is the same as the code called by the SDK method. Collecting indicators, collecting real-time parameters of indicators with preset restriction rules, and comparing the real-time parameters of the indicators with the preset restriction rules of the indicators; Circuit breaker: If you use the SDK to call the resource limiter, calling the resource limiter's start function before the original business code will determine whether circuit breaker is needed based on the indicators; if you use the macro method to mark the restricted function as resource restricted, the circuit breaker will be automatically triggered when the resource limiter is called; Degradation: When the monitored indicator needs to be circuit-breakered, no exception is thrown, but the configured degradation function is called in advance.

2. According to the method of claim 1, which is characterized by: The code definition method is to write the rule code in a hard-coded manner during the project initialization phase or during operation, and then load it into the rule manager. The configuration file method is defined by writing the rule configuration into an XML configuration file. During project initialization or operation, the configuration file is loaded by the rule manager and parsed into rules.

3. The method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming according to claim 1 is characterized in that: The downgraded function is required to have no parameters and the return value type is the same as that of the original function.

4. A device for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming, characterized in that: include: The rule definition module is used to define rules, including: The rule configuration unit is used to configure rules, including custom resource names and control indicators. The control indicators include the maximum number of concurrent users, TPS, average response time, number of exceptions within time period T, and custom expansion indicators. A rule definition unit is used to define rules, wherein the rule definition includes code definition and / or configuration file definition; The restriction rule preset module is used to preset restriction rules. The restriction rules that respond to different indicators are preset. The rule methods include more intrusive methods and less intrusive methods. The intrusive comparison unit is used to implement the intrusive comparison method, adding resource limiter code before and after the restriction code in the form of SDK calls; The intrusive comparison unit is used to implement a less intrusive method. It uses the metaprogramming of the Cangjie language to mark the attribute macro on the restricted function. The attribute is the resource name. The macro is a source code marker and is automatically expanded during the compilation process. The expanded code is the same as the code called by the SDK method. An indicator collection module is used to collect indicators, collect real-time parameters of indicators with preset restriction rules, and compare the real-time parameters of the indicators with the preset restriction rules of the indicators; The circuit breaker module is used to implement circuit breaking. If the resource limiter is called using the SDK, the start function of the resource limiter is called before the original business code. The circuit breaker will determine whether circuit breaking is required based on the indicators. If the restricted function is marked as resource restricted using a macro, the circuit breaker will be automatically triggered when the resource limiter is called. The degradation module is used to implement degradation. When it detects that an indicator needs to be fused, it does not throw an exception but calls the configured degradation function in advance.

5. The device for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming according to claim 4 is characterized in that: The rule definition unit includes: The code definition component is used to implement code definition. During the project initialization phase or during operation, the rule code is written in a hard-coded manner and loaded by the rule manager. The configuration file method definition component is used to implement the configuration file method definition and write the rule configuration into the XML configuration file. During project initialization or at runtime, the configuration file is loaded by the rule manager and parsed into rules.

6. An electronic device, characterized in that: It includes: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to: execute a method for implementing service flow limiting, circuit breaking and degradation based on Cangjie language metaprogramming according to any one of claims 1 to 3.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the method for implementing service current limiting, circuit breaking and degradation based on Cangjie language metaprogramming as described in any one of claims 1 to 3.