I use Twitter-Finagle create a server. In each RPC function of the server, Just use a Finagle client to call another server's RPC. like this:
def rpc() = {
// finagleClient is created in a std way according to Finagle's Doc:
// val client = Thrift.newIface[Hello.FutureIface]("localhost:8080")
// http://twitter.github.io/finagle/guide/Protocols.html#thrift-and-scrooge
//
val f: Future[xx] = finagleClient.otherRpc()
f onSuccess { // do something }
f onFailure { // handle exception }
}
But, not too long, error happens:
org.jboss.netty.channel.socket.nio.AbstractNioSelector: Failed to accept a connection
java.io.IOException: open too many files
And, I use lsof -p
and find that there are too many connections to another server(about 5000 connections!). I want to know how does it happen? Is there anything I missed.
================ problem solved =============
plz refer to Scala: Why mapValues produces a view and is there any stable alternatives?, Map's mapValue method maybe tricky
val resultIsAView = m.mapValue(mapFunction)
the function mapFunction
will be re-evaluated every time the result view resultIsAView
be used.
Can you confirm that you only create one finagleClient
, and not one for every request you receive? (i.e. Thrift.newIface
should be outside of the rpc
method).
Other potential cause, you may have only one client, but the otherRpc
backend never responds, so your server creates a new connection for every request (because the previous one is still "in use").