Microservice request processing method, device, computer equipment and storage medium
By responding to microservice requests in the server, judging and processing whether the indicator value exceeds the threshold, and implementing a circuit breaker and downgrade strategy, the problem of server crash caused by microservice requests is solved, ensuring stable operation of the server and improving user experience.
Patent Information
- Application Number
- CN202111436277.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2041-11-29
AI Technical Summary
When the prior art calls microservices remotely, due to the complexity and uncertainty of the network environment, the resources requested by users are easily blocked, resulting in unavailability of the microservices, and even eventually the server crashes across the board.
By responding to microservice requests, determine whether the target microservice needs to call the target interface, obtain the server's log data, extract indicator data, and determine whether the indicator value exceeds the preset threshold. When the indicator value exceeds the threshold, the target circuit breaker and downgrade strategy is queried, the corresponding circuit breaker and downgrade triggering instruction is generated, and the target microservice is circuit breaker and downgraded; when the indicator value does not exceed the threshold, the target interface is called to run the target microservice.
When the indicator value is too large, the purposeful active circuit breaker and downgrade are implemented to ensure that the interfaces of other microservices are available, avoid a full-scale server crash, ensure that the server can provide services normally, and improve user experience. At the same time, the target circuit breaker and downgrade strategies corresponding to each indicator value are different, achieving precise circuit breaker and downgrade of the target microservices, and the function is more powerful.
Smart Images

Figure CN114064326B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of fuse protection technology. Specifically, the present application relates to a method, device, computer equipment and storage medium for processing microservice requests. Background Art
[0002] With the rapid development of mobile Internet, people are shifting from functional requirements for physical products to microservice requirements for virtual products. When the current online operating system calls microservices remotely, due to the complexity and uncertainty of the network environment, it is easy to cause the resources requested by users to be blocked, resulting in the unavailability of microservices and even the collapse of the entire server. Summary of the invention
[0003] The main purpose of this application is to provide a method, device, computer equipment and storage medium for processing microservice requests to provide an overload protection mechanism, ensure that the server provides services normally, and improve user experience.
[0004] In order to achieve the above-mentioned object of the invention, the present application provides a method for processing a microservice request, which comprises the following steps:
[0005] The server responds to the microservice request and determines a target microservice that needs to be run by the microservice request;
[0006] Determine whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0007] When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained; wherein the log data includes indicator data for evaluating the running status of the server when running all the current microservices;
[0008] Extracting the indicator data from the log data, determining an indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold;
[0009] When it is determined that the indicator value exceeds the preset threshold, query the target fuse downgrade strategy corresponding to the indicator value;
[0010] Generate a corresponding target breaking and downgrading trigger instruction according to the target breaking and downgrading strategy, and break and downgrade the target microservice according to the target breaking and downgrading trigger instruction;
[0011] When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice.
[0012] Preferably, the indicator data includes a plurality of sub-indicator data, and determining the indicator value of the server according to the indicator data and judging whether the indicator value exceeds a preset threshold value includes:
[0013] Obtaining the time node where each of the sub-indicator data is located, dividing the sub-indicator data of the same time node into the same data set, and obtaining multiple sub-indicator data sets;
[0014] Calculate the indicator value of each sub-indicator data set respectively;
[0015] Calculating the standard deviation according to the indicator value of each sub-indicator data set to obtain a standard deviation value; wherein the standard deviation value is used to evaluate the fluctuation degree of the server;
[0016] Determining whether the standard deviation value is lower than a preset value;
[0017] If not, it is determined that the indicator value exceeds a preset threshold.
[0018] Preferably, the indicator value includes the CPU occupancy rate of the server, and determining the indicator value of the server according to the indicator data includes:
[0019] Query the process identification number corresponding to each current microservice according to the indicator data;
[0020] Obtain process information of each of the microservices according to the process identification number;
[0021] The process information of each of the microservices is parsed to obtain the CPU occupancy of the server.
[0022] Preferably, obtaining the process information of each microservice according to the process identification number includes:
[0023] In a preset application container engine environment, traverse the identifier of each microservice in the server;
[0024] If the identifier of each of the microservices is recorded in a preset microservice list, the process information of each of the microservices is obtained according to the process identification number.
[0025] Preferably, calling the target interface to run the target microservice includes:
[0026] When it is detected that the number of the target microservices is at least two, the code corresponding to each target microservice is converted into an intermediate code package to obtain a plurality of target intermediate code packages;
[0027] Combine all the target intermediate code packages according to a preset application building tool to obtain a combined target microservice;
[0028] The target interface is called to run the combined target microservice.
[0029] Preferably, performing circuit breaking and downgrading on the target microservice according to the target circuit breaking and downgrading trigger instruction includes:
[0030] Determine the probe of the target microservice according to the target fuse degradation trigger instruction;
[0031] The probe is used to insert a preset fuse component into the current processing process of the target microservice; wherein the fuse component is used to perform fuse downgrading on the current processing process of the target microservice.
[0032] Preferably, calling the target interface to run the target microservice includes:
[0033] Obtain the number of calls to the target interface within a preset time period;
[0034] Comparing the number of calls with a corresponding threshold number of calls within the preset time period;
[0035] When the number of calls to the target interface is less than the call number threshold, the target interface is called to run the target microservice.
[0036] The present application also provides a microservice request processing device, which includes:
[0037] A determination module, used for the server to respond to a microservice request and determine a target microservice that needs to be run by the microservice request;
[0038] A first judgment module is used to judge whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0039] An acquisition module, used to acquire log data of the server when it is determined that the target microservice needs to call the target interface; wherein the log data includes indicator data for evaluating the running status of the server when running all current microservices;
[0040] A second judgment module is used to extract the indicator data from the log data, determine the indicator value of the server according to the indicator data, and judge whether the indicator value exceeds a preset threshold;
[0041] A query module, used for querying a target fuse degradation strategy corresponding to the indicator value when it is determined that the indicator value exceeds a preset threshold;
[0042] A fuse downgrade module, used to generate a corresponding target fuse downgrade trigger instruction according to the target fuse downgrade strategy, and perform fuse downgrade on the target microservice according to the target fuse downgrade trigger instruction;
[0043] The calling module is used to call the target interface to run the target microservice when it is determined that the indicator value does not exceed the preset threshold.
[0044] The present application also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the above methods when executing the computer program.
[0045] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0046] The present application provides a method, device, computer equipment and storage medium for processing microservice requests. By responding to the microservice request, the target microservice that needs to be run by the microservice request is determined, and whether the target microservice needs to call the target interface. When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained, and the indicator data is extracted from the log data. The indicator value of the server is determined according to the indicator data, and it is determined whether the indicator value exceeds the preset threshold. When it is determined that the indicator value exceeds the preset threshold, the target fuse and degradation policy corresponding to the indicator value is queried, and a corresponding target fuse and degradation trigger instruction is generated according to the target fuse and degradation policy. The target microservice is fuse-broken and downgraded according to the target fuse and degradation trigger instruction. When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice, so that when the indicator value is too large, the fuse is actively broken and downgraded in a purposeful manner to ensure that the interfaces of other microservices are available, avoid the collapse of the entire server, ensure that the server provides services normally, and improve the user experience. At the same time, each indicator value corresponds to a different target circuit breaker and degradation strategy, which can achieve precise circuit breaker and degradation of the target microservice, and has more powerful functions. When the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice to reasonably allocate the interface and ensure stable operation of the server. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A flowchart of a method for processing a microservice request according to an embodiment of the present application;
[0048] Figure 2 This is a schematic block diagram of the structure of a device for processing microservice requests according to an embodiment of the present application;
[0049] Figure 3 A schematic block diagram of the structure of a computer device according to an embodiment of the present application.
[0050] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0052] The present application proposes a method for processing microservice requests, with a server as the execution subject. The server can be an independent server or a cloud server that provides basic cloud computing target microservices such as cloud target microservices, cloud databases, cloud computing, cloud functions, cloud storage, network target microservices, cloud communications, middleware target microservices, domain name target microservices, security target microservices, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0053] This microservice request processing method is used to solve the technical problem that when calling microservices, the resources requested by users are easily blocked due to the complexity and uncertainty of the network environment, making the microservices unavailable and even eventually causing the entire server to crash. Figure 1 In one embodiment, the method for processing the microservice request includes the following steps:
[0054] S11. The server responds to the microservice request and determines the target microservice that needs to be run by the microservice request;
[0055] S12, determining whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0056] S13. When it is determined that the target microservice needs to call the target interface, obtain log data of the server; wherein the log data includes indicator data for evaluating the running status of the server when running all current microservices;
[0057] S14, extracting the indicator data from the log data, determining an indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold;
[0058] S15. When it is determined that the indicator value exceeds a preset threshold, query the target fuse downgrade strategy corresponding to the indicator value;
[0059] S16. Generate a corresponding target breaking and downgrading trigger instruction according to the target breaking and downgrading strategy, and break and downgrade the target microservice according to the target breaking and downgrading trigger instruction;
[0060] S17: When it is determined that the indicator value does not exceed the preset threshold, call the target interface to run the target microservice.
[0061] As described in step S11 above, when the user's terminal initiates a microservice request to the server, the microservice request contains the identifier of the target microservice to be run, and based on the identifier, the microservice corresponding to the identifier is queried from a pre-built list to determine the target microservice to be run by the microservice request. The list records the microservice corresponding to each identifier.
[0062] Target microservice refers to the development of a single small but business-functional target microservice. Each target microservice has its own processing and lightweight communication mechanism and can be deployed on a single or multiple servers. When an enterprise targets microservices, there will be complex dependencies between target microservices. For example, a front-end request generally depends on multiple back-end target microservices. In actual production environments, target microservices are often not 100% reliable. Target microservices may fail or generate delays. If an application cannot tolerate and isolate the failures it depends on, then the application itself is at risk of being dragged down. In a high-traffic website, once a single backend is delayed, all application resources (threads, queues, etc.) may be exhausted within a few seconds, causing the so-called avalanche effect. In severe cases, the entire website may be paralyzed. Therefore, it is necessary to elastically scale resources according to the operating status of the server.
[0063] As described in step S12 above, it is possible to find out whether the target microservice needs to call the target interface of the specific target microservice by annotation. The target interface is an interface pre-configured for the specific target microservice, and the microservice request can be a request corresponding to a customized target microservice; in addition, the target interface can also be monitored and added by means of whitelist files, databases, etc.
[0064] As described in the above steps S13-S14, if the target microservice does not need to call the target interface, the target microservice is directly run; otherwise, according to the relevant algorithm, the index value used to evaluate the current server operation status is calculated, such as CPU usage, memory usage, etc. In this embodiment, the index data of the current server operation status can be extracted from the log data, so as to calculate the accurate index value of the current server according to the index data, and determine whether the index value exceeds the preset threshold value, which can be customized, such as determining whether the CPU usage rate exceeds 90%.
[0065] In one embodiment, the extracted indicator data includes but is not limited to one or more of the following combinations: the CPU capacity used in the server, the memory capacity used in the server, the request success rate of the target microservice in the server, and the average request response time of the target microservice in the server.
[0066] As described in the above steps S15-S16, when it is determined that the indicator value reaches the upper threshold, the target microservice is melted and downgraded; wherein, the role of the target microservice melt is similar to the fuse we use at home. When a target microservice is unavailable or the response times out, in order to prevent the entire server from avalanching, the call to the target microservice is temporarily stopped. The downgrade of the target microservice is based on the load of the entire server and is considered. For some situations where the load is relatively high, in order to prevent some functions (business scenarios) from being overloaded or responding slowly, the request for some non-core interfaces and data is temporarily abandoned inside, and a fall back error handling information prepared in advance is directly returned. In this way, although a lossy target microservice is provided, the stability and availability of the entire system are guaranteed.
[0067] Among them, there can be multiple fuse degradation strategies, and the specific number can be determined based on the number of fuse degradation conditions met. In this embodiment, the preset threshold configuration information corresponding to each fuse degradation strategy can be compared with the corresponding index value, so as to determine the target fuse degradation strategy corresponding to the index value. Then, a corresponding target fuse degradation trigger instruction is generated according to each target fuse degradation strategy, and the target microservice is fuse-degraded according to the target fuse degradation trigger instruction. For example, if the target fuse degradation strategy includes a thread pool isolation degradation strategy for the target business server, a target thread pool isolation degradation trigger instruction for the target business server is generated. If the target fuse degradation method includes a fuse strategy, a timeout change strategy, or an access current limiting degradation strategy, fuse trigger instructions, timeout change trigger instructions, or access current limiting degradation trigger instructions for all business servers are generated respectively, and fuse degradation is performed according to all generated trigger instructions.
[0068] As described in step S17 above, when it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice to reasonably allocate interfaces and ensure stable operation of the server. The target interface may be the interface with the least number of calls within a preset time period, and the interface with the least number of calls is selected to run the target microservice to quickly respond to the target microservice request.
[0069] A method for processing microservice requests provided by the present application determines the target microservice that needs to be run by the microservice request by responding to the microservice request, and determines whether the target microservice needs to call the target interface. When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained, the indicator data is extracted from the log data, the indicator value of the server is determined according to the indicator data, and it is determined whether the indicator value exceeds a preset threshold. When it is determined that the indicator value exceeds the preset threshold, the target fuse and degradation policy corresponding to the indicator value is queried, and a corresponding target fuse and degradation trigger instruction is generated according to the target fuse and degradation policy. The target microservice is fuse-broken and downgraded according to the target fuse and degradation trigger instruction. When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice, so that when the indicator value is too large, the fuse is actively broken and downgraded in a purposeful manner to ensure that the interfaces of other microservices are available, avoid a full-line server crash, ensure that the server provides services normally, and improve user experience. At the same time, each indicator value corresponds to a different target circuit breaker and degradation strategy, which can achieve precise circuit breaker and degradation of the target microservice, and has more powerful functions. When the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice to reasonably allocate the interface and ensure stable operation of the server.
[0070] In one embodiment, the indicator data includes a plurality of sub-indicator data, and determining the indicator value of the server according to the indicator data and judging whether the indicator value exceeds a preset threshold may specifically include:
[0071] Obtaining the time node where each of the sub-indicator data is located, dividing the sub-indicator data of the same time node into the same data set, and obtaining multiple sub-indicator data sets;
[0072] Calculate the indicator value of each sub-indicator data set respectively;
[0073] Calculating the standard deviation according to the indicator value of each sub-indicator data set to obtain a standard deviation value; wherein the standard deviation value is used to evaluate the fluctuation degree of the server;
[0074] Determining whether the standard deviation value is lower than a preset value;
[0075] If not, it is determined that the indicator value exceeds a preset threshold.
[0076] In this embodiment, the index data of the server fluctuates greatly, is prone to jitter, and has a high probability of accidentally damaging the target interface. It is necessary to divide the sub-index data of the same time node into the same data set to obtain multiple sub-index data sets, calculate the index value of each sub-index data set, that is, calculate the standard deviation of the index value within a unit time, and obtain the standard deviation value, which is used to describe the degree of fluctuation of the server. For tasks of the same type, the strategies of directional pressure are different. For tasks that are computationally intensive or IO-intensive, the data indicators of a single machine are compared; IO-intensive and computationally intensive tasks need to rely on distributed index data. If the threshold is exceeded, the target interface is downgraded to ensure that other interfaces are available and provide continuous and stable target microservices.
[0077] The step of calculating the standard deviation according to the indicator value of each sub-indicator data set to obtain the standard deviation value includes the following formula:
[0078]
[0079] Among them, M is the average index value of a single index value within a certain period of time, x n Represents the indicator value of a sub-indicator data set; wherein, M can be calculated by the following formula:
[0080]
[0081] In addition, different weights can be set for each indicator value according to the indicator type corresponding to different indicator values, and the value calculated according to the indicator value and the corresponding weight replaces the indicator value X=w1x1+w2x n (w1 and w2 represent weights), and the volatility of the server is calculated based on the calculated indicator value: |TX|<=D and the volatility is lower than T (T represents the upper threshold limit, X represents the indicator value, D represents the constant, and represents the error value).
[0082] In one embodiment, the indicator value includes the CPU occupancy rate of the server, and determining the indicator value of the server according to the indicator data may specifically include:
[0083] Query the process identification number corresponding to each current microservice according to the indicator data;
[0084] Acquire process information of each of the microservices according to the process identification number;
[0085] The process information of each of the microservices is parsed to obtain the CPU occupancy of the server.
[0086] Normally, it is necessary to collect CPU occupancy and memory usage. The server collection mechanism in the docker environment is different. For the server, a target microservice may occupy a single target microservice, and collecting the indicator data of the server can meet the needs; for the docker environment, multiple target microservices may be deployed, and it is necessary to collect the CPU information and memory information corresponding to the current process. During the collection, the process number PID corresponding to the application can be obtained, and the process information of each microservice can be obtained according to the process identification number. After parsing the process information, the CPU occupancy rate, memory usage rate and other indicator data of the current process can be obtained. Among them, PID (Process Identification) refers to the process identification number in the operating system, that is, the process identifier. Every time a program is opened in the operating system, a process ID, i.e., PID, is created.
[0087] In one embodiment, a preset value may be set as needed, and further processing may be performed by comparing the preset value with the CPU occupancy rate. That is, if the CPU occupancy rate is greater than the preset value, it means that the current server cannot run the target microservice, and further processing is required, such as allocating the target microservice to a backup server. If the CPU occupancy rate is less than the preset value, it means that the server can run the target microservice without affecting the overall efficiency.
[0088] In one embodiment, obtaining the process information of each microservice according to the process identification number may specifically include:
[0089] In a preset application container engine environment, traverse the identifier of each microservice in the server;
[0090] If the identifier of each of the microservices is recorded in a preset microservice list, the process information of each of the microservices is obtained according to the process identification number.
[0091] In this embodiment, the application container engine can specifically be a Docker application container engine. Docker is an open source application container engine that allows developers to package their applications and dependent packages into a portable container and then publish them to any popular Linux machine. It can also achieve virtualization. The container completely uses a sandbox mechanism and there will be no interface between them. In the docker environment, the identifier of each independent microservice in the server can be traversed. If the identifier of each microservice is recorded in the preset microservice list, the process information of each microservice is obtained according to the process identification number. Among them, each independent microservice is pre-assigned with a unique identifier.
[0092] In one embodiment, calling the target interface to run the target microservice may specifically include:
[0093] When it is detected that the number of the target microservices is at least two, the code corresponding to each target microservice is converted into an intermediate code package to obtain a plurality of target intermediate code packages;
[0094] Combine all the target intermediate code packages according to a preset application building tool to obtain a combined target microservice;
[0095] The target interface is called to run the combined target microservice.
[0096] In this embodiment, if the number of the target microservices is two or more, in order to facilitate management, all the target microservices can be converted into corresponding intermediate code packages to achieve the re-merging of multiple target microservices.
[0097] Specifically, all intermediate code packages can be combined according to a preset application building tool to obtain a combined target microservice with a corresponding application interface, which is the target interface that needs to be called later. Among them, the preset application building tool can be Maven's POM engineering tool. After completing the combination of multiple target microservices and obtaining the combined target microservice, the obtained combined target microservice can be directly deployed to the server, and the target interface is called to run the combined target microservice to obtain the execution result, so that in the case of multiple target microservices, the target microservice is run in a combined manner to ensure the stable operation of the current server.
[0098] In one embodiment, performing circuit breaking and downgrading on the target microservice according to the target circuit breaking and downgrading trigger instruction may specifically include:
[0099] Determine the probe of the target microservice according to the target fuse degradation trigger instruction;
[0100] The probe is used to insert a preset fuse component into the current processing process of the target microservice; wherein the fuse component is used to perform fuse downgrading on the current processing process of the target microservice.
[0101] Among them, the probe can be inserted into the process of the microservice by the server using Java virtual machine technology. When the probe is inserted into the current processing process of the target microservice, it will carry a fuse component. The fuse component includes a component library that implements the fuse degradation function, so that after the probe is loaded by the current processing process of the target microservice, the current processing process of the target microservice is fused and downgraded through the fuse component.
[0102] This embodiment inserts the fuse component into the current processing process of the target microservice through the probe to perform fuse downgrading on the microservice request. There is no need to change the original code or perform repeated access, which reduces development and maintenance costs, has high loss-stopping efficiency, and can implement accurate downgrade operations based on the obtained fuse downgrading strategy, thereby ensuring high stability of the server.
[0103] In one embodiment, calling the target interface to run the target microservice may specifically include:
[0104] Obtain the number of calls to the target interface within a preset time period;
[0105] Comparing the number of calls with a corresponding threshold number of calls within the preset time period;
[0106] When the number of calls to the target interface is less than the call number threshold, the target interface is called to run the target microservice.
[0107] In this embodiment, the preset time period is a relatively short period of time. For example, the number of calls to the target interface within 3 seconds can be obtained, and the number of calls is compared with the corresponding call number threshold within the preset time period. When the number of calls to the target interface is less than the call number threshold, the target interface is called to run the target microservice, otherwise the call to the target interface is suspended to avoid failures when calling the target interface.
[0108] Reference Figure 2 In an embodiment of the present application, a device for processing a microservice request is also provided, including:
[0109] A determination module 11 is used for the server to respond to a microservice request and determine a target microservice that needs to be run by the microservice request;
[0110] A first judgment module 12 is used to judge whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0111] The acquisition module 13 is used to acquire the log data of the server when it is determined that the target microservice needs to call the target interface; wherein the log data includes indicator data for evaluating the running status of the server when running all the current microservices;
[0112] A second judgment module 14 is used to extract the indicator data from the log data, determine the indicator value of the server according to the indicator data, and judge whether the indicator value exceeds a preset threshold;
[0113] A query module 15, configured to query a target fuse degradation strategy corresponding to the indicator value when it is determined that the indicator value exceeds a preset threshold;
[0114] A fuse downgrade module 16 is used to generate a corresponding target fuse downgrade trigger instruction according to the target fuse downgrade strategy, and perform fuse downgrade on the target microservice according to the target fuse downgrade trigger instruction;
[0115] The calling module 17 is used to call the target interface to run the target microservice when it is determined that the indicator value does not exceed the preset threshold.
[0116] In this embodiment, when the terminal where the user is located initiates a microservice request to the server, the microservice request contains the identifier of the target microservice to be run, and based on the identifier, the microservice corresponding to the identifier is queried from a pre-built list to determine the target microservice that the microservice request needs to run. The list records the microservice corresponding to each identifier.
[0117] Target microservice refers to the development of a single small but business-functional target microservice. Each target microservice has its own processing and lightweight communication mechanism and can be deployed on a single or multiple servers. When an enterprise targets microservices, there will be complex dependencies between target microservices. For example, a front-end request generally depends on multiple back-end target microservices. In actual production environments, target microservices are often not 100% reliable. Target microservices may fail or generate delays. If an application cannot tolerate and isolate the failures it depends on, then the application itself is at risk of being dragged down. In a high-traffic website, once a single backend is delayed, all application resources (threads, queues, etc.) may be exhausted within a few seconds, causing the so-called avalanche effect. In severe cases, the entire website may be paralyzed. Therefore, it is necessary to elastically scale resources according to the operating status of the server.
[0118] This embodiment can find out whether the target microservice needs to call the target interface of the specific target microservice by annotation. The target interface is an interface pre-configured for the specific target microservice, and the microservice request can be a request corresponding to the customized target microservice; in addition, the target interface can also be monitored and added by whitelist files, databases, etc.
[0119] If the target microservice does not need to call the target interface, the target microservice is directly run; otherwise, according to the relevant algorithm, the index value used to evaluate the current server operation status is calculated, such as CPU usage, memory usage, etc. In this embodiment, the index data of the current server operation status can be extracted from the log data to calculate the accurate index value of the current server according to the index data, and determine whether the index value exceeds the preset threshold value, which can be customized, such as determining whether the CPU usage exceeds 90%.
[0120] In one embodiment, the extracted indicator data includes but is not limited to one or more of the following combinations: the CPU capacity used in the server, the memory capacity used in the server, the request success rate of the target microservice in the server, and the average request response time of the target microservice in the server.
[0121] When it is determined that the indicator value reaches the upper threshold, the target microservice is downgraded by fuse. The function of the target microservice fuse is similar to the fuse in our homes. When a target microservice is unavailable or the response times out, in order to prevent the entire server from avalanche, the call to the target microservice is temporarily stopped. The downgrade of the target microservice is based on the load of the entire server. For some situations where the load is relatively high, in order to prevent some functions (business scenarios) from being overloaded or responding slowly, the request for some non-core interfaces and data is temporarily abandoned internally, and a fallback error handling information prepared in advance is directly returned. In this way, although a lossy target microservice is provided, the stability and availability of the entire system are guaranteed.
[0122] Among them, there can be multiple fuse degradation strategies, and the specific number can be determined based on the number of fuse degradation conditions met. In this embodiment, the preset threshold configuration information corresponding to each fuse degradation strategy can be compared with the corresponding index value, so as to determine the target fuse degradation strategy corresponding to the index value. Then, a corresponding target fuse degradation trigger instruction is generated according to each target fuse degradation strategy, and the target microservice is fuse-degraded according to the target fuse degradation trigger instruction. For example, if the target fuse degradation strategy includes a thread pool isolation degradation strategy for the target business server, a target thread pool isolation degradation trigger instruction for the target business server is generated. If the target fuse degradation method includes a fuse strategy, a timeout change strategy, or an access current limiting degradation strategy, fuse trigger instructions, timeout change trigger instructions, or access current limiting degradation trigger instructions for all business servers are generated respectively, and fuse degradation is performed according to all generated trigger instructions.
[0123] When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice to reasonably allocate interfaces and ensure stable operation of the server. The target interface can be the interface with the least number of calls within a preset time period, and the interface with the least number of calls is selected to run the target microservice to quickly respond to the target microservice request.
[0124] As described above, it can be understood that the various components of the microservice request processing device proposed in the present application can implement the functions of any one of the microservice request processing methods described above, and the specific structure will not be repeated.
[0125] Reference Figure 3 In the embodiment of the present application, a computer device is also provided, whose internal structure can be as follows Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes a storage medium and an internal memory. The storage medium stores an operating system, a computer program and a database. The memory provides an environment for the operation of the operating system and the computer program in the storage medium. The database of the computer device is used to store indicator data, log data and other data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for processing a microservice request is implemented.
[0126] The processor executes the microservice request processing method, including:
[0127] The server responds to the microservice request and determines a target microservice that needs to be run by the microservice request;
[0128] Determine whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0129] When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained; wherein the log data includes indicator data for evaluating the running status of the server when running all the current microservices;
[0130] Extracting the indicator data from the log data, determining an indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold;
[0131] When it is determined that the indicator value exceeds the preset threshold, query the target fuse downgrade strategy corresponding to the indicator value;
[0132] Generate a corresponding target breaking and downgrading trigger instruction according to the target breaking and downgrading strategy, and break and downgrade the target microservice according to the target breaking and downgrading trigger instruction;
[0133] When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice.
[0134] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, a method for processing a microservice request is implemented, including the steps of:
[0135] The server responds to the microservice request and determines a target microservice that needs to be run by the microservice request;
[0136] Determine whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice;
[0137] When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained; wherein the log data includes indicator data for evaluating the running status of the server when running all the current microservices;
[0138] Extracting the indicator data from the log data, determining an indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold;
[0139] When it is determined that the indicator value exceeds the preset threshold, query the target fuse downgrade strategy corresponding to the indicator value;
[0140] Generate a corresponding target breaking and downgrading trigger instruction according to the target breaking and downgrading strategy, and break and downgrade the target microservice according to the target breaking and downgrading trigger instruction;
[0141] When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice.
[0142] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in the present application and used in the embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double-speed data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0143] In summary, the greatest beneficial effects of this application are:
[0144] The present application provides a method, device, computer equipment and storage medium for processing microservice requests. By responding to the microservice request, the target microservice that needs to be run by the microservice request is determined, and whether the target microservice needs to call the target interface. When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained, and the indicator data is extracted from the log data. The indicator value of the server is determined according to the indicator data, and it is determined whether the indicator value exceeds the preset threshold. When it is determined that the indicator value exceeds the preset threshold, the target fuse and degradation policy corresponding to the indicator value is queried, and a corresponding target fuse and degradation trigger instruction is generated according to the target fuse and degradation policy. The target microservice is fuse-broken and downgraded according to the target fuse and degradation trigger instruction. When it is determined that the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice, so that when the indicator value is too large, the fuse is actively broken and downgraded in a purposeful manner to ensure that the interfaces of other microservices are available, avoid the collapse of the entire server, ensure that the server provides services normally, and improve the user experience. At the same time, each indicator value corresponds to a different target circuit breaker and degradation strategy, which can achieve precise circuit breaker and degradation of the target microservice, and has more powerful functions. When the indicator value does not exceed the preset threshold, the target interface is called to run the target microservice to reasonably allocate the interface and ensure stable operation of the server.
[0145] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method 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, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.
[0146] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for processing a microservice request, characterized in that: include: The server responds to the microservice request and determines a target microservice that needs to be run by the microservice request; Determine whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice; When it is determined that the target microservice needs to call the target interface, the log data of the server is obtained; wherein the log data includes indicator data for evaluating the running status of the server when running all the current microservices; Extracting the indicator data from the log data, determining an indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold; When it is determined that the indicator value exceeds the preset threshold, query the target fuse downgrade strategy corresponding to the indicator value; Generate a corresponding target breaking and downgrading trigger instruction according to the target breaking and downgrading strategy, and break and downgrade the target microservice according to the target breaking and downgrading trigger instruction; When it is determined that the indicator value does not exceed the preset threshold, calling the target interface to run the target microservice; The indicator data includes a plurality of sub-indicator data, and determining the indicator value of the server according to the indicator data, and judging whether the indicator value exceeds a preset threshold value, includes: Obtaining the time node where each of the sub-indicator data is located, dividing the sub-indicator data of the same time node into the same data set, and obtaining multiple sub-indicator data sets; Calculate the indicator value of each sub-indicator data set respectively; Calculating the standard deviation according to the indicator value of each sub-indicator data set to obtain a standard deviation value; wherein the standard deviation value is used to evaluate the fluctuation degree of the server; Determining whether the standard deviation value is lower than a preset value; If not, it is determined that the indicator value exceeds a preset threshold.
2. The method according to claim 1, characterized in that The indicator value includes a CPU occupancy rate of the server, and determining the indicator value of the server according to the indicator data includes: Query the process identification number corresponding to each current microservice according to the indicator data; Acquire process information of each of the microservices according to the process identification number; The process information of each of the microservices is parsed to obtain the CPU occupancy of the server.
3. The method according to claim 2, characterized in that The obtaining process information of each of the microservices according to the process identification number includes: In a preset application container engine environment, traverse the identifier of each microservice in the server; If the identifier of each of the microservices is recorded in a preset microservice list, the process information of each of the microservices is obtained according to the process identification number.
4. The method according to claim 1, characterized in that The calling the target interface to run the target microservice includes: When it is detected that the number of the target microservices is at least two, the code corresponding to each target microservice is converted into an intermediate code package to obtain a plurality of target intermediate code packages; Combine all the target intermediate code packages according to a preset application building tool to obtain a combined target microservice; The target interface is called to run the combined target microservice.
5. The method according to claim 1, characterized in that The performing circuit breaking and downgrading on the target microservice according to the target circuit breaking and downgrading trigger instruction includes: Determine the probe of the target microservice according to the target fuse degradation trigger instruction; The probe is used to insert a preset fuse component into the current processing process of the target microservice; wherein the fuse component is used to perform fuse downgrading on the current processing process of the target microservice.
6. The method according to claim 1, characterized in that The calling the target interface to run the target microservice includes: Obtain the number of calls to the target interface within a preset time period; Comparing the number of calls with a corresponding threshold number of calls within the preset time period; When the number of calls to the target interface is less than the call number threshold, the target interface is called to run the target microservice.
7. A microservice request processing device, used to implement the method according to any one of claims 1 to 6, characterized in that: include: A determination module, used for the server to respond to a microservice request and determine a target microservice that needs to be run by the microservice request; A first judgment module is used to judge whether the target microservice needs to call a target interface; wherein the target interface is an interface for running the target microservice; An acquisition module, used to acquire log data of the server when it is determined that the target microservice needs to call the target interface; wherein the log data includes indicator data for evaluating the running status of the server when running all current microservices; A second judgment module is used to extract the indicator data from the log data, determine the indicator value of the server according to the indicator data, and judge whether the indicator value exceeds a preset threshold; A query module, used for querying a target fuse degradation strategy corresponding to the indicator value when it is determined that the indicator value exceeds a preset threshold; A fuse downgrade module, used to generate a corresponding target fuse downgrade trigger instruction according to the target fuse downgrade strategy, and perform fuse downgrade on the target microservice according to the target fuse downgrade trigger instruction; The calling module is used to call the target interface to run the target microservice when it is determined that the indicator value does not exceed the preset threshold.
8. A computer device, characterized in that: include: processor; Memory; The memory stores a computer program, and the processor implements the method for processing a microservice request according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the method for processing a microservice request according to any one of claims 1 to 6.
Citation Information
Patent Citations
Fusing degradation triggering method and system and storage medium
CN112448987A
Fusing degradation method and device for micro service, equipment and medium
CN112965848A