How to handle requests using different thread pools in Thrift?

落花浮王杯 提交于 2019-12-11 09:06:47

问题


I have a thrift service that has two methods
1. Response processSync(Request req) : This method synchronously processes requests and returns a response. The client thread gets blocked until the request is completely processed by the server.
2. void processAsync(Request req) : This method is for asynchronous processing. Here as soon as the server completely receives the request, the call returns with no output. Client thread does not wait until the request is processed by the server.

While using ThreadedSelectorServer that has separate threads for reading/writing and processing of threads. The requirement is to use separate thread pools at the method level. This is because it might happen that the all the processing threads get busy with synchronous requests. Clients using the asynchronous api might timeout. I wish to give both api's equal weightage so that if the server is flooded with sync requests; the async requests do not suffer.

Thought of having two different services, one with only sync method and another one with async. But in that case two thrift servers have to be started which shall require two different ports.I wish to avoid doing that.

Any suggestions how this can be achieved ?


回答1:


Yes, use the multiplex protocol introduced with Thrift 0.9.1. It allows having multiple services sharing the same transport. Note that both server and client must use the multiplex protocol layer to succeed.

By the way, consider making the async method a oneway:

Service whatever {
  oneway void processAsync(1: Request req) 
}


来源:https://stackoverflow.com/questions/18911972/how-to-handle-requests-using-different-thread-pools-in-thrift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!