Skip to content

Commit cf8e816

Browse files
Balazs GibizerMrStupnikov
authored andcommitted
Add debug log for scheduler weight calculation
We have all the weighers enabled by default and each can have its own multiplier making the final compute node order calculation pretty complex. This patch adds some debug logging that helps understanding how the final ordering was reached. Change-Id: I7606d6eb3e08548c1df9dc245ab39cced7de1fb5 (cherry picked from commit 154ab7b) (cherry picked from commit 30c7180)
1 parent d6a296e commit cf8e816

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

nova/weights.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919

2020
import abc
2121

22+
from oslo_log import log as logging
23+
2224
from nova import loadables
2325

2426

27+
LOG = logging.getLogger(__name__)
28+
29+
2530
def normalize(weight_list, minval=None, maxval=None):
2631
"""Normalize the values in a list between 0 and 1.0.
2732
@@ -127,13 +132,40 @@ def get_weighed_objects(self, weighers, obj_list, weighing_properties):
127132
for weigher in weighers:
128133
weights = weigher.weigh_objects(weighed_objs, weighing_properties)
129134

135+
LOG.debug(
136+
"%s: raw weights %s",
137+
weigher.__class__.__name__,
138+
{(obj.obj.host, obj.obj.nodename): weight
139+
for obj, weight in zip(weighed_objs, weights)}
140+
)
141+
130142
# Normalize the weights
131-
weights = normalize(weights,
132-
minval=weigher.minval,
133-
maxval=weigher.maxval)
143+
weights = list(
144+
normalize(
145+
weights, minval=weigher.minval, maxval=weigher.maxval))
146+
147+
LOG.debug(
148+
"%s: normalized weights %s",
149+
weigher.__class__.__name__,
150+
{(obj.obj.host, obj.obj.nodename): weight
151+
for obj, weight in zip(weighed_objs, weights)}
152+
)
153+
154+
log_data = {}
134155

135156
for i, weight in enumerate(weights):
136157
obj = weighed_objs[i]
137-
obj.weight += weigher.weight_multiplier(obj.obj) * weight
158+
multiplier = weigher.weight_multiplier(obj.obj)
159+
weigher_score = multiplier * weight
160+
obj.weight += weigher_score
161+
162+
log_data[(obj.obj.host, obj.obj.nodename)] = (
163+
f"{multiplier} * {weight}")
164+
165+
LOG.debug(
166+
"%s: score (multiplier * weight) %s",
167+
weigher.__class__.__name__,
168+
{name: log for name, log in log_data.items()}
169+
)
138170

139171
return sorted(weighed_objs, key=lambda x: x.weight, reverse=True)

0 commit comments

Comments
 (0)