Service degradation method and terminal

文档序号:1834626 发布日期:2021-11-12 浏览:22次 中文

阅读说明:本技术 一种服务降级方法及终端 (Service degradation method and terminal ) 是由 刘德建 林伟 陈宏� 于 2021-06-29 设计创作,主要内容包括:本发明公开了一种服务降级方法及终端,在上游服务中接入降级组件,通过降级组件获取降级规则;当上游服务向下游服务的实例发送访问请求时,使用降级组件统计上游服务访问的失败次数,若失败次数达到预设次数则需要对下游服务的实例进行处理,具体的处理方法是使上游服务停止向下游服务的实例发送访问请求,或者降低上游服务向所述下游服务的实例发送访问请求的速度,因此,即使下游服务因请求过大而导致不稳定时,也能够提供部分服务;同时,当访问的下游服务出现大量问题时,减少对下游服务的请求量,能够为下游服务提供一定的保护能力,从而降低降级服务的压力。(The invention discloses a service degradation method and a terminal, wherein a degradation component is accessed in an upstream service, and a degradation rule is obtained through the degradation component; when an upstream service sends an access request to an instance of a downstream service, a degradation component is used for counting the failure times of the upstream service access, if the failure times reach a preset number, the instance of the downstream service needs to be processed, and the specific processing method is to enable the upstream service to stop sending the access request to the instance of the downstream service or reduce the speed of sending the access request to the instance of the downstream service by the upstream service, so that partial service can be provided even if the downstream service is unstable due to overlarge request; meanwhile, when a large number of problems occur in the accessed downstream service, the request amount of the downstream service is reduced, and certain protection capability can be provided for the downstream service, so that the pressure of degrading the service is reduced.)

1. A method of service degradation, comprising the steps of:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced.

2. The method of claim 1, wherein obtaining, by the downgrading component, downgrading rules comprises:

configuring a degradation rule of the downstream service, and acquiring the degradation rule through the degradation component;

counting, using the downgrade component, a number of times the upstream service access failed comprising:

and setting an asynchronous timing task in the downgrade component, and acquiring the latest times of the upstream service access failure through the timing task.

3. The method of claim 1, wherein stopping sending access requests to the instance of the downstream service or reducing the speed of sending access requests to the instance of the downstream service if the number of access failures reaches a preset number in the degradation rule comprises:

if the access failure times of a certain instance reach the preset times in the downgrade rule, identifying the instance as an abnormal instance;

calculating a degraded fraction of all instances in the downstream service;

and judging whether the degraded occupation ratio reaches a preset occupation ratio, if so, reducing the speed of sending the access request to the abnormal example, otherwise, stopping sending the access request to the abnormal example, and identifying the abnormal example as the degraded example.

4. The method of claim 3, wherein the step of, after the degraded percentage reaches a preset percentage, comprises:

and counting the duration of the degraded occupation ratio after reaching a preset occupation ratio, and if the duration is greater than the preset duration, identifying all the undegraded instances in the downstream service as degraded instances.

5. The method of claim 4, wherein identifying all non-degraded instances in the downstream service as degraded instances comprises:

and scanning the degraded examples of the downstream service at regular time through the degrading component, judging whether the degraded examples can be successfully accessed, and if so, identifying the degraded examples as normal examples.

6. A service degradation terminal comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor when executing the computer program implements the steps of:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced.

7. The service downgrading terminal of claim 6, wherein obtaining, by the downgrading component, downgrading rules comprises:

configuring a degradation rule of the downstream service, and acquiring the degradation rule through the degradation component;

counting, using the downgrade component, a number of times the upstream service access failed comprising:

and setting an asynchronous timing task in the downgrade component, and acquiring the latest times of the upstream service access failure through the timing task.

8. The terminal of claim 6, wherein if the number of access failures reaches a preset number in the degradation rule, stopping sending the access request to the instance of the downstream service or reducing the speed of sending the access request to the instance of the downstream service comprises:

if the access failure times of a certain instance reach the preset times in the downgrade rule, identifying the instance as an abnormal instance;

calculating a degraded fraction of all instances in the downstream service;

and judging whether the degraded occupation ratio reaches a preset occupation ratio, if so, reducing the speed of sending the access request to the abnormal example, otherwise, stopping sending the access request to the abnormal example, and identifying the abnormal example as the degraded example.

9. The terminal of claim 8, wherein after the degraded percentage reaches a preset percentage, the terminal comprises:

and counting the duration of the degraded occupation ratio after reaching a preset occupation ratio, and if the duration is greater than the preset duration, identifying all the undegraded instances in the downstream service as degraded instances.

10. The terminal of claim 9, wherein identifying all non-degraded instances in the downstream service as degraded instances comprises:

and scanning the degraded examples of the downstream service at regular time through the degrading component, judging whether the degraded examples can be successfully accessed, and if so, identifying the degraded examples as normal examples.

Technical Field

The present invention relates to the field of computer technologies, and in particular, to a service degradation method and a terminal.

Background

Today, the mobile internet is developed vigorously to develop various system applications, and many systems have various data interactions with other systems. With the dramatic increase of the number of users, the server needs to implement horizontal extension in a distributed deployment manner to support access of large data users in a highly concurrent manner. The micro-service architecture mode is a method for realizing distributed deployment by a common server side at present.

Since access is performed between micro services through protocols such as HTTP (Hypertext Transfer Protocol) or RPC (Remote Procedure Call), various Protocol access and micro services themselves may have some problems, such as network jitter, excessive micro service pressure, configuration error and other abnormal problems. The general service degradation is that the downstream service instance monitors the function of the service, and when the bottleneck of the service is reached, the lossy degradation of the service itself is performed. At this time, if the request amount of the client continues to increase, the pressure of degrading the service is further enhanced.

Disclosure of Invention

The technical problem to be solved by the invention is as follows: a service degradation method and a terminal are provided, which can reduce the pressure of degrading service.

In order to solve the technical problems, the invention adopts the technical scheme that:

a method of service degradation comprising the steps of:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced.

In order to solve the technical problem, the invention adopts another technical scheme as follows:

a service degradation terminal comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced.

The invention has the beneficial effects that: accessing a degradation component in the upstream service, and acquiring a degradation rule through the degradation component; when an upstream service sends an access request to an instance of a downstream service, a degradation component is used for counting the failure times of the upstream service access, if the failure times reach a preset number, the instance of the downstream service needs to be processed, and the specific processing method is to enable the upstream service to stop sending the access request to the instance of the downstream service or reduce the speed of sending the access request to the instance of the downstream service by the upstream service, so that partial service can be provided even if the downstream service is unstable due to overlarge request; meanwhile, when a large number of problems occur in the accessed downstream service, the request amount of the downstream service is reduced, and certain protection capability can be provided for the downstream service, so that the pressure of degrading the service is reduced.

Drawings

FIG. 1 is a flow chart of a method for service downgrading according to an embodiment of the present invention;

fig. 2 is a schematic diagram of a service degradation terminal according to an embodiment of the present invention.

Detailed Description

In order to explain technical contents, achieved objects, and effects of the present invention in detail, the following description is made with reference to the accompanying drawings in combination with the embodiments.

Referring to fig. 1, an embodiment of the present invention provides a service degradation method, including:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced.

From the above description, the beneficial effects of the present invention are: accessing a degradation component in the upstream service, and acquiring a degradation rule through the degradation component; when an upstream service sends an access request to an instance of a downstream service, a degradation component is used for counting the failure times of the upstream service access, if the failure times reach a preset number, the instance of the downstream service needs to be processed, and the specific processing method is to enable the upstream service to stop sending the access request to the instance of the downstream service or reduce the speed of sending the access request to the instance of the downstream service by the upstream service, so that partial service can be provided even if the downstream service is unstable due to overlarge request; meanwhile, when a large number of problems occur in the accessed downstream service, the request amount of the downstream service is reduced, and certain protection capability can be provided for the downstream service, so that the pressure of degrading the service is reduced.

Further, obtaining, by the demotion component, a demotion rule comprises:

configuring a degradation rule of the downstream service, and acquiring the degradation rule through the degradation component;

counting, using the downgrade component, a number of times the upstream service access failed comprising:

and setting an asynchronous timing task in the downgrade component, and acquiring the latest times of the upstream service access failure through the timing task.

According to the description, the configurable downgrading rule is obtained through the downgrading assembly, the asynchronous timing task is set in the downgrading assembly, and the latest number of times of the upstream service access failure is obtained in a timing mode, so that the flexibility of the downgrading rule configuration and the instantaneity of obtaining the upstream service access failure data are improved.

Further, if the number of times of access failure reaches a preset number of times in the downgrading rule, stopping sending the access request to the instance of the downstream service or reducing the speed of sending the access request to the instance of the downstream service includes:

if the access failure times of a certain instance reach the preset times in the downgrade rule, identifying the instance as an abnormal instance;

calculating a degraded fraction of all instances in the downstream service;

and judging whether the degraded occupation ratio reaches a preset occupation ratio, if so, reducing the speed of sending the access request to the abnormal example, otherwise, stopping sending the access request to the abnormal example, and identifying the abnormal example as the degraded example.

According to the description, by judging whether the degraded occupation ratios of all the instances in the downstream service reach the preset occupation ratio or not, the access request is selected to be stopped from being sent to the abnormal instance or the speed of sending the access request to the abnormal instance is reduced, the downstream service can provide part of services while the quantity of the requests for the downstream service is reduced, and the downstream service has certain protection capability.

Further, the step of after the degraded occupation ratio reaches the preset occupation ratio comprises the following steps:

and counting the duration of the degraded occupation ratio after reaching a preset occupation ratio, and if the duration is greater than the preset duration, identifying all the undegraded instances in the downstream service as degraded instances.

As can be seen from the above description, when the duration after the degraded occupancy reaches the preset occupancy is longer than the preset duration, the downstream service is completely unavailable at this time, and therefore, all the undegraded instances in the downstream service are identified as degraded instances, which can prevent the upstream service from continuously sending requests to the downstream service end, and reduce the pressure of the downstream service.

Further, identifying all non-degraded instances in the downstream service as degraded instances comprises:

and scanning the degraded examples of the downstream service at regular time through the degrading component, judging whether the degraded examples can be successfully accessed, and if so, identifying the degraded examples as normal examples.

From the above description, when the instances in the downstream service are all degraded instances, the downstream service is periodically scanned to determine whether the downstream service recovers access, so that the degraded instances of the recovered instances can be identified as normal instances in time, and the reliability of the degraded services is ensured.

Referring to fig. 2, another embodiment of the present invention provides a service degradation terminal, including a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor executes the computer program to implement the following steps:

accessing a downgrading component in an upstream service, and acquiring a downgrading rule through the downgrading component;

when the upstream service sends an access request to an instance of a downstream service, the downgrading component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the downgrading rule, the sending of the access request to the instance of the downstream service is stopped or the speed of sending the access request to the instance of the downstream service is reduced until the instance of the downstream service is successfully accessed.

As can be seen from the above description, accessing a downgrading component in an upstream service, and obtaining a downgrading rule through the downgrading component; when an upstream service sends an access request to an instance of a downstream service, a degradation component is used for counting the failure times of the upstream service access, if the failure times reach a preset number, the instance of the downstream service needs to be processed, and the specific processing method is to enable the upstream service to stop sending the access request to the instance of the downstream service or reduce the speed of sending the access request to the instance of the downstream service by the upstream service, so that partial service can be provided even if the downstream service is unstable due to overlarge request; meanwhile, when a large number of problems occur in the accessed downstream service, the request amount of the downstream service is reduced, and certain protection capability can be provided for the downstream service, so that the pressure of degrading the service is reduced.

Further, obtaining, by the demotion component, a demotion rule comprises:

configuring a degradation rule of the downstream service, and acquiring the degradation rule through the degradation component;

counting, using the downgrade component, a number of times the upstream service access failed comprising:

and setting an asynchronous timing task in the downgrade component, and acquiring the latest times of the upstream service access failure through the timing task.

According to the description, the configurable downgrading rule is obtained through the downgrading assembly, the asynchronous timing task is set in the downgrading assembly, and the latest number of times of the upstream service access failure is obtained in a timing mode, so that the flexibility of the downgrading rule configuration and the instantaneity of obtaining the upstream service access failure data are improved.

Further, if the number of times of access failure reaches a preset number of times in the downgrading rule, stopping sending the access request to the instance of the downstream service or reducing the speed of sending the access request to the instance of the downstream service includes:

if the access failure times of a certain instance reach the preset times in the downgrade rule, identifying the instance as an abnormal instance;

calculating a degraded fraction of all instances in the downstream service;

and judging whether the degraded occupation ratio reaches a preset occupation ratio, if so, reducing the speed of sending the access request to the abnormal example, otherwise, stopping sending the access request to the abnormal example, and identifying the abnormal example as the degraded example.

According to the description, by judging whether the degraded occupation ratios of all the instances in the downstream service reach the preset occupation ratio or not, the access request is selected to be stopped from being sent to the abnormal instance or the speed of sending the access request to the abnormal instance is reduced, the downstream service can provide part of services while the quantity of the requests for the downstream service is reduced, and the downstream service has certain protection capability.

Further, the step of after the degraded occupation ratio reaches the preset occupation ratio comprises the following steps:

and counting the duration of the degraded occupation ratio after reaching a preset occupation ratio, and if the duration is greater than the preset duration, identifying all the undegraded instances in the downstream service as degraded instances.

As can be seen from the above description, when the duration after the degraded occupancy reaches the preset occupancy is longer than the preset duration, the downstream service is completely unavailable at this time, and therefore, all the undegraded instances in the downstream service are identified as degraded instances, which can prevent the upstream service from continuously sending requests to the downstream service end, and reduce the pressure of the downstream service.

Further, identifying all non-degraded instances in the downstream service as degraded instances comprises:

and scanning the degraded examples of the downstream service at regular time through the degrading component, judging whether the degraded examples can be successfully accessed, and if so, identifying the degraded examples as normal examples.

From the above description, when the instances in the downstream service are all degraded instances, the downstream service is periodically scanned to determine whether the downstream service recovers access, so that the degraded instances of the recovered instances can be identified as normal instances in time, and the reliability of the degraded services is ensured.

The service degradation method and the terminal of the present invention are suitable for a degradation environment of a micro service project, and can reduce the pressure of degrading services, and are described below by specific embodiments:

example one

Referring to fig. 1, a service degradation method includes the steps of:

s1, accessing a downgrading component in the upstream service, and acquiring the downgrading rule through the downgrading component.

Wherein obtaining, by the demotion component, a demotion rule comprises:

and configuring a degradation rule of the downstream service, and acquiring the degradation rule through the degradation component.

Specifically, in this embodiment, by managing the background custom degradation rule, personalized degradation rule settings are performed for different downstream services, and key functions such as the frequency of upstream services accessing downstream services can be controllably realized;

a downgrade component is accessed in the upstream service, which automatically pulls downgrade rules and caches in local memory of the upstream service.

S2, when the upstream service sends an access request to the downstream service instance, the degradation component is used for counting the number of times of access failure of the upstream service, and if the number of times of access failure reaches the preset number of times in the degradation rule, the access request is stopped from being sent to the downstream service instance or the speed of sending the access request to the downstream service instance is reduced.

Wherein counting, using the downgrading component, a number of times the upstream service access failed comprises:

setting an asynchronous timing task in the downgrade component, and acquiring the latest number of times of the upstream service access failure through the timing task;

if the number of times of access failure of a certain instance reaches a preset number of times in the downgrade rule, it is identified as an abnormal instance.

Specifically, when the upstream service sends an access request to an instance of the downstream service, an asynchronous timing task exists in the downgrading component, the latest data of the upstream service access failure can be pulled from the management background at regular time, and the data of each instance of the request failure in the downgrading component is subjected to statistical processing;

in this embodiment, every 30 seconds is a statistical period, within one period, if there are 3 times of request failures for a certain instance, the instance is determined to be an abnormal instance, and client degradation processing needs to be performed, where the specific degradation processing is: stopping sending access requests to the abnormal instances or reducing the speed of sending access requests to the abnormal instances. In other equivalent embodiments, the statistical period may be 20 seconds, 40 seconds, or 1 minute, among other times. The preset number may be 2, 4, or five or other numbers.

Example two

The difference between this embodiment and the first embodiment is that how to downgrade the service according to the number of access failures is further defined, specifically:

if the number of access failures reaches the preset number in the downgrading rule, stopping sending the access request to the instance of the downstream service or reducing the speed of sending the access request to the instance of the downstream service includes:

calculating a degraded fraction of all instances in the downstream service;

and judging whether the degraded occupation ratio reaches a preset occupation ratio, if so, reducing the speed of sending the access request to the abnormal example, otherwise, stopping sending the access request to the abnormal example, and identifying the abnormal example as the degraded example.

In this embodiment, when a certain instance needs to be degraded, the proportion of the degraded instance to the total instance in the downstream service is judged in advance to obtain the degraded proportion;

when the degraded proportion is less than 50%, the client of the upstream service will identify the instance as a degraded instance in local memory and no longer send a request to the instance.

When the degradation proportion is greater than or equal to 50%, if an abnormal instance needing to be degraded continues to exist, at this time, the degrading component processes the abnormal instance according to the configured degradation condition, in this embodiment, the degradation condition may be to reduce the speed of sending the request to the instance, or when the threshold of the request amount has been reached in unit time, the abnormal information is directly returned, and the request is no longer sent to the instance.

Specifically, suppose that an upstream service a application calls a service of a downstream service B application, and there are 4 nodes in the application B providing external services, where the 4 nodes are a, B, c, and d, respectively;

if the network of the node a is unstable at a certain time, the proportion of the degraded examples to the total examples is checked in advance, and if the proportion is lower than 50%, the client degraded component sets the node a as the degraded example and does not send a request to the node a any more;

pre-checking the proportion of the degraded examples to the total examples, if the proportion is lower than 50%, setting the subsequent node b as the degraded example, and not sending the request to the node b;

and pre-checking the proportion of the degraded examples to the total examples, and when the proportion is higher than or equal to 50%, performing degradation processing on the subsequent examples c and d by adopting the reduced request sending speed.

Wherein the step of obtaining the degraded percentage comprises the following steps:

and counting the duration of the degraded occupation ratio after reaching a preset occupation ratio, and if the duration is greater than the preset duration, identifying all the undegraded instances in the downstream service as degraded instances.

Specifically, after the degraded occupation ratio reaches the preset occupation ratio, the duration after the degraded occupation ratio reaches the preset occupation ratio is counted, if the duration is longer than the preset duration, the downstream service is completely unavailable at this time, all the undegraded instances in the downstream service are identified as degraded instances, and the upstream service can be prevented from continuously accessing the unavailable downstream service.

Wherein identifying all non-degraded instances in the downstream service as degraded instances comprises:

and scanning the degraded examples of the downstream service at regular time through the degrading component, judging whether the degraded examples can be successfully accessed, and if so, identifying the degraded examples as normal examples.

Specifically, the timing task in the downgrade module scans the instances of the downstream service at intervals, and when the instances of the downstream service are recovered to normal, the state information of the abnormal instances in the local memory is recovered, and the recovered instances are identified as normal instances.

EXAMPLE III

Referring to fig. 2, a service degradation terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the service degradation method according to the first embodiment when executing the computer program.

In summary, the method and the terminal for service degradation provided by the present invention access the degradation component in the upstream service, and obtain the degradation rule through the degradation component, wherein the degradation rule is configurable and can adapt to different downstream services; when an upstream service sends an access request to an instance of a downstream service, a degradation component is used for regularly counting the failure times of the upstream service access, if the failure times reach a preset number, the instance is an abnormal instance, degraded occupation ratios of all instances in the current downstream service are obtained, if the degraded occupation ratios do not reach the preset occupation ratios, the upstream service stops sending the access request to the abnormal instance, and if the degraded occupation ratios reach the preset occupation ratios, the speed of sending the access request to the abnormal instance by the upstream service is reduced, so that even if the downstream service is unstable due to overlarge requests, partial service can be provided; meanwhile, when a large number of problems occur in the accessed downstream service, the request amount of the downstream service is reduced, and certain protection capability can be provided for the downstream service; when the degraded occupancy reaches the preset occupancy, the duration of the state starts to be counted, if the duration exceeds the preset value, the downstream service can be considered to be unavailable, and all the instances in the downstream service need to be identified as degraded instances, so that the invalid access requests of the upstream are reduced, and the pressure of the degraded service is reduced.

The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

10页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种流量控制方法、装置、设备及介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!