The invention discloses a redis-based dynamic service degradation method, which includes the following steps: establishing a key for each service interface in redis to record the visits during the preset monitoring period; setting a request threshold for each service interface; calculating the request rejection rate for each service interface; and making corresponding dynamic service degradation policies for each service interface according to the request rejection rate. Slightly dealt with. The invention also proposes a redis-based dynamic service degrading device, which includes a recording module, a setting module, a computing module and a processing module. The invention provides a server whose processor executes the steps of the method. The invention also provides a computer readable storage medium whose computer program executes the steps of the method. The invention formulates a flexible and dynamic service degradation strategy by combining redis with real-time access at the service interface level, ensures the health of the service and interface when the traffic increases sharply, and improves the robustness of the system. The invention belongs to the field of software engineering.
【技术实现步骤摘要】
基于redis的服务动态降级方法、装置、服务器及存储介质
本专利技术公开了一种基于redis的服务动态降级方法、装置、服务器及存储介质,属于软件工程领域。
技术介绍
软件工程领域,常有流量的大范围波动,如电商和游戏行业,在一些商业活动的时候,有大量请求和流量同时涌入,形成流量波峰,流量的剧增对服务器和应用带来巨大冲击,如果不加处理,可能造成服务挂掉,服务器宕机等情况,造成应用不可使用。常用的服务接口的流量控制策略有分流、降级、限流等。比如事先预警大流量,并提前扩容服务器,增加机器应对流量剧增,但是这种方法成本较高,开销较大,增加了运维成本。还有的系统采用配置化的限流策略,让用户请求排队处理或直接返回错误或者默认数据,这种方法很好的应对了流量剧增,但是需要人工配置并及时调整,如果调整不及时会带来不可预料的问题。
技术实现思路
本专利技术公开了一种基于redis的服务动态降级方法、装置、服务器及存储介质,用于在流量剧增时自动执行流量监控及服务动态降级的策略,保证服务正常运行。本专利技术实施例的第一方面,提供了一种基于redis的服务动态降级方法,具体采用了如下技术方案:S1、预设监控周期,在redis数据库中为每个服务接口建立一个string类型的key,用所述string类型的key记录各个服务接口在所述预设监控周期内的访问量;S2、为每个服务接口设置在所述预设监控周期内的请求量阈值;S3、根据所述访问量及所述请求量阈值计算各个服务接口的请求拒绝率;S4、根据所述请求拒绝率对各个服务接口做对应的服务动态降级策略处理。在上述技术方案中,步骤S1中所述用所述stri ...
【技术保护点】
1.一种基于redis的服务动态降级方法,其特征在于,包括如下步骤:S1、预设监控周期,在redis数据库中为每个服务接口建立一个string类型的key,用所述string类型的key记录各个服务接口在所述预设监控周期内的访问量;S2、为每个服务接口设置在所述预设监控周期内的请求量阈值;S3、根据所述访问量及所述请求量阈值计算各个服务接口的请求拒绝率;S4、根据所述请求拒绝率对各个服务接口做对应的服务动态降级策略处理。
【技术特征摘要】
1.一种基于redis的服务动态降级方法,其特征在于,包括如下步骤:S1、预设监控周期,在redis数据库中为每个服务接口建立一个string类型的key,用所述string类型的key记录各个服务接口在所述预设监控周期内的访问量;S2、为每个服务接口设置在所述预设监控周期内的请求量阈值;S3、根据所述访问量及所述请求量阈值计算各个服务接口的请求拒绝率;S4、根据所述请求拒绝率对各个服务接口做对应的服务动态降级策略处理。2.根据权利要求1所述基于redis的服务动态降级方法,其特性在于,步骤S1中所述用所述string类型的key记录每个服务接口在所述预设监控周期内的访问量的具体过程为:将所述string类型的key的过期时间设置为所述预设监控周期,单个服务接口每接收到一次用户请求都将所述服务接口对应的所述string类型key的键值加1。3.根据权利要求1所述基于redis的服务动态降级方法,其特性在于,步骤S2中所述请求量阈值,是基于当前的服务资源和服务接口的具体处理性能综合指定,所述请求量阈值的计算方式为:统计在指定的天数内,每个接口平均每天响应时间在设定参考时间内的请求数,继而计算各个服务接口在所述预设监控周期内的请求数,根据在所述预设监控周期内的请求数设置请求量阈值;将所述请求量阈值以hash类型的key存储在redis数据库中,并且可实时修改。4.根据权利要求1所述基于redis的服务动态降级方法,其特性在于,步骤S3中所述根据所述访问量及所述请求量阈值计算各个服务接口的请求拒绝率之前还包括:按所述预设监控周期扫描各个接口中所述string类型的key,获取各个服务接口在当前监控周期内的访问量,同时查询各个服务接口设置的请求量阈值。5.根据权利要求1所述基于redis的服务动态降级方法,其特性在于,所述步骤S3的具体过程为:设服务接口总数为n,i=1,2,…,n,第i个服务接口在当前监控周期内的访...
【专利技术属性】
技术研发人员:张振铎,
申请(专利权)人:武汉斗鱼网络科技有限公司,
类型:发明
国别省市:湖北,42
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。