EJAPP Top 10 countdown: #2 - Unnecessary remoting

Vincent Partington

Picking up the pace to make sure I get the countdown finished before I go to JavaOne ;-), I'll quickly move on to #2 of the EJAPP Top 10 countdown....

While remoting is often used in Enterprise Java applications due to the fact that other systems and applications need to be invoked, unnecessary remoting is an important cause of badly performing Enterprise Java applications.

Therefore this issue can manifest itself in a number of different ways:

  • Invoking a EJB remotely when a local call is available (also a case of incorrect usage of Java EE).
  • Invoking an external application when the functionality is available within Java itself. The code below was discovered in an production source code:
    Runtime.getRuntime().exec("d:\\path\\to\\bin\\sleep.exe " + nbSecond);

    The same functionality could have been gotten with a simple:

    Thread.sleep(nbSecond * 1000);
  • Using SOAP when RMI would suffice. SOAP invocations are typically 10 to 20 times slower than the equivalent RMI invocation, depending upon the SOAP framework used, the network speed, and the time taken on the server by the invoked method itself. See Comparison of performance of web services, WS-security, RMI, and RMI-SSL by Juric, Rozman, Brumen, Colnaric, and Hericko for a scientific case study. In any case, using SOAP can be a case of unnecessary use of XML, which in turn causes excessive memory usage.
  • Invoking a lot of small method calls (fine grained) instead of one large method call (coarse grained), thereby incurring the remote method invocation overhead multiple times. The Transfer Object pattern was invented to solve this problem in JavaEE where it was especially prevalent in EJB 1.x entity beans.

In some cases an architecture is designed with remoting built-in for some anticipated future need that never occurs. For example, a colleague of mine has encountered an application split into two projects: a services layer (providing access to a mainframe) designed for multiple front-ends that could be accessed through a SOAP interface and a web interface invoking the services layer. In the end no other front-ends were built and the whole system was deployed within one application server cluster. The benefits of remoting were not used, but the performance hit was still there. A typical case of YAGNI!

The same thing can be seen in previous version of J2EE; EJB 1.x had only remote beans because that would allow clustering to improve availability and performance, even though that was not always needed. Similarly I can't really get excited about WSRP; I shudder to think about the performance of a portal (not one of my favorite technologies in any case) that invokes it portlets over a SOAP interface.

Anyway, sometimes you just have to deal with remoting. In that case, these tips may help you mitigate the damage:

  • First of all, make sure you really need remoting.
  • Choose your remoting technology wisely. Don't use SOAP because all the cool kids are doing it. ;-) Consider alternatives like Hessian (an efficient binary protocol), Burlap (a XML version of Hessian), Spring's HTTP Invokers (a Java-only binary protocol), or RMI. Write a benchmark for your situation to help you decide.
  • Avoid invoking fine grained methods remotely. Use the Facade pattern to cluster them together to form coarsed grained methods.
  • If remoting is needed for only a part of your use cases, consider exposing your business functionality using different technologies. For example, the Spring framework allows functionality to be invoked by a Java method call while that same functionality is also exposed as a service by an Exporter.

Remoting has its uses and its advantages, just be aware of its implications for the performance of your application!

Comments (4)

  1. Juergen - Reply

    May 2, 2007 at 9:52 am

    A viable alternative besides RMI for a fast remoting protocol is CORBA. Contrary to all rumors you heard, CORBA has a very fast and efficient network protocol and really is not hard to implement:

    http://java.sun.com/j2se/1.4.2/docs/guide/idl/GShome.html

  2. [...] #02 - Utilisation abusive de la distribution [...]

  3. Rejeev - Reply

    May 25, 2007 at 5:10 am

    Most of the popular Application Servers (Pramati Application Server and Weblogic I know) optimizes the remote calls if the stub and skelton are part of the same application (part of same EAR)

  4. Xebia Blog - Reply

    August 17, 2007 at 10:15 am

    [...] Discussed are numbers 2-Unnecessary remoting. More information about number 2 can be found here. and for number 1-Incorrect database usage see; here. [...]

Add a Comment