• 沒有找到結果。

Resource-based First Fit Algorithm

When a VM request without providing the information for lifetime is issued, the cloud sched-uler will just assign the VM to a PM based on its resource requirements. In this section, we will propose the Resource-based F irst F it Algorithm (RFFA) to which PM is better to host a VM in detail. The RFFA scheme has a trend of assigning a VM to the PM with a smaller identity. Therefore, a PM with a larger identity can have a higher probability to be shut down.

The presented RFFA scheme is shown in Algorithm 1 and Algorithm 2. Then we will de-scribe the related functions of the algorithm. The function V M Request Arrive in Algorithm 1 is invoked when a new VM request trigged by a user arrives and is used to determine which PM can accept the VM corresponding to the request. Therefore, the inputs of the function are a VM request R with resource requirements, and a running PM set P= {P1, P2, ..., Pn}. Note that each PM has a flag, Busy, to indicate that it is in the running or idle state. The value of flag Busy for each PM in the set P is set as1. It represents that the PM can be contained into the set P only in the running state. Other PMs in the idle state are not in the set P.

At first, in line 2 of Algorithm 1, the variable Check is initialized as0 and is set as 1 if a PM in P can host the needed VM for the request. In lines 3-20, the f or loop is repeated until that a running PM being able to accept the VM is found, or all the running PMs are checked and no PM can host it. In lines 4-19, the function judges whether the checked PM is in a full

Algorithm 1 RESOURCE-BASED FIRST FIT ALGORITHM (1)

7: if The available amount of some kind of resource of Pj is smaller than the corre-sponding resource requirement of R then

8: continue;

14: if The available amount of some kind of resource of Pjis smaller than the threshold φ then

21: //When the corresponding VM for the request R can not be host by any running PM:

22: if Check = 0 then

Algorithm 2 RESOURCE-BASED FIRST FIT ALGORITHM (2)

1: FUNCTION V M T erminate(V, P )

2: if The PM P only hosts the VM V then

3: P .avaC ← Ccap;

4: P .avaM ← Mcap;

5: P .avaD← Dcap;

6: P .avaN ← Ncap;

7: P .Busy← 0;

8: P← P\P ;

9: else

10: P .avaC ← P .avaC+V .C;

11: P .avaM ← P .avaM+V .M;

12: P .avaD← P .avaD+V .D;

13: P .avaN ← P .avaN+V .N;

14: end if

15: P .F ully← 0;

16: END FUNCTION

state or not. That is, it considers whether the PM has enough available resources or not. If the amount of any kind of resource of a PM Pj is smaller than the threshold φ, the PM does not have enough resources to host other VMs. Then, the corresponding flag Pj.F ully is set as 1. Otherwise, Pj.F ully is set as 0. Therefore, the function continues searching for the next running PM. But if this PM is not full, there is an another issue that if the available amount of some kind of resources on the PM is smaller than the corresponding resource requirement of the request R, the function also continues finding the next operating PM. On the contrary, if the available amounts of all kinds of resources on the PM are larger or equal to the resource requirements of the VM for R, the VM is able to be assigned to the chosen PM. Then the available resources of the PM must be maintained. In lines 10-13, when the jth PM can host the VM for the request R, its new available resources are derived by subtracting the resource requirements from the original available resources. For example, the new available CPU resource Pj.avaC is equal to Pj.avaC − R.C. Besides, the flag Check is set as 1. That is to say, the VM has been assigned to a PM. But if the VM has not been placed on a running PM, the flag is still0. According to the sentence just mentioned, in lines 22-30, it means that no running PMs in the cloud computing system can host the VM request. Therefore, the cloud scheduler should open a new PM Pnewto host the VM request. The available resources of the new PM must also reduce the resource requirement of the VM. At last, the new PM is included in the set P of running PMs.

Then, when a VM V hosted on the PM P does not execute any more, the second function V M T erminate in Algorithm 2 is triggered. The inputs of the function are the VM V and its corresponding PM P . This function can be divided into two parts. The first part in lines 2-8 considers that when the only VM V on PM P asks for termination, the new available resources of the PM P are the maximum capacities after the VM V is terminated. For instance, the new available CPU resource P.avaC is equal to the maximum capacity of CPU Ccap. Besides, the flag P.F ully is set as0. The state of the PM P transit from the running state to the idle state, and the flag P.Busy is set as0. Certainly, the PM P will be excluded from the set P. The second part in lines 9-14 indicates that when the VM V on PM P requests for termination, if the PM P hosts not only the VM V but also other VMs, the new available resources of the

For example, the new available CPU resource P.avaC is equal to P.avaC+ V.C. Afterwards, because the available resources of the PM P must be larger or equal to the threshold φ after the VM V is terminated on the PM P . Therefore, the flag P.F ully is then set as0.

Let n indicate the number of the running PMs when a VM request arrives. In the function V M Request Arrive of Algorithm 1, the cloud scheduler searches a PM which can host the requiring VM for the request. In the worst case the cloud scheduler will check all the running PMs. Therefore, the time complexity of the function is O(n). In the function V M T erminate of Algorithm 2, it will only accept a request for termination from the VM at a time. The time complexity of the function is O(1).

相關文件