1.设置ice_connectionCached为false

service = (xxxServicePrx) service.ice_connectionCached(false);

和每一个服务端的endpoint建立tcp连接,客户端自己做负载均衡

通过netstat -nalp |grep port 检查

2.配置文件后台定时更新endpoints列表

Ice.BackgroundLocatorCacheUpdates=1
Ice.Default.LocatorCacheTimeout=5

BackgroundLocatorCacheUpdates 后台线程更新endpoint列表
LocatorCacheTimeout 5秒定时更新

3.连接缓存,感觉官网说的和负载均衡不清晰

https://doc.zeroc.com/ice/3.7/client-server-features/connection-management/connection-establishment#id-.ConnectionEstablishmentv3.7-cache

Connection Caching
When we refer to a proxy's connection, we actually mean the connection that the proxy is currently using. This connection can change over time, such that a proxy might use several connections during its lifetime. For example, an idle connection may be closed automatically and then transparently replaced by a new connection when activity resumes.

After establishing a connection in response to proxy activities, the Ice run time adds the connection to an internal pool for subsequent reuse by other proxies. The Ice run time manages the lifetime of the connection and eventually closes it. The connection is not affected by the life cycle of the proxies that use it, except that the lack of activity may prompt the Ice run time to close the connection after a while.

Once a proxy has been associated with a connection, the proxy's default behavior is to continue using that connection for all subsequent requests. In effect, the proxy caches the connection and attempts to use it for as long as possible in order to minimize the overhead of creating new connections. If the connection is later closed and the proxy is used again, the proxy repeats the connection-establishment procedure described earlier.

There are situations in which this default caching behavior is undesirable, such as when a client has a proxy with multiple endpoints and wishes to balance the load among the servers at those endpoints. The client can disable connection caching by passing an argument of false to the proxy factory method ice_connectionCached. The new proxy returned by this method repeats the connection-establishment procedure before each request, thereby achieving request load balancing at the expense of potentially higher latency. This type of load balancing is performed solely by the client using whatever endpoints are contained in the proxy. More sophisticated forms of load balancing are also possible, such as when using IceGrid.

Enabling or disabling connection caching on a proxy has two separate effects:

when caching is enabled, the proxy remembers ("caches") a connection until the connection is closed, while when caching is disabled, the proxy does not remember the connection it previously used.
when caching is enabled, Ice provides to this proxy an already established connection if possible; when caching is disabled, Ice does not prefer endpoints with established connections over other endpoints when providing a connection to this proxy.


连接缓存
当我们提到代理的连接时,实际上是指代理当前正在使用的连接。该连接可以随着时间而变化,以使代理在其生命周期内可能使用多个连接。例如,空闲连接可以自动关闭,然后在活动恢复时透明地由新连接替换。

在响应代理活动建立连接之后,Ice运行时会将连接添加到内部池中,以供其他代理随后重用。Ice运行时间管理连接的生存期,并最终将其关闭。该连接不受使用该代理的生命周期的影响,除了缺少活动可能会促使Ice运行时间过一会儿再关闭该连接。

将代理与连接关联后,该代理的默认行为是继续对所有后续请求使用该连接。实际上,代理会缓存连接并尝试尽可能长时间地使用它,以最大程度地减少创建新连接的开销。如果以后关闭连接并再次使用代理,则代理将重复前面描述的连接建立过程。

在某些情况下,这种默认的缓存行为是不希望有的,例如,当客户端具有多个端点的代理并且希望在这些端点的服务器之间平衡负载时。客户端可以通过将参数传递false给代理工厂方法 来禁用连接缓存ice_connectionCached。通过此方法返回的新代理在每个请求之前重复连接建立过程,从而以可能更高的延迟为代价实现请求负载平衡。此类负载平衡仅由客户端使用代理中包含的任何端点来执行。也可以使用更复杂的负载平衡形式,例如在使用 IceGrid时。

在代理上启用或禁用连接缓存有两个不同的效果:

启用缓存后,代理会记住(“缓存”)连接,直到关闭连接为止;而禁用缓存时,代理将不会记住以前使用的连接。
启用缓存后,Ice会向该代理提供一个已建立的连接(如果可能);如果禁用了缓存,则在提供到此代理的连接时,Ice不会比其他端点更喜欢具有已建立连接的端点。