标签:nova
就个人目前所知,L版有3种方式配置cpu的超配比。当然有什么错误之处,还请见谅!
a、AggregateCoreFilter的cpu_allocation_ratio metadata key
使用:nova aggregate-set-metadata 1 cpu_allocation_ratio=2.0
b、compute node的配置文件nova.conf支持cpu_allocation_ratio参数设置
c、原本的controller node nova.conf的cpu_allocation_ratio参数设置
优先级:a > b > c
为什么是这样的优先级呢,下面看代码:
class AggregateCoreFilter(BaseCoreFilter): """AggregateCoreFilter with per-aggregate CPU subscription flag. Fall back to global cpu_allocation_ratio if no per-aggregate setting found. """ def _get_cpu_allocation_ratio(self, host_state, filter_properties): import pdb;pdb.set_trace() aggregate_vals = utils.aggregate_values_from_key( host_state, ‘cpu_allocation_ratio‘) try: ratio = utils.validate_num_values( aggregate_vals, host_state.cpu_allocation_ratio, cast_to=float) # host_state是从nova数据库中compute_node表来的 except ValueError as e: LOG.warning(_LW("Could not decode cpu_allocation_ratio: ‘%s‘"), e) ratio = host_state.cpu_allocation_ratio return ratio # 如果没设置Aggregation主机聚合的cpu_allocation_ratio metadata key,返回空set def aggregate_values_from_key(host_state, key_name): """Returns a set of values based on a metadata key for a specific host.""" aggrlist = host_state.aggregates return {aggr.metadata[key_name] for aggr in aggrlist if key_name in aggr.metadata } def validate_num_values(vals, default=None, cast_to=int, based_on=min): """Returns a correctly casted value based on a set of values. This method is useful to work with per-aggregate filters, It takes a set of values then return the ‘based_on‘{min/max} converted to ‘cast_to‘ of the set or the default value. Note: The cast implies a possible ValueError """ num_values = len(vals) # 如果没设置Aggregation主机聚合的cpu_allocation_ratio metadata key if num_values == 0: return default # 还是调用host_state.cpu_allocation_ratio if num_values > 1: LOG.info(_LI("%(num_values)d values found, " "of which the minimum value will be used."), {‘num_values‘: num_values}) return based_on([cast_to(val) for val in vals]) # 如果Aggregation主机聚合设置了多个cpu_allocation_ratio metadata key,默认取最小的
这里还有个疑问,host_state中的cpu_allocation_ratio是如何更新的呢?
看个compute node支持独立设置cpu_allocation_ratio的bp
Add cpu_allocation_ratio and ram_allocation_ratio to ComputeNode: https://review.openstack.org/#/c/215471/9
Update ComputeNode values with allocation ratios in the RT:https://review.openstack.org/#/c/216362/ (compute端的,通过resource_tracker定时任务实现)
resource_tracker.py又是什么?
它的作用就是Keep the ComputeNode model updated with usage,也是compute节点的一个定时任务。bp实现:https://review.openstack.org/#/c/9402/
Add cpu_allocation_ratio and ram_allocation_ratio to ComputeNode bp实现中的 nova/objects/compute_node.py(重点部分)
@staticmethod def _from_db_object(context, compute, db_compute): special_cases = set([ ‘stats‘, ‘supported_hv_specs‘, ‘host‘, ‘pci_device_pools‘, ]) fields = set(compute.fields) - special_cases for key in fields: value = db_compute[key] # NOTE(sbauza): Since all compute nodes don‘t possibly run the # latest RT code updating allocation ratios, we need to provide # a backwards compatible way of hydrating them. # As we want to care about our operators and since we don‘t want to # ask them to change their configuration files before upgrading, we # prefer to hardcode the default values for the ratios here until # the next release (Mitaka) where the opt default values will be # restored for both cpu (16.0) and ram (1.5) allocation ratios. # TODO(sbauza): Remove that in the next major version bump where # we break compatibilility with old Kilo computes if key == ‘cpu_allocation_ratio‘ or key == ‘ram_allocation_ratio‘: if value == 0.0: # Operator has not yet provided a new value for that ratio # on the compute node value = None if value is None: # ResourceTracker is not updating the value (old node) # or the compute node is updated but the default value has # not been changed value = getattr(CONF, key) # 如果是0.0,cpu_allocation_ratio将会controller节点的cpu_allocation_ratio为准 if value == 0.0 and key == ‘cpu_allocation_ratio‘: # It‘s not specified either on the controller value = 16.0 if value == 0.0 and key == ‘ram_allocation_ratio‘: # It‘s not specified either on the controller value = 1.5 compute[key] = value
nova-compute Periodic tasks 机制 http://blog.csdn.net/gj19890923/article/details/50583435
Nova object 模型介绍 http://blog.csdn.net/tan198707/article/details/16994363
本文出自 “the-way-to-cloud” 博客,请务必保留此出处http://iceyao.blog.51cto.com/9426658/1832218
标签:nova
原文地址:http://iceyao.blog.51cto.com/9426658/1832218