雲端運算模擬工具中文注釋VmSchedulerSpaceShared.java

來源:互聯網
上載者:User
/* * Title:        CloudSim Toolkit * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html * * Copyright (c) 2009-2010, The University of Melbourne, Australia */package org.cloudbus.cloudsim;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;/** * 空間共用虛擬機器調度策略,pe不可以共用 * 當沒有pe時候,分配會失敗 * VmSchedulerSpaceShared is a VMM allocation policy that * allocates one or more Pe to a VM, and doesn't allow sharing * of PEs. If there is no free PEs to the VM, allocation fails. * Free PEs are not allocated to VMs * * @authorRodrigo N. Calheiros * @authorAnton Beloglazov * @sinceCloudSim Toolkit 1.0 */public class VmSchedulerSpaceShared extends VmScheduler {/** Map containing VM ID and a vector of PEs allocated to this VM. */private Map<String, List<Pe>> peAllocationMap;/** The free pes vector. */private List<Pe> freePes;/** * Instantiates a new vm scheduler space shared. * * @param pelist the pelist */public VmSchedulerSpaceShared(List<? extends Pe> pelist) {super(pelist);setPeAllocationMap(new HashMap<String, List<Pe>>());setFreePes(new ArrayList<Pe>());getFreePes().addAll(pelist);}/* (non-Javadoc) * 分配pes給vm * mipshare中的數值表示一個pe需要分配的mips,mipshare列表大小表示需要的cpu的個數 * @see org.cloudbus.cloudsim.VmScheduler#allocatePesForVm(org.cloudbus.cloudsim.Vm, java.util.List) */@Overridepublic boolean allocatePesForVm(Vm vm, List<Double> mipsShare) {//if there is no enough free PEs, failsif (getFreePes().size() < mipsShare.size()) {return false;}List<Pe> selectedPes = new ArrayList<Pe>();Iterator<Pe> peIterator = getFreePes().iterator();Pe pe = peIterator.next();double totalMips = 0;for (Double mips : mipsShare) {if (mips <= pe.getMips()) {selectedPes.add(pe);if (!peIterator.hasNext()) {break;}pe = peIterator.next();totalMips += mips;}}if (mipsShare.size() > selectedPes.size()) {  //free的pe不夠return false;}getFreePes().removeAll(selectedPes);          //從空閑列表中移走getPeAllocationMap().put(vm.getUid(), selectedPes);  //加入已指派的pe map中getMipsMap().put(vm.getUid(), mipsShare);            //對應的分配得到每個pe的mips放到mips map中setAvailableMips(getAvailableMips() - totalMips);return true;}/* (non-Javadoc) * 回收vm的pes * @see org.cloudbus.cloudsim.VmScheduler#deallocatePesForVm(org.cloudbus.cloudsim.Vm) */@Overridepublic void deallocatePesForVm(Vm vm) {getFreePes().addAll(getPeAllocationMap().get(vm.getUid()));      //vm佔用的pe加到free pe列表中getPeAllocationMap().remove(vm.getUid());                        //從已指派的pe map中刪除double totalMips = 0;                                            //更新availablemipsfor (double mips : getMipsMap().get(vm.getUid())) {totalMips += mips;}setAvailableMips(getAvailableMips() + totalMips);getMipsMap().remove(vm.getUid());                                //山粗對應的mips map中對應此虛擬機器部分}/** * Sets the pe allocation map. * * @param peAllocationMap the pe allocation map */protected void setPeAllocationMap(Map<String, List<Pe>> peAllocationMap) {this.peAllocationMap = peAllocationMap;}/** * Gets the pe allocation map. * * @return the pe allocation map */protected Map<String, List<Pe>> getPeAllocationMap() {return peAllocationMap;}/** * Sets the free pes vector. * * @param freePes the new free pes vector */protected void setFreePes(List<Pe> freePes) {this.freePes = freePes;}/** * Gets the free pes vector. * * @return the free pes vector */protected List<Pe> getFreePes() {return freePes;}}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.