【问题标题】:concurrent requests limit of Twitter-FinagleTwitter-Finagle 的并发请求数限制
【发布时间】:2015-03-09 21:17:03
【问题描述】:
【问题讨论】:
标签:
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 }
}
})
然后,可以得到满意的并发。希望对遇到同样问题的人有所帮助。