是否可以在分布式环境中将 RMI 与循环负载均衡器一起使用?

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

RMI 是Java 网络编程API 其中使用JRMP protocol。如果我们用 Wireshark 分析数据包,它表明 JRMP 协议在建立客户端和服务器之间的通信之前至少需要 2 次请求交换。

更多细节:第一个请求交换是协商步骤,第二个请求交换是 lookup() 步骤,然后其他请求交换是远程过程调用(当我们使用 class 扩展 Remote)。第一次远程过程调用包含序列化的 class 的属性名称,如果第二次调用相同的方法会有一些优化(每个属性名称将使用 integer id 而不是 String).

不太详细:JRMP 很复杂,因为它需要多次 client/server 请求交换。像 HTTP 这样的协议只需要一个。

考虑到我们在云上工作,我们有多个带有 RMI 服务器的节点,我们在 RMI 客户端和我们的云之间也有一个循环负载平衡器。 RMI客户端发送协商请求,第一个节点收到,然后负载均衡器向第二个节点发送lookup()请求...是否可以在分布式环境中使用RMI?

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

正确,但这只需要在客户端应用程序的生命周期中发生一次,而不是每次远程方法调用都发生。

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

不可能。两个请求都通过相同的 TCP 连接传输,ergo 到达相同的目标主机。

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

不一定。对目标对象的请求可以通过不同的连接,ergo 它们可以包括另一个协商步骤。他们也可以从第一个目标主机转到不同的主机,无论是否存在负载平衡器。

Is it possible to use RMI in a distributed environment?

您必须将您的注册表和所有远程对象复制到所有 load-balanced 主机,如果远程对象具有会话相互依赖性,您可能会遇到很多麻烦。

您最好使用 RMI/IIOP 和 load-balancing ORB。