我正在使用 spray-can 版本 1.3.3 和 akka 2.3.9 服务器代码看起来很标准
应用程序.conf:
spray.can {
server {
pipelining-limit = 10
request-timeout = 50ms
stats-support = on
}
...
引导:
object Boot extends App {
implicit val system = ActorSystem("on-spray-can")
val service = system.actorOf(Props[MyServiceActor], "demo-service")
IO(Http) ! Http.Bind(service, "0.0.0.0", port = 8080)
}
我的服务演员:
class MyServiceActor extends Actor with MyService {
def actorRefFactory = context
def receive = runRoute(route)
}
trait MyService extends HttpService {
implicit def executionContext = actorRefFactory.dispatcher
val route: Route =
path("do") {
post {
detach() {
entity(as[String]) { body =>
complete {
val resp = processRequestAsync(body)
convertToHttpResponseAsync(resp)
}}}}
}
def processRequestAsync(body:String):Future[MyContext]={
// do some non-blocking using async client.api, spray-client..
}
def convertToHttpResponseAsync(resp: Future[MyContext]): Future[HttpResponse] = {
resp.map { ctx =>
// ... Do some non blocking ops
HttpResponse(StatusCodes.OK, entity = HttpEntity(`application/json`, ctx.getData))
}
}
}
在我的本地主机环境中,统计数据看起来很合理(至少#of open connections)我正在使用 ab、wrk 基准,但在生产中我得到了非常不同的画面:
Total requests : 2434475
Open requests : 1847228
Max open requests : 1847228
Total connections : 1995540
Open connections : 142
Max open connections : 1239
Requests timed out : 189196
有一个 ngnix 接收外部请求并将它们发送到应用程序。
问题是这么多开放连接的根本原因是什么?什么参数,标题,我应该注意什么,调查?
我的应用程序从 docker 容器运行