0

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?

user207421
  • 305,947
  • 44
  • 307
  • 483
gokan
  • 1,028
  • 1
  • 14
  • 30
  • 2
    Theoretically, but is there a good reason in a situation like this not to use an HTTP or messaging interface? – chrylis -cautiouslyoptimistic- Feb 10 '17 at 03:19
  • Hi, yes there's a good reason: If we want to use a synchronous Service Oriented Architecture (SOA) implementation which is built on binary protocol (and not a plain text protocol like HTTP which cost more CPU for complex datas). – gokan Feb 10 '17 at 09:11
  • CPU time for serialization/deserialization is trivially cheap these days. The ease of debugging alone is worth the overhead. – chrylis -cautiouslyoptimistic- Feb 10 '17 at 12:51
  • What is this 'negotiation request' you mention? – user207421 Feb 10 '17 at 20:50
  • It's the first request exchange between the RMI client and server. If you read the packets, the client sends a request with the following magic bytes : 0x4a 0x52 0x4d 0x49 (it never changes), then the server responds with an ACK 0x4e message. – gokan Feb 11 '17 at 17:38
  • That's the RMI version protocol, which is sent once per connection. In any case the `lookup()` must be sent over the same connection, and therefore to the same host. The method call may go via a different connection, as the remote object may be listening on a different port. You would have to have your Registry and all remote objects replicated to all hosts in the round robin. You might be better off using RMI/IIOP and a load-balancing ORB – user207421 Feb 12 '17 at 04:36

1 Answers1

1

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.

user207421
  • 305,947
  • 44
  • 307
  • 483