I know a oneway
method is for using asynchronous mode, but is it enough?
Do I need to use TNonblockingSocket (instead of TSocket)?
Do I need to define the server as TNonblockingServer?
First and foremost, the oneway
keyword is used to mark Thrift service methods as "fire and forget".
What happens behind the scenes is that there is only the code for sending the input data is generated by the Thrift Compiler. The receiving part of the client code is entirely omitted for oneway
calls. In other words, the client just sends the request, then moves on without waiting for any response whatsoever (note that this also includes exceptions).
Whether those calls are oneway
or not does not make a difference on the server side in the first run. It primarily affects the client side, because the client does not need to wait any longer for a oneway
call to return once the request has been successfully sent.
How the server end handles that request is entirely up to the server. It can be a TSimpleServer
which only processes one call at a time. Or it can be some other server type, like TNonblockingServer
or TThreadPoolServer
, capable to handle multiple requests in a parallel (or semi-parallel) manner. But that is not so much different from any non-oneway
call. The only real difference is that there is no response sent back to the client.
... but there's of course a caveat.
If the server is not capable to provide the required throughput, it may be still working on the previous request when the next one arrives. At that point the client may indeed block until the next request could be sent.
If your code is of a certain complexity and the server faces frequent requests, you will have to enhance the server to guarantee the throughput you expect. Little's law formalizes this and puts it into a nice formula.