Akka 从管线创建时,流量节流不起作用

Akka 从管线创建时,流量节流不起作用,akka,akka-stream,akka-http,Akka,Akka Stream,Akka Http,考虑包含所有HTTP服务的路由 val routes:Route = ... 我希望限制请求的数量,所以我使用Route.handleFlow(routes)来创建流,并使用有限的持续时间调用了throttle方法 最后,我使用 Http().bindAndHandle(flowObjectAfterThrottling, hostname, port) 从循环触发HTTP请求时,akka不遵守限制 一种可能性是,“从循环触发”的http请求可能使用单独的连接。每个传入连接都以适当的速率进行

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

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

最后,我使用

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

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

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

改用配置

您不需要编写软件来设置
路线的限制费率

如果您只关心资源(如磁盘或RAM)的消耗,则可以删除速率逻辑并改用:

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

# 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