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 端。 html


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

相关文章
相关标签/搜索