发表文章

[Java] 按请求时间的速率限制 Rate limit by request time[spring-cloud-zuul-ratelimit]

lchayoun 2017-10-9 27

我们已经看到的情况下, 按请求号码的速率限制是不够的
有时单个请求可能会很长, 并且会加载网关

添加一个选项, 以测量请求时间, 并添加另一个限制选项的时间奎达可能会帮助在这种情况下

@marcosbarbero你认为这是个好主意吗?

原文:

we have seen cases that rate limit by request number is not enough
sometimes a single request can be long and load the gateway

adding an option to measure the request time and add another limit option by time quetta might help in such cases

@marcosbarbero do you think it's a good idea?

相关推荐
最新评论 (10)
marcosbarbero 2017-10-9
1

听起来不错, 你能详细阐述一下你的想法吗?

原文:

Sounds good, can you elaborate a little bit more about what you have in mind?

lchayoun 2017-10-9
2

我正在考虑一个新的参数到 Policy 类名为 "配额" 将表现如下:

  1. 用户将定义配额 (可选), 限制也将是可选的, 其中一个必须被定义
  2. RateLimitFilter 中, 将当前时间保存到请求属性 (如果定义了配额)
  3. 将添加一个新的 "post" 筛选器, 筛选器将检查开始时间的属性是否存在, 如果这样, 筛选器将计算经过的时间并将其从配额中减少
  4. 如果配额超过它将拒绝新的请求

这将帮助我们区分系统中的请求权重。
唯一的问题是, 时间是在每个请求的末尾计算的, 所以同时新的请求可以进入系统。

我认为这将增加一些权力的速率限制机制, 可以进一步加强

原文:

I was thinking of a new parameter to the Policy class called "quota" which will behave as follow:

  1. The user will define the quota (optional), limit will be optional as well, one of them has to be defined
  2. In the RateLimitFilter will save the current time to the request attributes (if quota is defined)
  3. A new "post" filter will be added, the filter will check if the attribute of the start time exists, if so the filter will calculate the elapsed time and reduce it from the quota
  4. If the quota exceeded it will reject the new requests

This will help us differentiate the requests weight on the system.
The only issue is that the the time is calculated at the end of each request, so meantime new requests can enter the system.

I think it will add some power to the rate limit mechanism that can be enhanced further

marcosbarbero 2017-10-9
3

感谢您的信息@lchayoun

这对我来说很清楚, 唯一的担心, 我已经你已经指出, 这是关于在稍后的阶段进行的计算意味着新的请求可以跳, 即使你已经达到速率极限容量。

原文:

Thanks for the info @lchayoun.

It's clear for me now, the only concern that I've you already pointed it's about the calculation being done in a later phase meaning new requests can jump in even thou the rate limit capacity has already being reached.

lchayoun 2017-10-9
4

我同意, 但有一个坚实的超时, 我认为它会足够强大, 你要我创建一个拉请求对它?

原文:

I agree, but with a solid timeout I think it will be strong enough, do you want me to create a pull request on it?

marcosbarbero 2017-10-9
5

@lchayoun如果有时间, 这将是很棒的:)

原文:

@lchayoun if you have time it would be awesome :)

marcosbarbero 2017-10-9
6

@lchayoun您是否能够使用所做的更改在本地编译项目?
我面临一些有关 consul 实现的问题。

com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'eyJrZXkiOiJyYXRlLWxpbWl0LWFwcGxpY2F0aW9uOnNlcnZpY2VEOi9zZXJ2aWNlRC9mNzA1NjI2NS1hNThiLTRjNmUtOTliMi04NTI3ZjIxMTM4NDAiLCJyZW1haW5pbmciOjEsInJlbWFpbmluZ1F1b3RhIjpudWxsLCJyZXNldCI6NjAwMDAsImV4cGlyYXRpb24iOiIyMC0wOS0yMDE3IDA4OjAyOjE4In0': was expecting ('true', 'false' or 'null')
 at [Source: eyJrZXkiOiJyYXRlLWxpbWl0LWFwcGxpY2F0aW9uOnNlcnZpY2VEOi9zZXJ2aWNlRC9mNzA1NjI2NS1hNThiLTRjNmUtOTliMi04NTI3ZjIxMTM4NDAiLCJyZW1haW5pbmciOjEsInJlbWFpbmluZ1F1b3RhIjpudWxsLCJyZXNldCI6NjAwMDAsImV4cGlyYXRpb24iOiIyMC0wOS0yMDE3IDA4OjAyOjE4In0=; line: 1, column: 232]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2839) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1903) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:749) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3850) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3799) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.ConsulRateLimiter.getRate(ConsulRateLimiter.java:49) ~[spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.AbstractRateLimiter.create(AbstractRateLimiter.java:31) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.AbstractRateLimiter.consume(AbstractRateLimiter.java:24) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.RateLimitPreFilter.lambda$run$0(RateLimitPreFilter.java:75) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at java.util.Optional.ifPresent(Optional.java:159) ~[na:1.8.0_131]

我相信这是与 ConsulRateLimiter#getRate(String) 在这一行:

rate = this.objectMapper.readValue(value.getValue(), Rate.class);
原文:

@lchayoun were you able to compile the project locally with your changes?
I'm facing some issues regarding consul implementation.

com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'eyJrZXkiOiJyYXRlLWxpbWl0LWFwcGxpY2F0aW9uOnNlcnZpY2VEOi9zZXJ2aWNlRC9mNzA1NjI2NS1hNThiLTRjNmUtOTliMi04NTI3ZjIxMTM4NDAiLCJyZW1haW5pbmciOjEsInJlbWFpbmluZ1F1b3RhIjpudWxsLCJyZXNldCI6NjAwMDAsImV4cGlyYXRpb24iOiIyMC0wOS0yMDE3IDA4OjAyOjE4In0': was expecting ('true', 'false' or 'null')
 at [Source: eyJrZXkiOiJyYXRlLWxpbWl0LWFwcGxpY2F0aW9uOnNlcnZpY2VEOi9zZXJ2aWNlRC9mNzA1NjI2NS1hNThiLTRjNmUtOTliMi04NTI3ZjIxMTM4NDAiLCJyZW1haW5pbmciOjEsInJlbWFpbmluZ1F1b3RhIjpudWxsLCJyZXNldCI6NjAwMDAsImV4cGlyYXRpb24iOiIyMC0wOS0yMDE3IDA4OjAyOjE4In0=; line: 1, column: 232]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2839) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1903) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:749) ~[jackson-core-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3850) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3799) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858) ~[jackson-databind-2.8.9.jar:2.8.9]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.ConsulRateLimiter.getRate(ConsulRateLimiter.java:49) ~[spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.AbstractRateLimiter.create(AbstractRateLimiter.java:31) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.AbstractRateLimiter.consume(AbstractRateLimiter.java:24) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.RateLimitPreFilter.lambda$run$0(RateLimitPreFilter.java:75) [spring-cloud-zuul-ratelimit-core-1.3.2.RELEASE.jar:1.3.2.RELEASE]
        at java.util.Optional.ifPresent(Optional.java:159) ~[na:1.8.0_131]

I believe it's related to ConsulRateLimiter#getRate(String) at this line:

rate = this.objectMapper.readValue(value.getValue(), Rate.class);
lchayoun 2017-10-9
7

分叉它再次, 看到同样的问题, 采取了一看

原文:

forked it again, seeing the same issue, taking a look

marcosbarbero 2017-10-9
8

@lchayoun在一堆中感谢

原文:

@lchayoun thanks in a bunch

marcosbarbero 2017-10-9
9

@lchayoun您是否有时间处理筛选器的几个测试 post ?似乎整个 #run() 方法都没有测试。

如果你没有时间, 让我知道。

原文:

@lchayoun do you have time to work on few tests for post filter? It seems that the whole #run() method has no test.

If you don't have time let me know.

marcosbarbero 2017-10-9
10

@lchayoun我们去v1.3 3. 发布

原文:

@lchayoun here we go v1.3.3.RELEASE.

返回
发表文章
lchayoun
文章数
1
评论数
3
注册排名
60728