Load Balancing

Replication 是IceGrid 一个重要的功能,结合 load balancing ,replication 变得更实用。

IceGrid 节点定期向registry报告所在主机的系统负载。在处理定位请求时,复制组的配置决定了registry 是否考虑系统负载信息。它的配置也指定了多少个replicas 包含在registry 的响应中。

IceGrid load balancing 帮助client 获取一组初始端点的目的是建立一个连接。一旦client 建立了一个连接,所有代理的后续请求发起的连接通常发送到同一个server,而不需重新向registry 查询。因此 registry 对定位请求的响应只能看做是某一时刻的快照副本。如果系统负载对client 非常重要,它必须定期的联系registry 并且更新它的端点。

Replica Group Load Balancing

一个复制组的描述符可以选择的配置 load balancing的描述符,来定义系统负载如何被定位请求使用。load balancing 描述符指定了下列信息:

1. Type
一些被支持的 负载类型 见: load balancing types、

2. Sampling interval
一 个 load balancing 类型确定的系统负载的统计数据,被每个node 定期汇报。复制组可以指定一个采样间隔,5 或者 15 分钟。选择采样间隔需要考虑 获取最新负载信息对 期望降低瞬态峰值 这两点间的平衡 。 在Unix 平台,node 报告所选择的采样间隔的系统负载平均值,在Windows 平台报告CPU 利用率的采样间隔的平均值。

3. Number of replicas
复制组能指示 registry 返回 endpoint 的一个 还是多个 Object adapter(默认是一个),如果指定了数量 N 比1大的数,proxy 返回至少 N 个object adapters. 如果 N 等于 0 ,proxy 返回所有 object adapters 。 Ice 运行时 client 随机选择一个 。

例如,下面展示的使用 adaptive 类型的load balancing 返回 endpoints 的最少2个 object adapters,使用5分钟采样间隔:

XML
<replica-groupid="ReplicatedAdapter">
<load-balancingtype="adaptive"load-sample="5"n-replicas="2"/>
</replica-group>


type 属性必须指定,其他选项可选。

Load Balancing Types

一个复制组可以选择下列的一种类型:
1. Random
Random 负载均衡 随机选择object adapters 。 registry 不会考虑系统负载。
2.Adaptive
Adaptive 负载均衡使用系统负载信息来选择。这是唯一使用 采样间隔属性的一个类型。
3.Round Robin
Round robin 负载均衡返回 最近最少使用的object adapters. registry 不考虑系统负载。请注意,round-robin 信息不会在 registry 的负载中共享;每个registry 的副本维护他们自己的最近最少使用的 object adapters。
4.Ordered
Ordered 负载均衡 使用优先级选择。复制组的object adapter 可以设置他们自己的优先级。如果你设置了多个adapter 使用同一个优先级,IceGrid 将会按照他们在描述符出现的顺序来确定。

选择合适的负载均衡的类型是高度依赖客户端应用的需求的。要实现负载均衡和故障切换同样需要客户端的协同合作。因此到现在,你理解Ice 运行时使用定位器来解决间接代理是非常重要的。


Using Load Balancing in the Ripper Application

我们唯一需要改变的就是添加 load balancing 的描述符:
XML
<icegrid>
<applicationname="Ripper">
<replica-groupid="EncoderAdapters">
<load-balancingtype="adaptive"/>
<objectidentity="EncoderFactory"type="::Ripper::MP3EncoderFactory"/>
</replica-group>
<server-templateid="EncoderServerTemplate">
<parametername="index"/>
<parametername="exepath"default="/opt/ripper/bin/server"/>
<serverid="EncoderServer${index}"exe="${exepath}"activation="on-demand">
<adaptername="EncoderAdapter"replica-group="EncoderAdapters"
endpoints="tcp"/>
</server>
</server-template>
<nodename="Node1">
<server-instancetemplate="EncoderServerTemplate"index="1"/>
</node>
<nodename="Node2">
<server-instancetemplate="EncoderServerTemplate"index="2"/>
</node>
</application>
</icegrid>

使用 adaptive 的负载均衡,我们已经解决了 介绍 replica groups 时候所丧失的能力。我们现在选择最少负载的 adapter,不需要改变client 端。


http://note.youdao.com/share/web/file.html?id=9056da95153eea832334a8a64940550b&type=note

你可能感兴趣的:(Load Balancing)