nova如何讓cpu超配比生效

就個人目前所知,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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章