Search code examples
javacloudload-balancingrmiround-robin

Is it possible to use RMI with a round-robin load balancer in a distributed environment?


RMI is a Java network programming API which use the JRMP protocol. If we analyze packets with Wireshark, it shows that the JRMP protocol requires at least 2 request exchanges before establishing a communication between a client and a server.

More detail: The first request exchange is the negotiation step, the second request exchange is the lookup() step, then the other request exchanges are the remote procedure calls (when we use methods from our class which extends Remote). The first remote procedure call contains serialized class's attribute names, if the same method is called a second time there will be some optimisations (an integer id will be used for each attribute name instead of String).

Less detail: JRMP is complex, because it requires multiple client/server request exchanges. A protocol like HTTP only requires one.

Consider we are working on the cloud, we have multiple nodes with RMI servers, we also have a round-robin load balancer between the RMI clients and our cloud. RMI client sends a negotiation request and the first node receives it, then the load balancer send the lookup() request to the second node... Is it possible to use RMI in a distributed environment?


Solution

  • The first request exchange is the negotiation step, the second request exchange is the lookup() step

    Correct, but this only needs to happen once in the life of the client application, not for every remote method call.

    RMI client sends a negotiation request and the first node receives it, then the load balancer send the lookup() request to the second node...

    Not possible. Both requests travel over the same TCP connection, ergo to the same target host.

    then the other request exchanges are the remote procedure calls (when we use methods from our class which extends Remote).

    Not necessarily. The requests to the target object could go via a different connection, ergo they could include another negotiation step. They can also go to a different host from the first target host, regardless of whether or not there is a load balancer present.

    Is it possible to use RMI in a distributed environment?

    You would have to have your Registry and all remote objects replicated to all load-balanced hosts, and if the remote objects have sessional interdepencies you could be in a large spot of bother.

    You might be better off using RMI/IIOP and a load-balancing ORB.