【问题标题】:concurrent requests limit of Twitter-FinagleTwitter-Finagle 的并发请求数限制
【发布时间】:2015-03-09 21:17:03
【问题描述】:

我像这样使用 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),但是找不到任何提示来配置最大请求限制。 如何配置 Finagle 的最大并发请求数?谢谢

【问题讨论】:

  • 您是如何发现限制为 5 的?

标签: scala finagle twitter-finagle


【解决方案1】:

我自己解决了这个问题,我在这里分享它以帮助可能遇到相同情况的其他人。因为我在 Thrift 之前和在 Thrift 中都是一个 thrift 用户,所以当您从 RPC 函数返回时,您会将值返回给调用客户端。在 Finagle 中,只有当您使用 Future.value() 时,您才会将值返回给客户端。而在使用Finagle的时候,你应该完全使用异步的方式,也就是说你最好不要在RPC函数中sleep或者同步做一些其他的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   }
  }
})

然后,可以得到满意的并发。希望对遇到同样问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    相关资源
    最近更新 更多