Project

General

Profile

root / trunk / doc / manual / policies.tex @ 705

1
Haizea uses several scheduling algorithms internally to determine what resources to allocate to a lease. For the most part, modifying these algorithms requires digging deep into the Haizea code. However, several scheduling decisions that depend on an organizations own resource allocation policies are factored out of the main scheduling code into pluggable \emph{policy decision module}. In particular, the following decisions are factored out:
2

    
3
\begin{description}
4
 \item[Lease admission]: Should a lease request be accepted or rejected? Take into account that this decision takes place before Haizea determines if the request is even feasible. For example, an organization may require that all AR leases must be requested at least one hour in advance, regardless of whether there would be enough resources to satisfy the request before that time. However, being accepted doesn't guarantee the lease will get resources (although this could factor into the decision too); an AR lease could meet the ``one hour advance warning'' requirement, but still end up being rejected because there are no resources available at the requested time.
5
 \item[Lease preemptability]: How preemptable is a lease? Not all leases are created equal and, if the scheduler determines that a lease request can only be satisfied by preempting other leases, it may have to determine what leases are better candidates for preemption. For example, given a choice of preempting a lease that's been running for a week and another that's been running for five minutes, an organization might prefer to not interrupt the long-running lease.
6
 \item[Host selection]: What hosts should a lease be scheduled in? When the scheduler has a choice of several physical hosts on which to deploy VMs, some might be preferable than others. For example, an organization might want to pack as many VMs into the same hosts, to shut down those that are not running VMs, while another might want to spread those VMs across several hosts, leaving some free resources available in each host in case the VMs need extra capacity further down the road.
7
\end{description}
8

    
9
As you can see, these are all policy decisions that are driven by an organization's own goals for its resources. Thus, Haizea makes it simple to write your own policy decision code \emph{without} having to modify Haizea's code. All you have to do is write a simple Python module, and then ``plug it'' into Haizea by instructing it (through the configuration file) to use that module. This chapter describes how this is done.
10

    
11
\begin{warning}
12
This documentation refers to Haizea objects, such as \texttt{Lease} and \texttt{SlotTable} that are not yet documented in this manual. For now, you will need to read the Haizea Pydoc documentation (linked from the Documentation section of the Haizea website) to see what attributes and methods these classes have. A more complete documentation will be included in the final 1.0 release.
13
\end{warning}
14

    
15
\section{Lease admission}
16

    
17
A lease admission policy module looks like this:
18

    
19
\begin{wideshellverbatim}
20
from haizea.core.scheduler.policy import LeaseAdmissionPolicy
21

    
22
class MyPolicy(LeaseAdmissionPolicy):
23
    def __init__(self, slottable):
24
        LeaseAdmissionPolicy.__init__(self, slottable)
25
        
26
    def accept_lease(self, lease):
27
        # Your code goes here
28
\end{wideshellverbatim}
29

    
30
The \texttt{accept\_lease} method receives a \texttt{Lease} object, and must return \texttt{True} if the lease can be accepted, and \texttt{False} if it should be rejected. You can also add code to the constructor, but cannot alter its parameter list. Haizea includes some built-in admission policies that you can see in \texttt{src/haizea/policies/admission.py}
31

    
32
The lease admission policy that Haizea must use is specified using the \texttt{policy-admission} option of the \texttt{[scheduling]} section in the configuration file. So, assuming you save your module as \texttt{policies.py}, you would specify the following in the configuration file:
33

    
34
\begin{wideshellverbatim}
35
[scheduling]
36
...
37
policy-admission: policies.MyPolicy
38
...
39
\end{wideshellverbatim}
40

    
41
For this to work, you have to make sure that the \texttt{policies.py} module you created is in your \texttt{PYTHONPATH} when you start Haizea.
42

    
43
For example, let's suppose we want to write an admission policy that, as described earlier, will reject AR leases that are not requested at least one hour in advance. This policy module would look like this:
44

    
45
\begin{wideshellverbatim}
46
from haizea.core.scheduler.policy import LeaseAdmissionPolicy
47
from haizea.core.leases import Lease
48
from haizea.common.utils import get_clock
49
from mx.DateTime import TimeDelta
50

    
51
class MyPolicy(LeaseAdmissionPolicy):
52
    def __init__(self, slottable):
53
        LeaseAdmissionPolicy.__init__(self, slottable)
54
        
55
    def accept_lease(self, lease):
56
        allowed = TimeDelta(hours=1)
57
        now = get_clock().get_time()
58
        
59
        if lease.get_type() == Lease.ADVANCE_RESERVATION:
60
            if lease.start.requested - now <= allowed:
61
                return False
62
        return True
63
\end{wideshellverbatim}
64

    
65
Save this file as \texttt{policies.py}, make sure the directory it's in is in your \texttt{PYTHONPATH}, and set \texttt{[scheduling].policy-admission} to \texttt{policies.MyPolicy} in the configuration file. If you rerun the example from the quickstart guide, instead of seeing this:
66

    
67
\begin{wideshellverbatim}
68
[2006-11-25 13:15:00.00] LSCHED  Lease #2 has been requested.
69
[2006-11-25 13:15:00.00] LSCHED  Lease #2 has been marked as pending.
70
\end{wideshellverbatim}
71

    
72
You will see that the AR lease, which is requested 15 minutes before it starts, is rejected:
73

    
74
\begin{wideshellverbatim}
75
[2006-11-25 13:15:00.00] LSCHED  Lease #2 has been requested.
76
[2006-11-25 13:15:00.00] LSCHED  Lease #2 has not been accepted
77
\end{wideshellverbatim}
78

    
79
In fact, if you modify the starting time to be the following:
80

    
81
\begin{wideshellverbatim}
82
<start>
83
	<exact time="02:00:00"/>
84
</start>
85
\end{wideshellverbatim}
86

    
87
The lease will be accepted again, although it will start later than before:
88

    
89
\begin{wideshellverbatim}
90
[2006-11-25 15:00:00.00] VMSCHED Started VMs for lease 2 on nodes [1, 2, 3, 4]
91
[2006-11-25 15:30:00.00] VMSCHED Stopped VMs for lease 2 on nodes [1, 2, 3, 4]
92
\end{wideshellverbatim}
93

    
94
\section{Lease preemptability}
95

    
96
A lease preemptability policy module looks like this:
97

    
98
\begin{wideshellverbatim}
99
from haizea.core.leases import Lease
100
from haizea.core.scheduler.policy import PreemptabilityPolicy
101

    
102
class MyPolicy(PreemptabilityPolicy):
103
    def __init__(self, slottable):
104
        PreemptabilityPolicy.__init__(self, slottable)
105
    
106
    def get_lease_preemptability_score(self, preemptor, preemptee, time):
107
        # Your code goes here
108
\end{wideshellverbatim}
109

    
110
The \texttt{get\_lease\_preemptability\_score} receives two \texttt{Lease} objects, the lease that wants to preempt resources (the \texttt{preemptor}) and the lease that is being considered for preemption (the \texttt{preemptee}), and the time at which the preemption would take place. The method should return the \emph{preemptability score} of the preemptee, indicating how preemptable the lease is. This score can take on the following values:
111

    
112
\begin{itemize}
113
 \item $-1$: Cannot be preempted under any circumstances
114
 \item $0.0 \leq \textrm{score} \leq 1.0$: The lease can be preempted. The higher the score, the "more preemptable" it is. Take into account that this is a relative measure: the score will be used by the scheduler to determine which of several leases is a better candidate for preemption.
115
\end{itemize}
116

    
117
The lease preemptability policy to use is specified using the \texttt{policy-preemption} option of the \texttt{[scheduling]} section in the configuration file. So, assuming you save your module as \texttt{policies.py}, you would specify the following in the configuration file:
118

    
119
\begin{wideshellverbatim}
120
[scheduling]
121
...
122
policy-preemption: policies.MyPolicy
123
...
124
\end{wideshellverbatim}
125

    
126
\section{Host selection}
127

    
128
A host selection policy module looks like this:
129

    
130
\begin{wideshellverbatim}
131
from haizea.core.scheduler.policy import HostSelectionPolicy
132

    
133
class NoPolicy(HostSelectionPolicy):
134
    def __init__(self, slottable):
135
        HostSelectionPolicy.__init__(self, slottable)
136
    
137
    
138
    def get_host_score(self, node, time, lease):       
139
        # Your code goes here
140
\end{wideshellverbatim}
141

    
142
The \texttt{get\_host\_score} method receives a physical host (the integer node identifier used in the slot table, which all policy modules have access to), a time, and a \texttt{Lease} object we would like to schedule at that time. This method returns a score indicating how desirable that host is for that lease at that time. The score can be between 0.0 and 1.0, and the higher the score,       the "more desirable" the physical host is. Like the lease preemptability score, this is a relative measure; the score will be used to determine which of several physical hosts is more desirable for this lease.
143

    
144
The host selection policy to use is specified using the \texttt{policy-host-selection} option of the \texttt{[scheduling]} section in the configuration file. So, assuming you save your module as \texttt{policies.py}, you would specify the following in the configuration file:
145

    
146
\begin{wideshellverbatim}
147
[scheduling]
148
...
149
policy-host-selection: policies.MyPolicy
150
...
151
\end{wideshellverbatim}