nova的资源管理
2018-03-26 21:57
288 查看
nova-compute需要在数据库中存储主机的资源使用情况,包括内存、cpu、磁盘等,以便nova-scheduler获取作为选择主机的依据,这就要求每创建、迁移、删除一个虚拟机,都要更新数据库中相关的内容。Nova使用ComputeNode对象保存计算节点的配置信息以及资源使用状态。nova-compute为每一个主机创建一个ResourceTracker对象,任务就是更新ComputeNode对象在数据库中对应的表compute_nodes。有两种更新数据库中资源数据的方式:一是Resource Tracker的Claim机制,二是使用周期性任务(Periodic Task)。一 Claim机制当一台主机被多个nova-scheduler同时选中并发送创建虚拟机的请求时,这台主机并不一定有足够的资源来满足这些虚拟机的创建要求。Claim机制即是在创建之前先测试一下主机的可用资源是否能够满足新建虚拟机的需求,如果满足,则更新数据库,将虚拟机申请的资源从主机可用的资源中减掉,如果后来创建失败或者是将虚拟机删除时,会通过Claim加上之前减掉的部分。
#nova/compute/resource_tracker.py def instance_claim(self, context, instance_ref, limits=None): if self.disabled: # compute_driver doesn't support resource tracking, just # set the 'host' and node fields and continue the build: self._set_instance_host_and_node(context, instance_ref) return claims.NopClaim() # sanity checks: if instance_ref['host']: LOG.warning(_("Host field should not be set on the instance until " "resources have been claimed."), instance=instance_ref) if instance_ref['node']: LOG.warning(_("Node field should not be set on the instance " "until resources have been claimed."), instance=instance_ref) # get memory overhead required to build this instance: overhead = self.driver.estimate_instance_overhead(instance_ref) LOG.debug("Memory overhead for %(flavor)d MB instance; %(overhead)d " "MB", {'flavor': instance_ref['memory_mb'], 'overhead': overhead['memory_mb']}) #如果Claim返回为None,即主机的可用资源满足不了新建虚拟机的需求 #上层函数会调用__exit__()方法将占用的资源返回到主机的可用资源中 claim = claims.Claim(context, instance_ref, self, self.compute_node, overhead=overhead, limits=limits) #通过Conductor API更新instance的host、node与launched_on属性 self._set_instance_host_and_node(context, instance_ref) instance_ref['numa_topology'] = claim.claimed_numa_topology # 根据新建虚拟机的需求计算主机的可用的资源 self._update_usage_from_instance(context, self.compute_node, instance_ref) elevated = context.elevated() #根据上面的计算结果更新数据库 self._update(elevated, self.compute_node) return claim二 Periodic Task机制在类nova.compute.manager.ComputeManager中有个周期性任务update_available_resource(),用于更新主机的资源数据。
#nova/compute/manager.py #修饰符periodic_task表示此函数是一个周期性任务,会被周期性调用 @periodic_task.periodic_task def update_available_resource(self, context): new_resource_tracker_dict = {} nodenames = set(self.driver.get_available_nodes()) #更新所有主机数据库中的资源数据 for nodename in nodenames: rt = self._get_resource_tracker(nodename) rt.update_available_resource(context) new_resource_tracker_dict[nodename] = rt # Delete orphan compute node not reported by driver but still in db compute_nodes_in_db = self._get_compute_nodes_in_db(context, use_slave=True) for cn in compute_nodes_in_db: if cn.hypervisor_hostname not in nodenames: LOG.audit(_("Deleting orphan compute node %s") % cn.id) cn.destroy() self._resource_tracker_dict = new_resource_tracker_dict三 小结这两种更新方式并不冲突,Claim机制是在数据库当前数据的基础上去计算并更新,能够保证数据库里的可用资源及时更新,以便为nova-scheduler提供最新的数据。周期性任务(Periodic Task)是为了保证数据库内的信息的准确性,它每次都会调用Hypervisor获取主机信息,并将这些信息更新到数据库中。
相关文章推荐
- OpenStack Nova Placement API 统一资源管理接口的未来
- 资源管理
- 使用 Chef 管理 Azure 资源
- 使用scvmm 2012的动态优化管理群集资源
- WIN8/WIN8.1 任务栏经常卡死,资源管理无响应重启的解决方法(2015年3月开始)
- actionscript3.0 资源管理问题
- C++中的资源管理(一):构造自己的auto_ptr与shared_ptr智能指针
- 解决问题E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录
- Oracle 学习笔记4 —— 使用profile管理系统资源
- 使用ScopeGuard统一管理系统资源的释放
- Android平台的音乐资源管理与播放
- C++ Primer : 第十三章 : 拷贝控制之拷贝控制和资源管理
- C++中的资源管理<转载>
- 设备资源管理系统-分页
- 管理资源的几种数据结构
- Effective C++读书笔记(三) 资源管理
- Lomox_2013_04_05_Release 发布,增加资源管理API
- Apple TV编程指南:资源管理
- CMS-一篇关于分类资源管理系统设计思路的笔记
- C++中动态资源管理