我正在尝试向akka-http发送200k消息。
protected val someRouts: Route = pathPrefix("foo") {
pathEndOrSingleSlash {
put {
entity(as[Foo]) { foo =>
log.debug(s"/foo update $foo")
complete(Future(Foo("a")).map(f => s"Got - $f "))
}
}
}
Http().bindAndHandle(someRouts, "0.0.0.0", 9000)
来自不同的进程我发送循环200K消息。 客户代码(简化):
lazy val apiFlow: Flow[HttpRequest, HttpResponse, Any] =
Http().outgoingConnection("0.0.0.0", 9000)
def request(request: HttpRequest): Future[HttpResponse] = Source.single(request).via(apiConnectionFlow).runWith(Sink.head)
for (i <- 1 to 200000){
request(RequestBuilding.Put("/foo", Foo(i))
}
过了一会儿,我得到了这个例外:
[akka.actor.default-dispatcher-33] ERROR akka.io.TcpListener - Accept error: could not accept new connection
java.io.IOException: Too many open files in system
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
at akka.io.TcpListener.acceptAllPending(TcpListener.scala:112)
at akka.io.TcpListener$$anonfun$bound$1.applyOrElse(TcpListener.scala:85)
at akka.actor.Actor$class.aroundReceive(Actor.scala:502)
at akka.io.TcpListener.aroundReceive(TcpListener.scala:34)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
at akka.actor.ActorCell.invoke(ActorCell.scala:495)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
UPDATE
使用lsof -i tcp:9000 | wc -l
检查打开的连接我可以看到该数字显着超过6500
答案 0 :(得分:1)
您的问题是您尝试打开到0.0.0.0:9000
的200,000个TCP连接,并且您正在使用的计算机未配置为允许一次激活那么多文件描述符。
来自the docs(强调我的):
请注意,在返回的流实际实现之前,不会尝试连接! 如果流程已实现多次,则将打开几个独立的连接(每个实现一个)。
检查ulimit -n
- 它可能远低于200K。
另见: