Skip to content

Instantly share code, notes, and snippets.

@mgagne
Created July 28, 2016 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgagne/1fbeca4c0b60af73f019bc2e21eb4a80 to your computer and use it in GitHub Desktop.
Save mgagne/1fbeca4c0b60af73f019bc2e21eb4a80 to your computer and use it in GitHub Desktop.
Ironic Scheduler Performance patch
commit 76b2a790a65690812c69ae72ed9edbf6208a33c6
Author: Mathieu Gagné <mgagne@iweb.com>
Date: Mon Jul 25 18:37:28 2016 -0400
Only load empty compute nodes in Ironic HostManager
There is no way to schedule more than one instance on an Ironic node.
Optimize nova-scheduler when Ironic is used to only load empty compute nodes.
Change-Id: I476c9372ad7d9a693217fd250b37508daf83d02d
diff --git a/nova/db/api.py b/nova/db/api.py
index 39e3fe5..d4971d9 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -209,6 +209,16 @@ def compute_node_get_all(context):
return IMPL.compute_node_get_all(context)
+def compute_node_get_all_empty(context):
+ """Get all empty computeNodes.
+
+ :param context: The security context
+
+ :returns: List of dictionaries each containing compute node properties
+ """
+ return IMPL.compute_node_get_all_empty(context)
+
+
def compute_node_get_all_by_host(context, host, use_slave=False):
"""Get compute nodes by host name
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index cdc6363..4d13be0 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -618,6 +618,13 @@ def compute_node_get_all(context):
@require_admin_context
+def compute_node_get_all_empty(context):
+ return model_query(context, models.ComputeNode, read_deleted='no').\
+ filter_by(running_vms=0).\
+ all()
+
+
+@require_admin_context
def compute_node_search_by_hypervisor(context, hypervisor_match):
field = models.ComputeNode.hypervisor_hostname
return model_query(context, models.ComputeNode).\
diff --git a/nova/objects/compute_node.py b/nova/objects/compute_node.py
index e11ca57..e517d60 100644
--- a/nova/objects/compute_node.py
+++ b/nova/objects/compute_node.py
@@ -312,6 +312,12 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
db_computes)
@base.remotable_classmethod
+ def get_all_empty(cls, context):
+ db_computes = db.compute_node_get_all_empty(context)
+ return base.obj_make_list(context, cls(context), objects.ComputeNode,
+ db_computes)
+
+ @base.remotable_classmethod
def get_by_hypervisor(cls, context, hypervisor_match):
db_computes = db.compute_node_search_by_hypervisor(context,
hypervisor_match)
diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py
index 0dcf23f..4d808bc 100644
--- a/nova/scheduler/host_manager.py
+++ b/nova/scheduler/host_manager.py
@@ -532,7 +532,7 @@ class HostManager(object):
for service in objects.ServiceList.get_by_binary(
context, 'nova-compute')}
# Get resource usage across the available compute nodes:
- compute_nodes = objects.ComputeNodeList.get_all(context)
+ compute_nodes = self._get_compute_node_list(context)
seen_nodes = set()
for compute in compute_nodes:
service = service_refs.get(compute.host)
@@ -571,6 +571,9 @@ class HostManager(object):
return self.host_state_map.itervalues()
+ def _get_compute_node_list(self, context):
+ return objects.ComputeNodeList.get_all(context)
+
def _add_instance_info(self, context, compute, host_state):
"""Adds the host instance info to the host_state object.
diff --git a/nova/scheduler/ironic_host_manager.py b/nova/scheduler/ironic_host_manager.py
index 664ecbf..f9b9774 100644
--- a/nova/scheduler/ironic_host_manager.py
+++ b/nova/scheduler/ironic_host_manager.py
@@ -27,6 +27,7 @@ from oslo_log import log as logging
from oslo_utils import timeutils
from nova.compute import hv_type
+from nova import objects
from nova.scheduler import host_manager
host_manager_opts = [
@@ -99,6 +100,9 @@ class IronicNodeState(host_manager.HostState):
class IronicHostManager(host_manager.HostManager):
"""Ironic HostManager class."""
+ def _get_compute_node_list(self, context):
+ return objects.ComputeNodeList.get_all_empty(context)
+
def _load_filters(self):
if CONF.scheduler_use_baremetal_filters:
return CONF.baremetal_scheduler_default_filters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment