代码调用流程:

1. nova.scheduler.client.query.SchedulerQueryClient#select_destinations
2. nova.scheduler.rpcapi.SchedulerAPI#select_destinations
3. nova.scheduler.manager.SchedulerManager#select_destinations
4. nova.scheduler.filter_scheduler.FilterScheduler#select_destinations

scheduler的rpcapi和manager属于同步调用。

在第三步中scheduler会调用placement提供的API,对所有的`compute node`进行初步的筛选,placement的API会返回一个字典,格式如下:

{
"provider_summaries": {
"4cae2ef8-30eb-4571-80c3-3289e86bd65c": {
"resources": {
"VCPU": {
"used": 2,
"capacity": 64
},
"MEMORY_MB": {
"used": 1024,
"capacity": 11374
},
"DISK_GB": {
"used": 2,
"capacity": 49
}
}
}
},
"allocation_requests": [
{
"allocations": [
{
"resource_provider": {
"uuid": "4cae2ef8-30eb-4571-80c3-3289e86bd65c"
},
"resources": {
"VCPU": 1,
"MEMORY_MB": 512,
"DISK_GB": 1
}
}
]
}
]
}

对于placement API筛选出的节点,scheduler会再度进行筛选,大概的筛选过程:all hosts => filtering => weighting => random
1. get all hosts:这里的all host当然不是指环境中所有的host,而是在通过placement API,返回的所有host的详细信息;
2. filtering:首先过滤ignore host和force host,如果force host或者force node直接返回即可。然后结合nova的配置文件中available_filters和enabled_filters参数,依次执行所有的filter。下面我们举几个filter的例子,执行filter的入口:

nova.filters.BaseFilterHandler#get_filtered_objects

    def get_filtered_objects(self, filters, objs, spec_obj, index=0):
list_objs = list(objs)
LOG.debug("Starting with %d host(s)", len(list_objs))
part_filter_results = []
full_filter_results = []
log_msg = "%(cls_name)s: (start: %(start)s, end: %(end)s)"
# 循环遍历配置文件中指定的filters
for filter_ in filters:
if filter_.run_filter_for_index(index):
cls_name = filter_.__class__.__name__
# 记录开始该执行filter之前的host的个数
start_count = len(list_objs)
# 对所有的host执行该filter,返回只有经过该filter的host
objs = filter_.filter_all(list_objs, spec_obj)
if objs is None:
LOG.debug("Filter %s says to stop filtering", cls_name)
return
list_objs = list(objs)
end_count = len(list_objs)
part_filter_results.append(log_msg % {"cls_name": cls_name,
"start": start_count, "end": end_count})
if list_objs:
remaining = [(getattr(obj, "host", obj),
getattr(obj, "nodename", ""))
for obj in list_objs]
full_filter_results.append((cls_name, remaining))
else:
LOG.info(_LI("Filter %s returned 0 hosts"), cls_name)
full_filter_results.append((cls_name, None))
break
LOG.debug("Filter %(cls_name)s returned "
"%(obj_len)d host(s)",
{'cls_name': cls_name, 'obj_len': len(list_objs)})
# 下边是一些日志中打印一些详细信息,不在赘述
…………
return list_objs

接下来介绍几个filter。

class AvailabilityZoneFilter(filters.BaseHostFilter):

    # 如果是一次创建多个虚机,则AvailabilityZoneFilter指执行一次
run_filter_once_per_request = True
# 所有的filter都需要实现该方法
def host_passes(self, host_state, spec_obj):
# 获取request_spec中指定的availability_zone,这里需要强调一下,如果创建时,没有指定--availability-zone 参数,request_sepc中的availability_zone就是空的。
availability_zone = spec_obj.availability_zone
# 如果request_spec中availability_zone值为空,那么也就是这个操作是允许跨AZ操作的。
if not availability_zone:
return True
# 获取host的availability_zone信息,首先获取该host所属的aggregate信息,aggregate信息中有availability_zone相关的信息
metadata = utils.aggregate_metadata_get_by_host(
host_state, key='availability_zone') if 'availability_zone' in metadata:
# 判断request_spec中指定的availability_zone是否在该host所属的availability_zone中。
hosts_passes = availability_zone in metadata['availability_zone']
host_az = metadata['availability_zone']
else:
hosts_passes = availability_zone == CONF.default_availability_zone
host_az = CONF.default_availability_zone if not hosts_passes:
LOG.debug("Availability Zone '%(az)s' requested. "
"%(host_state)s has AZs: %(host_az)s",
{'host_state': host_state,
'az': availability_zone,
'host_az': host_az}) return hosts_passes
nova.scheduler.filters.image_props_filter.ImagePropertiesFilter#host_passes

    # 主要是根据镜像中的property的值进行过滤,在ironic的调度中会使用到。
def host_passes(self, host_state, spec_obj):
image_props = spec_obj.image.properties if spec_obj.image else {}
# 判断该compute_node是否支持image的property属性中指定的参数值。
if not self._instance_supported(host_state, image_props,
host_state.hypervisor_version):
LOG.debug("%(host_state)s does not support requested "
"instance_properties", {'host_state': host_state})
return False
return True def _instance_supported(self, host_state, image_props,
hypervisor_version):
img_arch = image_props.get('hw_architecture') # 架构,i686或x86_64
img_h_type = image_props.get('img_hv_type') # hypervisor 类型
img_vm_mode = image_props.get('hw_vm_mode') # 虚拟化类型
…………
# 获取该compute_node支持的instance类型,返回值为列表。比如:
[["x86_64", "baremetal", "hvm"]]
[["i686", "qemu", "hvm"], ["i686", "kvm", "hvm"], ["x86_64", "qemu", "hvm"], ["x86_64", "kvm", "hvm"]]
supp_instances = host_state.supported_instances
…………
比较规则
def _compare_props(props, other_props):
# 对image的property指定的所有值进行遍历
for i in props:
查看该property是否是该compute_node支持的
if i and i not in other_props:
return False
return True
# 对该compute_node支持的所有类型进行遍历
for supp_inst in supp_instances:
if _compare_props(checked_img_props, supp_inst)

对于Ironic的调度需要我们着重使用到ImagePropertiesFilter,虚机使用的镜像和裸机使用的镜像中的property的值是不同的,再结合相关的placement的调度,实现虚机不会调度到ironic node,同时创建裸机不会调度到qemu的node。

3. 把过滤后的hosts计算权重并且进行最优排序,下面我们举几个weight的例子:

class BaseWeightHandler(loadables.BaseLoader):
object_class = WeighedObject def get_weighed_objects(self, weighers, obj_list, weighing_properties):
"""Return a sorted (descending), normalized list of WeighedObjects."""
# obj_list 表示filter筛选出的所有hosts
# weighing_properties 表示request_sepc信息
weighed_objs = [self.object_class(obj, 0.0) for obj in obj_list]
# 如果经过filter筛选只剩一个host,则无需进行权重的比较,直接返回该host即可
if len(weighed_objs) <= 1:
return weighed_objs
# 根据配置文件中指定的weigher_classes,逐个计算权重
for weigher in weighers:
# 以RAMWeigher为例进行说明
weights = weigher.weigh_objects(weighed_objs, weighing_properties) # Normalize the weights
weights = normalize(weights,
minval=weigher.minval,
maxval=weigher.maxval) for i, weight in enumerate(weights):
obj = weighed_objs[i]
# 将计算后的权重值,保存到host信息中,并且将所有类型的权重加到一块,如果我们想要增加某种类型的权重比例,我们可以修改配置文件中*_weight_multiplier的值,比如我们想要在权重的计算中有关内存的权重占更大的作用,那么我们可以通过调节ram_weight_multiplier的值达到效果。
obj.weight += weigher.weight_multiplier() * weight
# 按照权重进行性排序(倒序)
return sorted(weighed_objs, key=lambda x: x.weight, reverse=True) class RAMWeigher(weights.BaseHostWeigher):
minval = 0 def weight_multiplier(self):
"""Override the weight multiplier."""
return CONF.filter_scheduler.ram_weight_multiplier def _weigh_object(self, host_state, weight_properties):
"""Higher weights win. We want spreading to be the default."""
# 直接返回该节点的剩余内存,也就是剩余内存越多的节点,有关内存的权重越大。
return host_state.free_ram_mb

4. random,这个过程我们通过代码进行详细的分析。

host_subset_size = CONF.filter_scheduler.host_subset_size
if host_subset_size < len(weighed_hosts):
weighed_subset = weighed_hosts[0:host_subset_size]
else:
weighed_subset = weighed_hosts
# 使用随机算法,从N个中抽取1个
chosen_host = random.choice(weighed_subset)
weighed_hosts.remove(chosen_host)
return [chosen_host] + weighed_hosts

对于host_subset_size参数,默认值为1。官方是这样解释的:如果设置大于1的正整数,当有多个scheduler进程处理相同的请求是会减少调度到同一台host的可能性,创造了一种竞争机制。从N个host中挑选最适合请求的一个host,会减少冲突。然而,如果该值设置的越大,对于给定的请求,选择的主机可能不太优化。

boot,rebuild,resize,migrate有关的scheduler流程的更多相关文章

  1. Migrate Instance 操作详解 - 每天5分钟玩转 OpenStack(40)

    Migrate 操作的作用是将 instance 从当前的计算节点迁移到其他节点上. Migrate 不要求源和目标节点必须共享存储,当然共享存储也是可以的. Migrate 前必须满足一个条件:计算 ...

  2. Resize Instance 操作详解 - 每天5分钟玩转 OpenStack(41)

    Resize 的作用是调整 instance 的 vCPU.内存和磁盘资源. Instance 需要多少资源是定义在 flavor 中的,resize 操作是通过为 instance 选择新的 fla ...

  3. 最近做的一个Spring Boot小项目,欢迎大家访问 http://39.97.115.152/

    最近做的一个Spring Boot小项目,欢迎大家访问 http://39.97.115.152/,帮忙找找bug,网站里有源码地址 网站说明 甲壳虫社区(Beetle Community) 一个开源 ...

  4. 关于DSP的boot mode / boot loader /上电顺序 /在线升级等问题的总结

    使用器件 ti dsp c2000 2837x 1.dsp的上电过程和boot mode以及boot loader 1)dsp的上电顺序, 对于双核系统而言 , 他的上电启动顺序如下所示: 系统复位或 ...

  5. CentOS系统启动流程你懂否

    一.Linux内核的组成 相关概念: Linux系统的组成部分:内核+根文件系统 内核:进程管理.内存管理.网络协议栈.文件系统.驱动程序. IPC(Inter-Process Communicati ...

  6. Linux启动流程与模块管理(15)

    系统的启动其实是一项非常复杂的过程,因为内核得要检测硬件并加载适当的驱动程序,接下来则必须要调用程序来准备好系统运行的环境,以让用户能够顺利的操作整台主机系统,如果你能够理解系统启动的原理,那么将有助 ...

  7. 【docker】docker部署spring boot项目在服务器上

    IDE:idea 工具:docker spring boot:2.0.1 ======================================== 简单记录一下流程,以供参考: 第一步:首先得 ...

  8. Spring Boot Security And JSON Web Token

    Spring Boot Security And JSON Web Token 说明 流程说明 何时生成和使用jwt,其实我们主要是token更有意义并携带一些信息 https://github.co ...

  9. docker部署spring boot项目在服务器上

    IDE:idea 工具:docker spring boot:2.0.1 ======================================== 简单记录一下流程,以供参考: 第一步:首先得 ...

随机推荐

  1. 用JavaScript编写简单斗地主效果Es6

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 数据库事务ACID特性及隔离级别

    数据库ACID特性介绍 1.原子性(Atomic)一个事务被视为一个不可分割的最小工作单元,这个事务里的所有操作要么全部成功执行,要么全都不执行,不能只执行其中的一部分操作.实现事务的原子性,要支持回 ...

  3. JS判断两个数字的大小

    javascript中定义的var类型是弱类型,默认是String类型,在比较两个数字大小的时候默认比较的是两个字符串,比如,在比较10和2时,按数字做比较10是比2大,可是按默认的字符串比较时,第一 ...

  4. node 借助Node Binary管理模块“n”更新

    Node.js的版本频繁变化,如果有模块不能在你当前的Node版本上使用,需要升级Node环境 1)首先:查看当前node版本:node –v 2)安装n模块:npm install -g n 3)检 ...

  5. grep基础用法详解

    适合初学linux的人学得比较凌乱的人看这个也能理理思路学得更系统,节约你的学习时间,提高效率,但是思维导图的作用是帮人理清思路不会迷失在细节中,细节补充学习请参考https://www.cnblog ...

  6. Error evaluating expression ''xxx''. Cause: org.apache.ibatis.ognl.NoSuchPropertyException:

    1.检查实体类相应的字段名以及set,get方法(仔仔细细看) 2.检查mapper.xml取值字段 3.注意实体类中isDelete等类似 isXxx的字段 set get方法会变成GetDelet ...

  7. PHP保存数组到数据库

    数组是 PHP 开发中使用最多的数据类型之一,对于结构化的数据尤为重要. 很多时候我们需要把数组保存到数据库中,实现对结构化数据的直接存储和读取. 其中一个案例就是,对于 Form 提交的多选 che ...

  8. tp5多入口配置

    手册里可能有写,但不是特别清晰,在这给个实例,有两种方式: 1.多个入口文件: 将public下的index.php复制一份,粘贴.重命名为对应模块的名字,如admin: 编辑admin.php的内容 ...

  9. HIve常用CLI命令

    1. 清楚屏幕:Ctrl+L 或者!Clear 最后加上分号 2. 查看数据仓库中的表:show tables; 3. 查看数据仓库中内置函数:show functions: 4. 查看表结构 :de ...

  10. CVE-2018-8174 EXP 0day python

    usage: CVE-2018-8174.py [-h] -u URL -o OUTPUT [-i IP] [-p PORT] Exploit for CVE-2018-8174 optional a ...