如何做akka-http请求级背压?

时间:2017-10-13 22:12:51

标签: akka akka-stream akka-http rate-limiting backpressure

在akka-http中,你可以:

  1. 设置akka.http.server.max-connections,这将阻止超过该数量的连接。超过此限制意味着客户端将获得连接超时。
  2. 设置akka.http.server.pipelining-limit,它可以防止给定连接一次超过此数量的请求。超过这意味着客户端将获得套接字超时。
  3. 这些都是从http服务器到客户端的背压形式,但两者都是非常低级别的,并且只与您服务器的性能间接相关。

    根据服务器看到的请求率,似乎更好的是在http级别进行背压。可能返回429 - 太多请求。 请求率也可以说是对绩效的间接衡量,但似乎比连接数更接近。

    这似乎是一个相当合理的事情,但我找不到任何现有的模式。这是我能找到的最接近的参考:https://github.com/akka/akka-http/issues/411

    据我所知,最好的方法是抓住FlowRoute转换为Route,并将其插入到具有全球请求率度量的图表中(或者可能是单个处理队列)和一个完全绕过import turtle import random import sys while True: list = ['report', 'beach', 'mayor', 'score', 'overeat', 'load', 'battery', 'social', 'honor', 'risk'] turns = 10 guesses = '' err = 0 usedw = random.choice(list) wn = turtle.Screen() draw = turtle.Turtle() length = len(usedw) print("Welcome to hangman your word is", length, "letters long.") while turns > 0: guess = input("Choose a character: ") guesses += guess; lengthr = 0 for char in usedw: if char in guesses: print (char,) lengthr += 1; else: err += 1; if err == 1: draw.goto(0,0) draw.down() draw.goto(200,0) elif err == 2: draw.up() draw.goto(0,0) draw.down() draw.goto(0,200) elif err == 3: draw.up() draw.goto(0,200) draw.down() draw.goto(100,200) elif err == 4: draw.up() draw.goto(100,200) draw.down() draw.goto(100,150) elif err == 5: draw.up() draw.goto(100,100) draw.down() draw.circle(25) elif err == 6: draw.up() draw.goto(100,100) draw.down() draw.goto(100,50) elif err == 7: draw.up() draw.goto(75,90) draw.down() draw.goto(125,90) elif err == 8: draw.up() draw.goto(100,50) draw.down() draw.goto(75,35) elif err == 9: draw.up() draw.goto(100,50) draw.down() draw.goto(125,35) print("You loose.") break if lengthr == length: print ("You won!") break cont = input("Would you like to continue (y/n) ") if cont == 'y': print("Alright!") else: print("Thanks for playing!") break sys.exit() (通过返回429或其他)的短路。

    有更好的想法吗?

0 个答案:

没有答案