Skip to content

Commit

Permalink
Merge "Add debug log for scheduler weight calculation" into stable/wa…
Browse files Browse the repository at this point in the history
…llaby
  • Loading branch information
Zuul authored and openstack-gerrit committed Jul 12, 2023
2 parents d46a71f + cf8e816 commit 57c084f
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions nova/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

import abc

from oslo_log import log as logging

from nova import loadables


LOG = logging.getLogger(__name__)


def normalize(weight_list, minval=None, maxval=None):
"""Normalize the values in a list between 0 and 1.0.
Expand Down Expand Up @@ -127,13 +132,40 @@ def get_weighed_objects(self, weighers, obj_list, weighing_properties):
for weigher in weighers:
weights = weigher.weigh_objects(weighed_objs, weighing_properties)

LOG.debug(
"%s: raw weights %s",
weigher.__class__.__name__,
{(obj.obj.host, obj.obj.nodename): weight
for obj, weight in zip(weighed_objs, weights)}
)

# Normalize the weights
weights = normalize(weights,
minval=weigher.minval,
maxval=weigher.maxval)
weights = list(
normalize(
weights, minval=weigher.minval, maxval=weigher.maxval))

LOG.debug(
"%s: normalized weights %s",
weigher.__class__.__name__,
{(obj.obj.host, obj.obj.nodename): weight
for obj, weight in zip(weighed_objs, weights)}
)

log_data = {}

for i, weight in enumerate(weights):
obj = weighed_objs[i]
obj.weight += weigher.weight_multiplier(obj.obj) * weight
multiplier = weigher.weight_multiplier(obj.obj)
weigher_score = multiplier * weight
obj.weight += weigher_score

log_data[(obj.obj.host, obj.obj.nodename)] = (
f"{multiplier} * {weight}")

LOG.debug(
"%s: score (multiplier * weight) %s",
weigher.__class__.__name__,
{name: log for name, log in log_data.items()}
)

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

0 comments on commit 57c084f

Please sign in to comment.