Flow control method, device and equipment

By combining Nginx and Hystrix, the dual-layer control mechanism of the network layer and the application layer is realized, which solves the problem of difficult to achieve fine-grained flow control in the microservice architecture, and realizes more intelligent and refined flow control, improving the stability and scalability of the system.

CN119544616APending Publication Date: 2025-02-28AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411715672.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The prior art is difficult to achieve fine-grained flow control in microservice architectures, and cannot effectively deal with complex and dynamically changing service environments, resulting in fault propagation and system instability.

Method used

Combining Nginx and Hystrix, a two-layer control mechanism between the network layer and the application layer is realized. Nginx performs global traffic allocation and request speed limit at the network layer, and Hystrix provides fine-grained flow control through thread pool isolation and fuse mechanisms at the application layer.

Benefits of technology

More refined and comprehensive flow control is achieved, making flow control more intelligent, able to adapt to changing service needs and traffic patterns, improve the maintainability and scalability of the system, and enhance fault tolerance and adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119544616A_ABST
    Figure CN119544616A_ABST
Patent Text Reader

Abstract

The invention discloses a flow control method, device and equipment, and the method comprises the steps: filtering N request messages based on a flow limiting parameter configured in Nginx to obtain M request messages, N and M being natural numbers greater than 0, and N being less than or equal to M; the M request messages are classified into corresponding thread pools, the thread pools are isolation units of application-level granularity set by Hystrix, and each thread pool allows one thread to execute; and then, based on the execution condition of the thread in each thread pool and the fuse state of the Hystrix, determining a processing strategy for the request message in the thread pool. Therefore, by combining a double-layer control mechanism of a network layer (namely Nginx) and an application layer (namely Hystrix), finer and more comprehensive flow control is realized, so that the flow control is more intelligent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a flow control method, device and equipment. Background Art

[0002] As we all know, effective flow control is an important measure to ensure system stability and reliability. Traditional flow control methods usually rely on network-level restrictions, such as limiting the global request message rate. Although this method performs well when processing a large number of request messages, it cannot dynamically control specific services at the application level in detail. Especially in scenarios such as microservice architecture, the complex dependencies between services require more intelligent flow control strategies.

[0003] Based on this, there is an urgent need to provide a flow control method that can achieve finer granularity to make the flow control solution more intelligent. Summary of the invention

[0004] In order to solve the above technical problems, the present application provides a flow control method, device and equipment, which combines Nginx and Hystrix to implement a two-layer control mechanism at the network layer and the application layer, and provides a fine-grained flow control solution at the application level, making flow control more intelligent.

[0005] In order to achieve the above objectives, the technical solutions provided by this application are as follows:

[0006] In a first aspect, the present application provides a flow control method, comprising:

[0007] Based on the current limiting parameters configured in Nginx, N request messages are filtered to obtain M request messages, where both N and M are natural numbers greater than 0, and N is less than or equal to M;

[0008] The M request messages are classified into corresponding thread pools, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute;

[0009] Based on the execution status of each thread in the thread pool and the fuse status of the Hystrix, a processing strategy for the request message in the thread pool is determined.

[0010] Optionally, determining a processing strategy for request messages in the thread pool based on the execution status of each thread in the thread pool and the fuse status of the Hystrix includes:

[0011] If the number of thread executions in the thread pool reaches a first threshold, a processing strategy for the request message in the thread pool is determined based on the fuse status of the Hystrix.

[0012] Optionally, determining a processing strategy for the request message in the thread pool based on the fuse state of the Hystrix includes:

[0013] If the fuse state of the Hystrix is ​​on, the request message in the thread pool is rejected and a downgrade response message is returned;

[0014] If the fuse state of the Hystrix is ​​half-open, the request message in the thread pool enters waiting and retries after a preset time.

[0015] Optionally, the method further comprises:

[0016] If the failure rate reaches the second threshold and / or the response time reaches the third threshold, the fuse state of the Hystrix is ​​triggered to be open.

[0017] Optionally, the M request messages include a first request message, and the processing of the first request message includes:

[0018] Determine the current processing logic of the thread pool corresponding to the first request message based on the user information downgrade implementation class and the service downgrade abstract class;

[0019] If the current processing logic is a normal execution logic, the first request message is processed based on the run() function of the Hystrix;

[0020] If the current processing logic is an abnormal degradation logic, the first request message is processed based on the getFallback() function of the Hystrix.

[0021] Optionally, the configuration process of Hystrix includes:

[0022] Import Hystrix dependencies and create Hystrix commands;

[0023] Construct a run() function and a getFallback() function, wherein the getFallback() function is used to process abnormal degradation logic, and the run() function is used to process normal execution logic;

[0024] Configure the fuse parameters of Hystrix, where the fuse parameters include at least one of the following parameters: a threshold value for the number of request messages, a condition for opening the fuse, or a duration for opening the fuse.

[0025] In a second aspect, the present application also provides a flow control device, comprising:

[0026] A filtering unit, configured to filter N request messages based on the current limiting parameters configured in Nginx to obtain M request messages, where both N and M are natural numbers greater than 0, and N is less than or equal to M;

[0027] An isolation unit, used to classify the M request messages into a corresponding thread pool, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute;

[0028] The processing unit is used to determine a processing strategy for the request message in the thread pool based on the execution status of each thread in the thread pool and the fuse status of the Hystrix.

[0029] Optionally, the processing unit is specifically configured to:

[0030] If the number of thread executions in the thread pool reaches a first threshold, a processing strategy for the request message in the thread pool is determined based on the fuse status of the Hystrix.

[0031] Optionally, the processing unit includes:

[0032] The first processing subunit is used to refuse to execute the request message in the thread pool and return a downgrade response message if the fuse state of the Hystrix is ​​open;

[0033] The second processing subunit is used to, if the fuse state of the Hystrix is ​​half-open, the request message in the thread pool enters waiting and retries after a preset time.

[0034] Optionally, the device further comprises:

[0035] The state switching unit is used to trigger the fuse state of the Hystrix to be open if the failure rate reaches a second threshold and / or the response time reaches a third threshold.

[0036] Optionally, the M request messages include a first request message, and the processing of the first request message by the processing unit is specifically used to:

[0037] Determine the current processing logic of the thread pool corresponding to the first request message based on the user information downgrade implementation class and the service downgrade abstract class;

[0038] If the current processing logic is a normal execution logic, the first request message is processed based on the run() function of the Hystrix;

[0039] If the current processing logic is an abnormal degradation logic, the first request message is processed based on the getFallback() function of the Hystrix.

[0040] Optionally, the device further comprises a configuration unit;

[0041] The configuration unit is used to configure the Hystrix;

[0042] The configuration unit is specifically used for:

[0043] Import Hystrix dependencies and create Hystrix commands;

[0044] Construct a run() function and a getFallback() function, wherein the getFallback() function is used to process abnormal degradation logic, and the run() function is used to process normal execution logic;

[0045] Configure the fuse parameters of Hystrix, where the fuse parameters include at least one of the following parameters: a threshold value for the number of request messages, a condition for opening the fuse, or a duration for opening the fuse.

[0046] It should be noted that the specific implementation method of the device and the technical effects achieved can refer to the relevant description of the method provided in the first aspect or any implementation method of the first aspect.

[0047] In a third aspect, the present application further provides an electronic device, the electronic device comprising: a processor and a memory;

[0048] The memory is used to store instructions or programs;

[0049] The processor is used to execute the instructions or programs in the memory so that the electronic device executes the method provided by the first aspect or any one of the implementations of the first aspect.

[0050] In a fourth aspect, the present application further provides a readable medium, in which instructions or programs are stored. When the instructions or programs are executed on a processor, the processor executes the method provided by the first aspect or any one of the implementations of the first aspect.

[0051] Compared with the prior art, the embodiments of the present application have at least the following advantages:

[0052] In the technical solution provided by the present application, a flow control method is provided, which may include, for example: first, based on the current limiting parameters configured in Nginx, N request messages are filtered to obtain M request messages, where N and M are both natural numbers greater than 0, and N is less than or equal to M; then, the M request messages are classified into the corresponding thread pool, which is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute; then, based on the execution of threads in each thread pool and the fuse state of Hystrix, a processing strategy for the request messages in the thread pool is determined. In this way, Nginx is used as a front-end load balancer, responsible for global traffic distribution and request speed limiting, thereby providing the first line of defense at the network level; while Hystrix plays a role at the application level, and the isolation mechanism based on the thread pool and the fuse mechanism based on the fuse provide an independent flow control scheme for each service, so that by combining the double-layer control mechanism of the network layer (i.e., Nginx) and the application layer (i.e., Hystrix), a more refined and comprehensive flow control is achieved, making the flow control more intelligent. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0054] Figure 1 A schematic diagram of the structure of a system applicable to an embodiment of the present application;

[0055] Figure 2 A flow chart of a flow control method provided in an embodiment of the present application;

[0056] Figure 3 A schematic diagram of a process of Hystrix processing a request message provided in an embodiment of the present application;

[0057] Figure 4 A schematic diagram of the structure of a flow control device 400 provided in an embodiment of the present application;

[0058] Figure 5 A schematic diagram of the structure of an electronic device 500 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] With the rapid development of Internet applications and the increasing complexity of enterprise information technology (IT) architecture, it is particularly important to maintain high availability and stability of the system. In this context, traffic control has become a key measure to maintain the stable operation of the system. Traditional traffic control methods, such as using hardware load balancers or single network layer proxies (such as Nginx), perform well when handling high traffic, but they often lack sufficient flexibility and intelligence to cope with complex and dynamically changing service environments.

[0060] With the popularity of microservice architecture, more decentralized and distributed service management challenges have been brought about. In this architecture, the system is split into many small, independent services, and the services communicate with each other through the network. Such a microservice architecture design improves the flexibility and scalability of the system, but it also introduces complex dependencies and the risk of fault propagation. For example, under the microservice architecture, the failure of a single service may cause other services in the dependency chain of the service to be affected. It can also be understood that the current flow control method does not provide service-level fault isolation. This means that when a service has a problem, the fault cannot be automatically isolated and the fault cannot be prevented from spreading to the entire system. If a single service has a problem, calling this service will cause thread blocking. At this time, if a large number of requests flow in, the thread resources will be consumed, causing the service to paralyze. Due to the dependency between services, faults will propagate, causing catastrophic and serious consequences for the entire microservice system, resulting in an "avalanche" effect of service failures. It can be seen that the current flow control method lacks fault isolation, service degradation, and complex flow control logic. These limitations may affect the stability and resilience of distributed systems under high load and unstable environments.

[0061] In order to cope with the problems and higher demands in more complex and dynamically changing system frameworks, a more comprehensive and intelligent flow control solution is needed. Considering that Hystrix is ​​a fault-tolerant framework at the application layer, it provides a variety of protection mechanisms including circuit breaking, degradation, and isolation, which can effectively prevent the propagation of faults between services and maintain the basic availability of services. However, using Hystrix alone may not be able to fully manage the overall flow entering the system, especially in the face of large-scale and sudden traffic peaks, using only Hystrix for flow control is somewhat inadequate.

[0062] Therefore, the embodiment of the present application proposes a flow control scheme based on Hystrix and Nginx, and forms a double-layer protection mechanism by combining the network layer flow management capability of Nginx and the application layer fault tolerance capability of Hystrix. This mechanism can not only effectively allocate and limit flow at the network entrance (for example, the interface when the server receives the request message sent from the client) to avoid system overload, but also provide targeted service protection at the application level, enhance the overall stability and reliability of the system, and improve the system's self-recovery ability for unstable dependence and service anomalies. Such a comprehensive solution makes flow control more refined and intelligent, can adapt to changing service requirements and flow patterns, and effectively improves the maintainability and scalability of the system. In addition, the fault tolerance and self-adaptation capabilities of the system are also enhanced to ensure the stable operation of the system and the continuity of services under high concurrency and abnormal conditions.

[0063] As an example, the method provided in an embodiment of the present application may include: first, based on the current limiting parameters configured in Nginx, N request messages are filtered to obtain M request messages, where N and M are both natural numbers greater than 0, and N is less than or equal to M; then, the M request messages are classified into a corresponding thread pool, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute; then, based on the execution status of the threads in each thread pool and the fuse status of Hystrix, a processing strategy for the request messages in the thread pool is determined.

[0064] In this way, Nginx is used as the front-end load balancer, responsible for global traffic distribution and request rate limiting, thus providing the first line of defense at the network level; while Hystrix plays a role at the application level, and the thread pool-based isolation mechanism and the fuse-based fuse mechanism provide independent traffic control solutions for each service. In this way, by combining the two-layer control mechanism of the network layer (i.e. Nginx) and the application layer (i.e. Hystrix), more sophisticated and comprehensive traffic control can be achieved, making traffic control more intelligent.

[0065] In addition, in practice, the embodiments of the present application can dynamically adjust the flow control strategy and fault handling logic according to the real-time flow and service status. For example, when the system detects that the response time of a service has increased or the error rate has increased, the flow limit of the service can be automatically adjusted or the fuse mechanism can be triggered to prevent the problem from spreading and reduce the burden on the system. Moreover, through real-time data analysis and machine learning technology, flow trends and potential service risks can be predicted to further optimize flow distribution and fault prevention strategies.

[0066] Figure 1 A schematic diagram of the structure of a system to which the method provided in the embodiment of the present application is applicable is given. Figure 1As shown in Figure 1, when the client interacts with the server, the client sends a large number of request messages to the server, such as Figure 1 Request message 1 to request message N in, where N is an integer greater than 1. The server may include an Nginx cluster, an application service cluster and a database (DB). The Nginx cluster may include multiple Nginx to implement the Nginx current limiting strategy; the application service cluster may include multiple application servers to implement the Hystrix current limiting strategy. The server will first pass through the Nginx current limiting strategy, then pass through the Hystrix current limiting strategy, and finally enter the DB for the request message received. It should be noted that after Nginx receives the server's response to the request message, Nginx can forward it to the corresponding client.

[0067] It should be noted that the subject implementing the flow control method may be the flow control device provided in the embodiment of the present application. The flow control device may be carried in an electronic device or a functional module of an electronic device. The flow control device may be a functional module implementing the flow control function on the server, for example, Figure 1 The Nginx cluster and application service cluster in.

[0068] Some technical terms involved in the embodiments of the present application are introduced and explained below.

[0069] Nginx is a high-performance Hypertext Transfer Protocol (HTTP) and reverse proxy server, widely used in network-level traffic control and load balancing. With its lightweight, high-performance and easy-to-configure features, Nginx excels in processing static content, load balancing and HTTP caching. It can effectively disperse the server load and improve the overall processing capacity and response speed by processing client request messages and forwarding them to the appropriate server.

[0070] Hystrix is ​​a delay and fault tolerance library developed by Netflix to protect services in distributed systems from failures. Hystrix helps services maintain stable operation in the face of high load or service failures through mechanisms such as circuit breaking, isolation, and degradation. It can monitor the calls between services. Once a problem is found, such as call timeout or high error rate, the circuit breaker mechanism is activated to prevent the spread of the fault, and a degradation strategy is provided to maintain the lowest level of service operation.

[0071] Traffic control refers to the process of controlling the rate of data transmission or the number of access requests in network management. Traffic control aims to prevent network or system overload and ensure the rational allocation and optimal use of resources, thereby ensuring high performance and stability of the system. This includes limiting and adjusting the processing rate of data packets, the number of concurrent connections, and the access frequency. Effective traffic control can avoid network congestion, reduce data transmission delays, and improve the quality of the system's external services and user experience.

[0072] A fuse is an automated protection mechanism in a microservice architecture that prevents faults from propagating in a distributed system. When the error rate of a particular service exceeds a preset threshold, the fuse will "trip" (i.e., open), temporarily interrupting service calls to prevent the continued failure of the service from affecting other parts of the system. A fuse has three basic states: closed (also called closed, normal service), open (stop service), and half-open (partially restore service to test whether it returns to normal). This mechanism can quickly respond to service failures and reduce the overall risk of the system.

[0073] Figure 2 A flow chart of a flow control method provided in an embodiment of the present application is shown in FIG. The method can be applied to a flow control device, which can be, for example, Figure 4 The flow control device 400 is shown.

[0074] like Figure 2 As shown, the method may include, for example, the following S201 to S203:

[0075] S201, based on the current limiting parameters configured in Nginx, filter N request messages to obtain M request messages, where N and M are both natural numbers greater than 0, and N is less than or equal to M.

[0076] It is understandable that in the Nginx current limiting configuration script, the configuration of Nginx can be divided into three modules, namely, http module, server module and location module. Among them, the Nginx current limiting logic is to configure the current limiting parameters on the http module, and reference the corresponding current limiting parameters in the server module and location module. The current limiting parameters are used to indicate the execution details of the Nginx current limiting process.

[0077] As an example, the current limiting parameters may include but are not limited to: limit_req_zone and limit_conn_zone. Among them, limit_req_zone is used to set a shared memory area, which is used to store the status of each Internet Protocol (IP) address and the access frequency of the uniform resource locator (URL) of the restricted request. The specific configuration parameters may include: (1) key, which defines the request characteristics of the application restriction, usually using a binary client address; (2) zone, which defines the shared memory area used to store the status, including the name and size of the area; (3) rate, which defines the maximum request rate, such as 10 requests per second. Among them, limit_conn_zone is used to limit the number of concurrent connections for a specific IP address or IP address segment, which helps prevent malicious users from consuming server resources through a large number of connections and ensures the access speed and experience of normal users.

[0078] Assume that N=1000, M=100, that is, 1000 request messages are sent from the client to the server. After the flow limiting by Nginx in S201 according to the configured flow limiting parameters, only 100 of the 1000 request messages can enter the server. This can be understood as gateway flow limiting, which realizes the first layer of flow control in the embodiment of the present application.

[0079] In this way, through step S201, Nginx can implement global request current limiting, control the server entrance under high concurrency conditions, and ensure that no flooding occurs; Nginx can provide load balancing and failover as a reverse proxy.

[0080] S202, classify the M request messages into a corresponding thread pool, where the thread pool is an isolation unit of application-level granularity set by Hystrix.

[0081] Each thread pool only allows one thread to execute. If there are only 10 threads in the thread pool, at most 10 threads will execute, and not all resources will be used for execution. In this way, no more than this number of request messages will be executed, and all thread resources in the cache service will not be exhausted due to a failure of a dependent service.

[0082] Hystrix is ​​integrated at the application level and uses the most basic resource isolation technology - thread pool isolation technology. All call requests to a certain module (which can correspond to the application-level granularity in S202) are isolated into a thread pool. For example, if there are 100 request messages (i.e., M=100), if the 100 request messages come from 9 modules, then the 100 request messages are assigned to the thread pools corresponding to these 9 modules.

[0083] Corresponding to the scenario of banks, the module mentioned above can be understood as a transaction, or multiple transactions with application-level association. For example, access can be a transaction that forms a module (i.e., access module). For another example, multiple transactions related to loan issuance can be considered to belong to one module (i.e., loan issuance module). Therefore, the application-level granularity in S202 can be understood as the application-level transaction granularity.

[0084] S203, based on the execution status of the threads in each thread pool and the fuse status of Hystrix, determine the processing strategy for the request message in the thread pool.

[0085] As an example, S203 may include: determining whether the number of thread executions in the thread pool reaches a first threshold, and if so, determining a processing strategy for request messages in the thread pool based on the fuse status of Hystrix; if not, the Hystrix current limiting strategy may not be enabled.

[0086] Among them, determining the processing strategy for the request message in the thread pool based on the fuse state of Hystrix may include: if the fuse state of Hystrix is ​​open, refusing to execute the request message in the thread pool and returning a downgrade response message; if the fuse state of Hystrix is ​​half-open, the request message in the thread pool enters waiting and retries after a preset time. If the call succeeds during the retry, the fuse state of Hystrix is ​​set to the closed state; if the call fails during the retry, the fuse state of Hystrix is ​​set to the open state.

[0087] Among them, the Hystrix fuse monitors the failure rate and / or response time. If the monitored parameters include the failure rate, then when it is found that the failure rate reaches the second threshold, the Hystrix fuse state is triggered to switch to the open state. If the monitored parameters include the response time, then when it is found that the response time reaches the third threshold, the Hystrix fuse state is triggered to switch to the open state. If the monitored parameters include the failure rate and response time, then when it is found that the failure rate reaches the second threshold and / or the response time reaches the third threshold, the Hystrix fuse state is triggered to switch to the open state.

[0088] For the processing strategy of the request message in the thread pool in S203, taking the first request message among the M request messages as an example, it may include: determining the current processing logic of the thread pool corresponding to the first request message based on the user information downgrade implementation class and the service downgrade abstract class; if the current processing logic is the normal execution logic, processing the first request message based on the run() function of Hystrix (also referred to as the method, i.e., the run() method); if the current processing logic is the abnormal downgrade logic, processing the first request message based on the getFallback() function of Hystrix (also referred to as the method, i.e., the getFallback() method).

[0089] For example, if Figure 3 As shown, the HTTP request passes through the GetUsermmand user information downgrade implementation class (also abbreviated as GetUserCommand) and the HystrixCommand service downgrade abstract class in sequence to obtain the module identifier (if the module includes only one transaction, the module identifier can use the transaction code; if the module includes multiple transactions, the module identifier can refer to an identifier or attribute that can indicate the association relationship between these transactions); then, based on the module identifier, it is determined whether the current processing logic of the corresponding thread pool is normal. If normal, the normal processing logic corresponding to the run() function is executed; if abnormal, the abnormal downgrade logic corresponding to the getFallback() function is executed.

[0090] After S202~S203, Hystrix performs current limiting and fault tolerance within the service to achieve fine-grained flow control. The Hystrix fuse can prevent request messages from continuing to flow to the backend when a service fails, thereby reducing the backend load. It complements the fault tolerance mechanism of Nginx and improves the fault tolerance of the system.

[0091] It should be noted that, in an embodiment of the present application, based on the characteristics of combining the application layer and the network layer for flow control, the configuration process of Hystrix may include: S11, importing Hystrix dependencies and creating Hystrix commands; S12, building a run() function and a getFallback() function, wherein the getFallback() function is used to process the abnormal degradation logic, and the run() function is used to process the normal execution logic; S13, configuring the fuse parameters of Hystrix, which include at least one of the following parameters: a threshold value for the number of request messages, a condition for opening the fuse, or a duration for opening the fuse.

[0092] For S11 and S12, Hystrix commands can encapsulate operations that may fail. You can create custom Hystrix commands by inheriting the HystrixCommand or HystrixObservableCommand class and overriding their run() function. The specific code may include:

[0093]

[0094]

[0095] Here, the run() function uses HttpClient to send HTTP requests to simulate remote service calls. When the remote service call of the run() function fails, the getFallback() function will be called to prevent the failure from spreading to the entire system.

[0096] The getFallback() function is used to provide service degradation logic, which is the backup logic executed when the original command fails for some reason (such as returning a static, predefined response, or returning the most recent cached data or default data when user data needs to be returned). If there are backup services or resources, these backup services can be called in the getFallback() function. It should be noted that the getFallback() function can be designed to be as simple as possible to avoid introducing complex logic or other external dependencies that may cause failure. Specific code may include, for example:

[0097]

[0098] For S13, the configuration of the fuse parameters can be set in the command builder, or using global properties. The specific code may include, for example:

[0099]

[0100] When a service or operation fails, the fuse can prevent further calls to the service, thereby avoiding cascading failures and causing the entire system to crash. When the fuse is turned on, calls to the failed service will fail immediately instead of waiting for a timeout, which can reduce resource waste and improve system response time.

[0101] In this way, by combining Nginx and Hystrix, this method implements a two-layer flow control strategy at the network layer and the application layer. After receiving the request message, Nginx performs rate limiting to ensure that only a reasonable number of requests reach the application, preventing too many request messages from reaching the application, and forming the first line of defense. Inside the application, Hystrix can capture problems with external service calls and execute degradation logic. Hystrix is ​​used to handle timeouts, concurrency control, and degradation of dependent operations to prevent external dependency issues from affecting the performance and availability of the application. In this way, this flow control method has the capabilities of flow control, dynamic flow adjustment, fuse degradation, etc., which can effectively prevent system overload and improve the system's self-recovery ability for unstable dependencies and service anomalies. It is a more intelligent, comprehensive, and reliable flow control solution.

[0102] Accordingly, the embodiment of the present application further provides a flow control device 400, such as Figure 4 The device 400 may include:

[0103] A filtering unit 401 is used to filter N request messages based on the current limiting parameters configured in Nginx to obtain M request messages, where both N and M are natural numbers greater than 0, and N is less than or equal to M;

[0104] An isolation unit 402 is used to classify the M request messages into a corresponding thread pool, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute;

[0105] The processing unit 403 is used to determine a processing strategy for the request message in the thread pool based on the execution status of each thread in the thread pool and the fuse status of the Hystrix.

[0106] Optionally, the processing unit 403 is specifically configured to:

[0107] If the number of thread executions in the thread pool reaches a first threshold, a processing strategy for the request message in the thread pool is determined based on the fuse status of the Hystrix.

[0108] Optionally, the processing unit 403 includes:

[0109] The first processing subunit is used to refuse to execute the request message in the thread pool and return a downgrade response message if the fuse state of the Hystrix is ​​open;

[0110] The second processing subunit is used to, if the fuse state of the Hystrix is ​​half-open, the request message in the thread pool enters waiting and retries after a preset time.

[0111] Optionally, the device 400 further includes:

[0112] The state switching unit is used to trigger the fuse state of the Hystrix to be open if the failure rate reaches a second threshold and / or the response time reaches a third threshold.

[0113] Optionally, the M request messages include a first request message, and the processing of the first request message by the processing unit 403 is specifically used to:

[0114] Determine the current processing logic of the thread pool corresponding to the first request message based on the user information downgrade implementation class and the service downgrade abstract class;

[0115] If the current processing logic is a normal execution logic, the first request message is processed based on the run() function of the Hystrix;

[0116] If the current processing logic is an abnormal degradation logic, the first request message is processed based on the getFallback() function of the Hystrix.

[0117] Optionally, the device 400 further includes a configuration unit;

[0118] The configuration unit is used to configure the Hystrix;

[0119] The configuration unit is specifically used for:

[0120] Import Hystrix dependencies and create Hystrix commands;

[0121] Construct a run() function and a getFallback() function, wherein the getFallback() function is used to process abnormal degradation logic, and the run() function is used to process normal execution logic;

[0122] Configure the fuse parameters of Hystrix, where the fuse parameters include at least one of the following parameters: a threshold value for the number of request messages, a condition for opening the fuse, or a duration for opening the fuse.

[0123] It should be noted that the specific implementation method of the device 400 and the technical effects achieved can be found in Figure 2 The relevant description in the method shown.

[0124] In addition, an embodiment of the present application also provides an electronic device, which includes a processor and a memory: the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes any implementation of the method provided in the embodiment of the present application.

[0125] See also Figure 5 , which shows a schematic diagram of the structure of an electronic device 500 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include but is 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), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0126] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0127] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0128] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 509, or installed from the storage device 508, or installed from the ROM502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0129] The electronic device provided by the embodiment of the present disclosure and the method provided by the above embodiment belong to the same inventive concept, and the technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0130] The embodiment of the present application also provides a computer-readable medium, in which instructions or computer programs are stored. When the instructions or computer programs are executed on a device, the device executes any implementation of the method provided in the embodiment of the present application.

[0131] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0132] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (Hyper Text Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0133] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0134] The computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device can execute the method.

[0135] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0136] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0137] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit / module does not, in some cases, constitute a limitation on the unit itself.

[0138] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0139] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0140] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0141] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0142] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0143] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0144] It should be noted that in the embodiments of the present application, user sensitive information is not involved, and user-related information is obtained, used and determined after user authorization. In one example, before obtaining user-related information, the corresponding interface displays prompt information related to obtaining data use authorization. The prompt information is based on relevant laws and regulations in an appropriate manner to inform the user of the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure, so that the user can determine whether to agree to the authorization based on the prompt information. It can be understood that the above notification and the process of obtaining user authorization are only illustrative and do not constitute a limitation on the implementation method of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation method of the present disclosure.

[0145] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A flow control method, characterized in that: include: Based on the current limiting parameters configured in Nginx, N request messages are filtered to obtain M request messages, where both N and M are natural numbers greater than 0, and N is less than or equal to M; The M request messages are classified into corresponding thread pools, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute; Based on the execution status of each thread in the thread pool and the fuse status of the Hystrix, a processing strategy for the request message in the thread pool is determined.

2. The method according to claim 1, characterized in that Determining a processing strategy for request messages in the thread pool based on the execution status of each thread in the thread pool and the fuse status of the Hystrix includes: If the number of thread executions in the thread pool reaches a first threshold, a processing strategy for the request message in the thread pool is determined based on the fuse status of the Hystrix.

3. The method according to claim 2, characterized in that The determining of a processing strategy for the request message in the thread pool based on the fuse state of the Hystrix includes: If the fuse state of the Hystrix is ​​on, the request message in the thread pool is rejected and a downgrade response message is returned; If the fuse state of the Hystrix is ​​half-open, the request message in the thread pool enters waiting and retries after a preset time.

4. The method according to claim 2, characterized in that: The method further comprises: If the failure rate reaches the second threshold and / or the response time reaches the third threshold, the fuse state of the Hystrix is ​​triggered to be open.

5. The method according to any one of claims 1 to 4, characterized in that: The M request messages include a first request message, and a process of processing the first request message includes: Determine the current processing logic of the thread pool corresponding to the first request message based on the user information downgrade implementation class and the service downgrade abstract class; If the current processing logic is a normal execution logic, the first request message is processed based on the run() function of the Hystrix; If the current processing logic is an abnormal degradation logic, the first request message is processed based on the getFallback() function of the Hystrix.

6. The method according to claim 5, characterized in that The configuration process of Hystrix includes: Import Hystrix dependencies and create Hystrix commands; Construct a run() function and a getFallback() function, wherein the getFallback() function is used to process abnormal degradation logic, and the run() function is used to process normal execution logic; Configure the fuse parameters of Hystrix, where the fuse parameters include at least one of the following parameters: a threshold value for the number of request messages, a condition for opening the fuse, or a duration for opening the fuse.

7. A flow control device, characterized in that: include: A filtering unit, configured to filter N request messages based on the current limiting parameters configured in Nginx to obtain M request messages, where both N and M are natural numbers greater than 0, and N is less than or equal to M; An isolation unit, used to classify the M request messages into a corresponding thread pool, where the thread pool is an isolation unit of application-level granularity set by Hystrix, and each thread pool allows one thread to execute; The processing unit is used to determine a processing strategy for the request message in the thread pool based on the execution status of each thread in the thread pool and the fuse status of the Hystrix.

8. The device according to claim 7, characterized in that The processing unit is specifically used for: If the number of thread executions in the thread pool reaches a first threshold, a processing strategy for the request message in the thread pool is determined based on the fuse status of the Hystrix.

9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory; The memory is used to store instructions or programs; The processor is used to execute the instructions or programs in the memory so that the electronic device executes the method according to any one of claims 1 to 6.

10. A readable medium, characterized in that: The readable medium stores instructions or programs, and when the instructions or programs are executed on a processor, the processor is enabled to execute the method according to any one of claims 1 to 6.