Oh, I see what you're trying to do. Well there is not currently an async API on the server side so that the result could be passed back to Netty asynchronously. However, one thing you could do is use a cached thread pool or similar when you create the Netty server so that there will always be a thread available, and then the Responder could just block until services B, C, and D have returned. If you want to do it this way, use the NettyServer constructor that takes an ExecutionHandler:
http://avro.apache.org/docs/current/api/java/org/apache/avro/ipc/NettyServer.html#NettyServer The ExecutionHandler should use an Executor that will create new threads as needed (e.g. Executors.newCachedThreadPool()) so that there will always be a thread available to handle an incoming RPC. From a performance perspective this shouldn't be a big problem because threads are fairly lightweight, especially if they're just sitting there waiting for async responses to come back. Of course if this is a high throughput service you'll always have the possibility that requests will be arriving faster than the server can respond, which would lead to resources building up and OOME in the worst case. In that case even an async interface on the server side wouldn't help because some state will always have to be stored on a per-RPC basis. In the future we may be able to support the async interface on the server side as well. For example, if the SpecificResponder implements the inner Callback interface we could have the Callback.handleResult(T) send the result back when invoked. -James On Sun, Feb 26, 2012 at 8:02 PM, Peter S <[email protected]> wrote: > Hi James, > > Thanks for the quick reply. > I get how the client side callback works. My question was actually > concerning the server side. > > Suppose I have a service A which is implemented as an asynchronous server > using netty. Service A depends on B, C, D which are also avro service. In > order not to block the thread in service A, service A need to call B,C,D > asynchronously. But this needs Avro to support this when implementing > service A. For example, after calling B, C, D and gathering all results, > the handler in service A could call a callback (e.g. > callback.done(response)) to notify the underline transportation to send the > response to the client of A. > > Can Avro support this RPC chain in an asynchronous way? > > Regards, > Peter > > > On Sun, Feb 26, 2012 at 4:40 PM, James Baldassari > <[email protected]>wrote: > >> Hi Peter, >> >> Yes, there is support in Avro for asynchronous RPCs, but it's currently >> limited to Java and the Netty client/server implementation. This was >> implemented in AVRO-539 and first released in Avro 1.5.2. >> >> Asynchronous RPCs are implemented using the Callback interface. When >> Avro generates the Java interface for your protocol in v1.5.2 or later >> you'll see a sub-interface called Callback. For example, if your protocol >> is called Mail, you'll have a Java interface called Mail and a >> sub-interface Mail.Callback which extends Mail and adds the >> callback-enabled RPCs. This is the interface you should use on the client >> side (when you create a SpecificRequestor). On the server side, nothing >> changes to enable asynchronous RPCs. The server (SpecificResponder) will >> implement Mail. >> >> I would suggest taking a look at some examples to get started. A good >> place to start would be the Avro unit tests for the Callback APIs: >> >> >> http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServerWithCallbacks.java?view=markup >> >> I also created a github project to demonstrate a real-world use case for >> async RPCs using a real-time online auction: >> >> https://github.com/jbaldassari/Avro-RPC >> >> Also see this recent Avro users thread which has some pointers about >> callbacks: >> >> http://search-hadoop.com/m/HDNLxeVRbO >> >> Hopefully that will get you started, but please write back if you have >> any problems getting it working. >> >> -James >> >> >> >> On Sun, Feb 26, 2012 at 6:24 PM, Peter S <[email protected]> wrote: >> >>> Hi all, >>> >>> I am new to avro. I am trying to writing an asynchronous server which >>> will make other RPC calls. So I am wondering how can I do this. I found a >>> related jira issue: >>> https://issues.apache.org/jira/browse/AVRO-405 >>> >>> But it seems only #1 is solved. Does Avro support #2 in this ticket now? >>> Thanks! >>> >>> Regards, >>> Peter >>> >> >> >
