Twitter-Finagle的并发请求限制

时间:2015-01-12 06:19:18

标签: scala finagle twitter-finagle

我使用像这样的Finagle创建一个thrift服务器

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

但是,我发现并发请求的最大数量是5(为什么5?当超过5时,服务器只是忽略了过时的请求。)我很难看完Finagle的文档(http://twitter.github.io/finagle/guide/Protocols.html#thrift-and-scrooge) ,但没有找到任何提示配置max-request-limit。 如何配置Finagle的最大并发请求数?谢谢

1 个答案:

答案 0 :(得分:2)

我自己解决了这个问题,并在此分享,以帮助其他可能遇到同样情况的人。因为当你从RPC函数返回时我是Thrift之前和之后的thrift用户,你将值返回给调用客户端。只有在使用Future.value()时才在Finagle中将值返回给客户端。当使用Finagle时,你应该完全使用异步方式,也就是说你最好不要在RPC函数中睡眠或同步执行其他RPC。

/*   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   }
  }
})

然后,可以获得满意的并发性。希望它可以帮助那些有同样问题的人。