From f223a56fd503125452864c5d222ff7c70499ff6b Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 24 Aug 2020 12:09:51 +0800 Subject: [PATCH] 4.0.3 --- doc/docs/files/10092_接口限流.md | 4 +-- .../api/service/param/LimitNewAddParam.java | 4 +-- .../service/param/LimitNewUpdateParam.java | 4 +-- .../api/service/param/LimitParam.java | 4 +-- .../api/service/result/LimitNewVO.java | 4 +-- .../api/service/result/LimitVO.java | 4 +-- .../sop/adminserver/bean/ConfigLimitDto.java | 2 +- .../sop/adminserver/common/LimitEnum.java | 2 +- .../sop/adminserver/entity/ConfigLimit.java | 2 +- .../limit/DefaultLimitManager.java | 2 +- .../sop/gatewaycommon/limit/LimitType.java | 2 +- .../gitee/sop/gateway/entity/ConfigLimit.java | 2 +- .../sop/gateway/entity/ConfigRouteLimit.java | 2 +- sop-mysql5.6以下版本.sql | 15 ++--------- sop.sql | 27 ++----------------- 15 files changed, 23 insertions(+), 57 deletions(-) diff --git a/doc/docs/files/10092_接口限流.md b/doc/docs/files/10092_接口限流.md index 8f1c9ef8..06b9e481 100644 --- a/doc/docs/files/10092_接口限流.md +++ b/doc/docs/files/10092_接口限流.md @@ -2,10 +2,10 @@ SOP提供了简单的接口限流策略: -- 漏桶策略:每秒处理固定数量的请求,超出请求返回错误信息。 +- 窗口策略:每秒处理固定数量的请求,超出请求返回错误信息。 - 令牌桶策略:每秒放置固定数量的令牌数,每个请求进来后先去拿令牌,拿到了令牌才能继续,拿不到则等候令牌重新生成了再拿。 -如果一个接口设置了漏桶策略,假设接口每秒可处理5个请求,一秒内同时有6个请求进来,前5个接口是能够访问的,第六个请求将返回错误信息。 +如果一个接口设置了窗口策略,假设接口每秒可处理5个请求,一秒内同时有6个请求进来,前5个接口是能够访问的,第六个请求将返回错误信息。 如果设置了令牌桶策略,桶的容量是5,那么每秒中生成5个令牌,同一时间有6个请求进来,那么前5个能成功拿到令牌继续,第六个则等待,令牌重新生成了再拿。 diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewAddParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewAddParam.java index 470de1e4..e686edd6 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewAddParam.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewAddParam.java @@ -30,8 +30,8 @@ public class LimitNewAddParam { @NotBlank(message = "serviceId can not null") private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ - @ApiDocField(description = "限流策略,1:漏桶策略,2:令牌桶策略") + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ + @ApiDocField(description = "限流策略,1:窗口策略,2:令牌桶策略") @NotNull(message = "limitType不能为空") private Byte limitType; diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewUpdateParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewUpdateParam.java index 5f4902fa..5b326e69 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewUpdateParam.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitNewUpdateParam.java @@ -35,8 +35,8 @@ public class LimitNewUpdateParam { @NotBlank(message = "serviceId can not null") private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ - @ApiDocField(description = "限流策略,1:漏桶策略,2:令牌桶策略") + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ + @ApiDocField(description = "限流策略,1:窗口策略,2:令牌桶策略") @NotNull(message = "limitType不能为空") private Byte limitType; diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitParam.java index c2e36a52..dbd5172e 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitParam.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/LimitParam.java @@ -20,8 +20,8 @@ public class LimitParam { @NotBlank(message = "serviceId can not null") private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ - @ApiDocField(description = "限流策略,1:漏桶策略,2:令牌桶策略") + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ + @ApiDocField(description = "限流策略,1:窗口策略,2:令牌桶策略") @NotNull private Byte limitType; diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitNewVO.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitNewVO.java index 1ec2c6b9..58c2de38 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitNewVO.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitNewVO.java @@ -41,9 +41,9 @@ public class LimitNewVO { private String serviceId; /** - * 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type + * 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ - @ApiDocField(description = "限流策略,1:漏桶策略,2:令牌桶策略") + @ApiDocField(description = "限流策略,1:窗口策略,2:令牌桶策略") private Byte limitType; /** diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitVO.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitVO.java index 166f72cc..afcb218d 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitVO.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/LimitVO.java @@ -32,9 +32,9 @@ public class LimitVO { private String serviceId; /** - * 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type + * 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ - @ApiDocField(description = "限流策略,1:漏桶策略,2:令牌桶策略") + @ApiDocField(description = "限流策略,1:窗口策略,2:令牌桶策略") private Byte limitType; /** diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ConfigLimitDto.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ConfigLimitDto.java index 701c9622..94d646bf 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ConfigLimitDto.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ConfigLimitDto.java @@ -21,7 +21,7 @@ public class ConfigLimitDto { /** 服务id, 数据库字段:service_id */ private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ private Byte limitType; /** 每秒可处理请求数, 数据库字段:exec_count_per_second */ diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/LimitEnum.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/LimitEnum.java index e516dbf9..1dc2048f 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/LimitEnum.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/LimitEnum.java @@ -6,7 +6,7 @@ package com.gitee.sop.adminserver.common; */ public enum LimitEnum { /** - * 限流策略,1:漏桶策略 + * 限流策略,1:窗口策略 */ TYPE_LEAKY_BUCKET((byte) 1), /** diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigLimit.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigLimit.java index d14fa006..0a7b60f0 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigLimit.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigLimit.java @@ -37,7 +37,7 @@ public class ConfigLimit { /** 服务id, 数据库字段:service_id */ private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ private Byte limitType; /** 每秒可处理请求数, 数据库字段:exec_count_per_second */ diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/DefaultLimitManager.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/DefaultLimitManager.java index a7f78048..e79b32da 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/DefaultLimitManager.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/DefaultLimitManager.java @@ -39,7 +39,7 @@ public class DefaultLimitManager implements LimitManager { // 被限流了 return counter.get(routeConfig.getId()).incrementAndGet() <= execCountPerSecond; } catch (ExecutionException e) { - log.error("漏桶限流出错,routeConfig:{}", routeConfig, e); + log.error("窗口限流出错,routeConfig:{}", routeConfig, e); return false; } } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/LimitType.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/LimitType.java index 66da4379..2837a998 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/LimitType.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/limit/LimitType.java @@ -7,7 +7,7 @@ package com.gitee.sop.gatewaycommon.limit; */ public enum LimitType { /** - * 漏桶策略。每秒处理固定数量的请求,超出请求返回错误信息。 + * 窗口策略。每秒处理固定数量的请求,超出请求返回错误信息。 */ LEAKY_BUCKET(1), /** diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigLimit.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigLimit.java index 43cd1cdc..30bd01c4 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigLimit.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigLimit.java @@ -38,7 +38,7 @@ public class ConfigLimit { /** 服务id, 数据库字段:service_id */ private String serviceId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ private Byte limitType; /** 每秒可处理请求数, 数据库字段:exec_count_per_second */ diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigRouteLimit.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigRouteLimit.java index da4584e5..cd52de97 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigRouteLimit.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigRouteLimit.java @@ -28,7 +28,7 @@ public class ConfigRouteLimit { /** 路由id, 数据库字段:route_id */ private String routeId; - /** 限流策略,1:漏桶策略,2:令牌桶策略, 数据库字段:limit_type */ + /** 限流策略,1:窗口策略,2:令牌桶策略, 数据库字段:limit_type */ private Byte limitType; /** 每秒可处理请求数, 数据库字段:exec_count_per_second */ diff --git a/sop-mysql5.6以下版本.sql b/sop-mysql5.6以下版本.sql index 66d3cf3a..4b8694d9 100644 --- a/sop-mysql5.6以下版本.sql +++ b/sop-mysql5.6以下版本.sql @@ -87,7 +87,7 @@ CREATE TABLE `config_limit` ( `app_key` VARCHAR(128) DEFAULT NULL, `limit_ip` VARCHAR(300) DEFAULT NULL COMMENT '限流ip,多个用英文逗号隔开', `service_id` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '服务id', - `limit_type` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:漏桶策略,2:令牌桶策略', + `limit_type` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:窗口策略,2:令牌桶策略', `exec_count_per_second` INT(11) DEFAULT NULL COMMENT '每秒可处理请求数', `duration_seconds` INT(11) NOT NULL DEFAULT '1' COMMENT '限流持续时间,默认1秒,即每durationSeconds秒允许多少请求(当limit_type=1时有效)', `limit_code` VARCHAR(64) DEFAULT NULL COMMENT '返回的错误码', @@ -117,7 +117,7 @@ CREATE TABLE `config_route_limit` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `route_id` VARCHAR(64) NOT NULL COMMENT '路由id', `service_id` VARCHAR(64) NOT NULL DEFAULT '', - `limit_type` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:漏桶策略,2:令牌桶策略', + `limit_type` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:窗口策略,2:令牌桶策略', `exec_count_per_second` INT(11) DEFAULT NULL COMMENT '每秒可处理请求数', `limit_code` VARCHAR(64) DEFAULT NULL COMMENT '返回的错误码', `limit_msg` VARCHAR(100) DEFAULT NULL COMMENT '返回的错误信息', @@ -231,17 +231,6 @@ INSERT INTO `admin_user_info` (`id`, `username`, `password`, `status`, `gmt_crea ALTER TABLE `admin_user_info` ENABLE KEYS; -INSERT INTO `config_limit` (`id`, `route_id`, `app_key`, `limit_ip`, `service_id`, `limit_type`, `exec_count_per_second`, `limit_code`, `limit_msg`, `token_bucket_count`, `limit_status`, `order_index`, `remark`, `gmt_create`, `gmt_modified`) VALUES - (1,'alipay.story.get1.0','','192.168.1.1,172.2.2.3','story-service',2,5,'','',6,1,3,NULL,'2019-05-17 19:21:35','2019-05-21 09:12:15'), - (2,'alipay.story.get1.0','2019032617262200001','','story-service',2,5,'service-budy','服务器忙',10,1,0,'','2019-05-17 19:39:30','2019-05-21 15:36:52'), - (3,'alipay.story.find1.0','20190331562013861008375808','','story-service',1,3,'service-busy','服务器忙',5,1,1,NULL,'2019-05-17 20:20:32','2019-05-20 17:40:17'), - (4,'alipay.story.get1.2','','','story-service',1,5,'service-busy','服务器忙',3,1,1,'','2019-05-20 16:27:21','2019-05-21 15:53:10'), - (5,'','20190401562373796095328256','','story-service',1,5,'service-busy','服务器忙',5,1,0,'这个appKey调用很频繁,重点照顾','2019-05-21 15:48:08','2019-05-21 18:45:32'), - (6,'','','10.1.30.54','story-service',1,5,'service-busy','服务器忙',5,1,0,'这个ip在攻击我们','2019-05-21 15:55:33','2019-05-21 18:17:29'), - (7,'story.get1.1','','10.1.30.54','story-service',1,5,'service-busy','服务器忙',5,1,0,NULL,'2019-05-21 16:30:48','2019-05-21 16:30:48'), - (8,'','20190513577548661718777857','10.1.30.54','story-service',1,5,'service-busy','服务器忙',5,1,0,NULL,'2019-05-21 17:10:45','2019-05-21 17:10:52'); - - INSERT INTO `config_route_base` (`id`, `route_id`, `status`, `gmt_create`, `gmt_modified`) VALUES (1,'story.get1.1',1,'2019-04-09 19:15:58','2019-04-09 19:16:54'), (2,'alipay.story.get1.0',1,'2019-04-09 19:19:57','2019-04-19 14:45:33'), diff --git a/sop.sql b/sop.sql index 181d4c8e..2f850206 100644 --- a/sop.sql +++ b/sop.sql @@ -89,7 +89,7 @@ CREATE TABLE `config_limit` ( `app_key` varchar(128) DEFAULT NULL, `limit_ip` varchar(300) DEFAULT NULL COMMENT '限流ip,多个用英文逗号隔开', `service_id` varchar(64) NOT NULL DEFAULT '' COMMENT '服务id', - `limit_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:漏桶策略,2:令牌桶策略', + `limit_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:窗口策略,2:令牌桶策略', `exec_count_per_second` int(11) DEFAULT NULL COMMENT '每秒可处理请求数', `duration_seconds` int(11) NOT NULL DEFAULT '1' COMMENT '限流持续时间,默认1秒,即每durationSeconds秒允许多少请求(当limit_type=1时有效)', `limit_code` varchar(64) DEFAULT NULL COMMENT '返回的错误码', @@ -119,7 +119,7 @@ CREATE TABLE `config_route_limit` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `route_id` varchar(64) NOT NULL COMMENT '路由id', `service_id` varchar(64) NOT NULL DEFAULT '', - `limit_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:漏桶策略,2:令牌桶策略', + `limit_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '限流策略,1:窗口策略,2:令牌桶策略', `exec_count_per_second` int(11) DEFAULT NULL COMMENT '每秒可处理请求数', `limit_code` varchar(64) DEFAULT NULL COMMENT '返回的错误码', `limit_msg` varchar(100) DEFAULT NULL COMMENT '返回的错误信息', @@ -229,31 +229,10 @@ CREATE TABLE `user_info` ( ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='用户信息表'; - - INSERT INTO `admin_user_info` (`id`, `username`, `password`, `status`, `gmt_create`, `gmt_modified`) VALUES (1,'admin','a62cd510fb9a8a557a27ef279569091f',1,'2019-04-02 19:55:26','2019-04-02 19:55:26'); - - - - - - - - -INSERT INTO `config_limit` (`id`, `route_id`, `app_key`, `limit_ip`, `service_id`, `limit_type`, `exec_count_per_second`, `duration_seconds`, `limit_code`, `limit_msg`, `token_bucket_count`, `limit_status`, `order_index`, `remark`, `gmt_create`, `gmt_modified`) VALUES - (1,'alipay.story.get1.0','','192.168.1.1,172.2.2.3','story-service',2,5,1,'','',6,1,3,NULL,'2019-05-17 19:21:35','2019-05-21 09:12:15'), - (2,'alipay.story.get1.0','2019032617262200001','','story-service',2,5,1,'service-budy','服务器忙',10,1,0,'','2019-05-17 19:39:30','2019-05-21 15:36:52'), - (3,'alipay.story.find1.0','20190331562013861008375808','','story-service',1,3,1,'service-busy','服务器忙',5,1,1,NULL,'2019-05-17 20:20:32','2019-05-20 17:40:17'), - (4,'alipay.story.get1.2','','','story-service',1,5,1,'service-busy','服务器忙',3,1,1,'','2019-05-20 16:27:21','2019-05-21 15:53:10'), - (5,'','20190401562373796095328256','','story-service',1,5,1,'service-busy','服务器忙',5,1,0,'这个appKey调用很频繁,重点照顾','2019-05-21 15:48:08','2019-05-21 18:45:32'), - (6,'','','10.1.30.54','story-service',1,5,1,'service-busy','服务器忙',5,1,0,'这个ip在攻击我们','2019-05-21 15:55:33','2019-05-21 18:17:29'), - (7,'story.get1.1','','10.1.30.54','story-service',1,5,1,'service-busy','服务器忙',5,1,0,NULL,'2019-05-21 16:30:48','2019-05-21 16:30:48'), - (8,'','20190513577548661718777857','10.1.30.54','story-service',1,5,1,'service-busy','服务器忙',5,1,0,NULL,'2019-05-21 17:10:45','2019-05-21 17:10:52'); - - INSERT INTO `config_route_base` (`id`, `route_id`, `status`, `gmt_create`, `gmt_modified`) VALUES (1,'story.get1.1',1,'2019-04-09 19:15:58','2019-04-09 19:16:54'), (2,'alipay.story.get1.0',1,'2019-04-09 19:19:57','2019-04-19 14:45:33'), @@ -272,8 +251,6 @@ INSERT INTO `config_route_limit` (`id`, `route_id`, `service_id`, `limit_type`, (4,'alipay.category.get1.0','story-service',1,5,'error-code','服务器忙',5,1,'2019-05-07 12:22:04','2019-05-07 12:25:06'); - - INSERT INTO `isv_info` (`id`, `app_key`, `status`, `sign_type`, `remark`, `gmt_create`, `gmt_modified`) VALUES (1,'2019032617262200001',1,1,NULL,'2019-03-27 10:10:34','2019-05-09 11:10:38'), (3,'asdfasdf',2,1,NULL,'2019-03-27 11:01:11','2019-05-11 10:45:01'),