1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """This module provides pluggable host selection policies. See the documentation
20 for haizea.core.schedule.policy.HostSelectionPolicy for more details on
21 host selection policies.
22 """
23
24 from haizea.core.scheduler.policy import HostSelectionPolicy
25
27 """A simple host selection policy: all hosts have the same score
28 """
36
37
39 """Computes the score of a host
40
41 See class documentation for details on what policy is implemented here.
42 See documentation of HostSelectionPolicy.get_host_score for more details
43 on this method.
44
45 Arguments:
46 node -- Physical node (the integer identifier used in the slot table)
47 time -- Time at which the lease might be scheduled
48 lease -- Lease that is being scheduled.
49 """
50 return 1
51
52
53
55 """A greedy host selection policy.
56
57 This policy scores hosts such that hosts with fewer leases already
58 scheduled on them, with the highest capacity, and with fewest leases
59 scheduled in the future are scored highest.
60
61 """
69
71 """Computes the score of a host
72
73 See class documentation for details on what policy is implemented here.
74 See documentation of HostSelectionPolicy.get_host_score for more details
75 on this method.
76
77 Arguments:
78 node -- Physical node (the integer identifier used in the slot table)
79 time -- Time at which the lease might be scheduled
80 lease -- Lease that is being scheduled.
81 """
82 aw = self.slottable.get_availability_window(time)
83
84 leases_in_node_horizon = 4
85
86
87 leases_in_node = len(aw.get_leases_at(node, time))
88 if leases_in_node > leases_in_node_horizon:
89 leases_in_node = leases_in_node_horizon
90
91
92
93 leases_in_node = (leases_in_node_horizon - leases_in_node) / float(leases_in_node_horizon)
94 leases_in_node_score = leases_in_node
95
96
97
98 avail = aw.get_availability(time, node)
99
100 high_capacity_score = 1.0
101
102
103
104 duration = aw.get_capacity_duration(node, time)
105 if duration == None or duration>=lease.duration.requested:
106 duration_score = 1.0
107 else:
108 duration_score = duration.seconds / float(lease.duration.requested.seconds)
109
110 return 0.5 * leases_in_node_score + 0.25 * high_capacity_score + 0.25 * duration_score
111