我使用Finagle创建了一个节俭服务器,如下所示
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的最大并发请求数?谢谢
发布于 2015-01-13 17:57:39
我自己解决了这个问题,我在这里分享它,以帮助其他可能遇到同样情况的人。因为我以前是thrift用户,所以在Thrift中,当您从RPC函数返回时,将值返回给调用client。而在Finagle中,只有当您使用Future.value()时,才会将值返回给client。当使用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 }
}
})然后,可以获得令人满意的并发性。希望对其他有同样问题的人有所帮助。
https://stackoverflow.com/questions/27896356
复制相似问题