How to do akka-http request-level backpressure?

徘徊边缘 提交于 2019-12-07 19:59:04

问题


In akka-http, you can:

  1. Set akka.http.server.max-connections, which will prevent more than that number of connections. Exceeding this limit means clients will get connection timeouts.
  2. Set akka.http.server.pipelining-limit, which prevents a given connection from having more than this number of requests outstanding at once. Exceeding this means clients will get socket timeouts.

These are both forms of backpressure from the http server to the client, but both are very low level, and only indirectly related to your server's performance.

What seems better would be to backpressure at the http level, based on request rate as seen by the server. Probably by returning 429 - Too Many Requests. Request rate is arguably an indirect measure of performance too, but it seems closer than number of connections.

This seems like a fairly reasonable thing, but I'm having trouble finding any existing patterns. This is the closest reference I can find: https://github.com/akka/akka-http/issues/411

From what I can tell, the best approach would be to grab the Flow you turn your Route into, and insert it into a graph that has a global measure of request rate (or maybe a single processing queue) and a short-circuit that bypasses the Route (by returning 429 or whatever) entirely.

Are there better ideas?

来源:https://stackoverflow.com/questions/46738696/how-to-do-akka-http-request-level-backpressure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!