【问题标题】:Throttling of Flow not working when created from Route从路由创建时流的限制不起作用
【发布时间】:2018-11-12 03:33:58
【问题描述】:

考虑包含所有 HTTP 服务的路由

val routes:Route = ...

我希望限制请求的数量,所以我使用Route.handleFlow(routes) 创建流并调用限制持续时间的限制方法。

最后,我创建了 HTTP 绑定使用

Http().bindAndHandle(flowObjectAfterThrottling, hostname, port)

当 HTTP 请求从循环中触发时,akka 不遵守限制。

【问题讨论】:

    标签: akka akka-stream akka-http


    【解决方案1】:

    一种可能性是“从循环中触发”的 http 请求可能使用单独的连接。每个传入连接都以适当的速率进行节流,但总吞吐量高于预期。

    改用配置

    您无需编写软件即可为您的Route 设置限制费率。

    如果您只关心资源的消耗,例如磁盘或 RAM,那么您可以删除速率逻辑并改用 akka configuration settings

    # The maximum number of concurrently accepted connections when using the
    # `Http().bindAndHandle` methods.
    max-connections = 1024
    
    # The maximum number of requests that are accepted (and dispatched to
    # the application) on one single connection before the first request
    # has to be completed.
    pipelining-limit = 16
    

    这不提供设置最大频率的能力,但它至少允许指定最大并发使用量,这通常足以保护资源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2015-07-03
      • 2015-06-23
      • 1970-01-01
      • 2016-02-29
      • 2014-09-07
      • 2023-04-03
      相关资源
      最近更新 更多