问题
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