concurrent requests limit of Twitter-Finagle

1k Views Asked by At

I create a thrift server using Finagle like this

val server = Thrift.serveIface(bindAddr(), new MyService[Future] {
  def myRPCFuction() {}
})

But, I found that the maximum number of concurrent requests is five( why 5? when more than 5, the server just ignore the excessed ones.) I look through the doc of Finagle really hard (http://twitter.github.io/finagle/guide/Protocols.html#thrift-and-scrooge), but find nothing hint to configure the max-request-limit. How to config the maximum concurrent request num of Finagle? Thanks

1

There are 1 best solutions below

0
On

I've solved this problem by myself and I share it here to help others who may run into the same case. Because I m a thrift user before and in Thrift when you return from the RPC function you return the values back to calling client. While in Finagle only when you use Future.value() you return the value to client. And when use Finagle, you should totally use the asynchronous way, that's to say you had better not sleep or do some other RPC synchronously in the RPC function.

/*   THIS is  BAD */
val server = Thrift.serveIface(bindAddr(), new MyService[Future] {
  def myRPCFuction() {
      val rpcFuture = rpcClient.callOtherRpc() // call other rpc which return a future
      val result = Await.result(rpcFuture, TwitterDuration(rpcTimeoutSec()*1000, MILLISECONDS))
      Future.value(result)
  }
})
/* This is  GOOD */
val server = Thrift.serveIface(bindAddr(), new MyService[Future] {
  def myRPCFuction() {
      val rpcFuture = rpcClient.callOtherRpc() // call other rpc which return a future
      rpcFuture onSuccess { // do you job when success (you can return to client using Future.value) }
      rpcFuture onFailure { // do your job when fail   }
  }
})

Then, can get a satisfactory concurrency. Hope it helps others who have the same issue.