扩展规则
扩展服务
Cloudify支持两种方式来扩展服务 :
自动扩展
Cloudify使每个服务定义一个扩展规则来决定是否服务需要扩展或缩小,例如使用一个基于忙线程的平均数量的规则,cloudify来决定增加还是缩小tomcat的服务实例数:
扩展规则流程
扩展规则的元素
基于统计指标,在配方中定义扩展规则的上、下阈值和从应用程序的服务插件收集来,每个规则涉及到一个集群的一个或多个服务实例。
测量指标:
统计数据 :
因此使用所收集的度量来判读统计指标。当一个统计指标高于阈值上限时,cloudify增加服务实例数,相反地,当指标低于阈值下限时,cloudify减少服务实例数。
例如如果有一个服务有3个实例,每个实例的CPU使用量分别为30%, 20% 和90%,如果规则定义一个对CPU使用量的上限为80%,[Max(30, 20, 90) == 90]则cloudify会启动另一个服务实例。
扩展规则的语法
如果最少一个tomcat实例大于每秒一个请求,则增加一个tomcat实例的配方片段,相反,如果tomcat集群(所有的tomcat实例)小于每秒0.2个请求数,则移除一个tomcat实例。
service { name "tomcat" ...
/* A global flag that enables changing the number of instances for this service */ elastic true // the initial number of instances numInstances 1 /* The minimum number of service instances. Used together with scaling rules */ minAllowedInstances 1 /* The maximum number of service instances. Used together with scaling rules */ maxAllowedInstances 2 /* The time (in seconds) that scaling rules are disabled after scale in (instances removed) or scale out (instances added). This has the same effect as setting scaleInCooldownInSeconds and scaleOutCooldownInSeconds separately. Used together with scaling rules. This attribute should be greater than or equal to the movingTimeRangeInSeconds attribute in the serviceStatistics section. */ scaleCooldownInSeconds 20 /* The time (in seconds) between two consecutive metric samples. Used together with scaling rules */ samplingPeriodInSeconds 1 // Defines an automatic scaling rule based on "counter" metric value scalingRules ([ scalingRule { serviceStatistics { /* The name of the metric that is the basis for the scale rule decision In the current example, the metric we use is "Total Requests Count". */ metric "Total Requests Count" /* (Optional) The sliding time range (in seconds) for aggregating per-instance metric samples. The number of samples in the time windows equals the time window divided by the sampling period. Default value: 300 */ movingTimeRangeInSeconds 20 /* (Optional) The algorithms for aggregating metric samples by instances and by time. Metric samples are aggregated separately per instance in the specified time range,and then aggregated again for all instances. Default value: Statistics.averageOfAverages Possible values: Statistics.maximumOfAverages, Statistics.minimumOfAverages, Statistics.averageOfAverages, Statistics.percentileOfAverages(90), Statistics.maximumOfMaximums, Statistics.minimumOfMinimums, Statistics.maximumThroughput. The following has the same effect as setting instancesStatistics and timeStatistics separately. For example: statistics Statistics.maximumOfAverages is the same as: timeStatistics Statistics.average instancesStatistics Statistics.maximum */ statistics Statistics.maximumThroughput } highThreshold { /* The value above which the number of instances is increased */ value 1 /* The number of instances to increase when above threshold */ instancesIncrease 1 } lowThreshold { /* The value below which the number of instances is decreased */ value 0.2
/* The number of instances to decrease when below threshold */ instancesDecrease 1 } } ]) plugins([ plugin { name "jmx" className "org.cloudifysource.usm.jmx.JmxMonitor" config([ "Total Requests Count": [ "Catalina:type=GlobalRequestProcessor,name=\"http-bio-8080\"", "requestCount" ], port: "11099" ]) } ]) } |
当前版本每个服务只需描述一个扩展规则
手动扩展
Cloudify还使你能够手动设置服务实例数。
手动设置服务实例数:在cloudify shell下执行 set-instances service-name number-of-required-instances
number-of-required-instances必须:
为了启用手动扩展规则,你必须在服务描述文件中将elastic属性设置为true
下面的例子是通过命令来调整tomcat服务实例的数量: set-instances tomcat 3
如果调用命令前tomcat服务有2个实例,它将增加tomcat服务实例的数量到3个。相反地,如果前面命令前tomcat服务有5个实例,它将减少tomcat服务实例到3个
service { name "tomcat" ...
/* A global flag that enables changing the number of instances for this service */ elastic true // the initial number of instances numInstances 1 /* The minimum number of service instances. */ minAllowedInstances 1 /* The maximum number of service instances. */ maxAllowedInstances 8 } |