settingsLogin | Registersettings

Re: [Openstack] Custom Nova Scheduler Weigher

0 votes

For what it is worth...I was able to code a weigher. By dropping the code
below into a .py file in the weights directory and restarting the
scheduler, the scheduler will automatically consider if instances in the
same group are on a node before placing another instance there. For what it
is worth, both the ram weigher and the antiAffinity weigher are on the
playing field and so I have set "one node in the same group= 100GB of ram".

Thanks,
Danny Beutler

"""
AntiAffinityWeigher. Weigh hosts by whether or not they have another host
in the same group.

"""

from oslo.config import cfg

from nova import db
from nova.openstack.common.gettextutils import _
from nova.scheduler import weights
from nova.scheduler import filters
from nova.openstack.common import log as logging

LOG = logging.getLogger(name)

antiaffinityweightopts = [
cfg.FloatOpt('antiAffinityWeigher
Multiplier',
default=1.0,
help='Multiplier used for weighing hosts. Negative '
'numbers mean to spread vs stack.'),
]

CONF = cfg.CONF
CONF.registeropts(antiaffinityweightopts)

class AntiAffinityWeigher(weights.BaseHostWeigher):
def weightmultiplier(self):
"""Override the weight multiplier."""
return CONF.antiAffinityWeigher_Multiplier

def _weigh_object(self, host_state, weight_properties):
    group_hosts = weight_properties.get('group_hosts') or []
    LOG.debug(_("Group anti affinity weigher: check if %(host)s not "
                "in %(configured)s"), {'host': host_state.host,
                                       'configured': group_hosts})
    if group_hosts:
        group_hosts = weight_properties.get('group_hosts') or []
        num_instances_in_group = group_hosts.count(host_state.host)
        LOG.debug(_("Number of instances in the same group on this node

%(host)s"), {'host': numinstancesingroup})
return group
hosts.count(host_state.host) * -100000

    # No groups configured
    return 0

On Mon, Aug 4, 2014 at 12:14 PM, Dugger, Donald D <donald.d.dugger@intel.com

wrote:

Danny-

People have been thinking about affinity/anti-affinity scheduling so this
is a good area to look at but we might want to think of a general approach
that addresses this and other issues. I know that Yathi & Debo have
proposed a BP:

https://blueprints.launchpad.net/nova/+spec/solver-scheduler

you might want to check it out and see how it relates to your issues.

--

Don Dugger

"Censeo Toto nos in Kansa esse decisse." - D. Gale

Ph: 303/443-3786

From: Danny Beutler [mailto:dannybeutler@gmail.com]
Sent: Friday, August 1, 2014 10:47 AM
To: openstack@lists.openstack.org
Subject: [Openstack] Custom Nova Scheduler Weigher

I am in the process of implementing a custom weigher class. I have created
a weigher that prefers hosts which do not have other instances in the same
group (think GroupAntiAffinityFilter but for weight).

Here is the code for the class:

Copyright (c) 2011 OpenStack Foundation

All Rights Reserved.

#

Licensed under the Apache License, Version 2.0 (the "License"); you

may

not use this file except in compliance with the License. You may

obtain

a copy of the License at

#

http://www.apache.org/licenses/LICENSE-2.0

#

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT

WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See

the

License for the specific language governing permissions and

limitations

"""
AntiAffinityWeigher. Weigh hosts by whether or not they have another host
in the same group.

"""

from oslo.config import cfg

from nova import db
from nova.openstack.common.gettextutils import _
from nova.scheduler import weights
from nova.scheduler import filters
from nova.openstack.common import log as logging

LOG = logging.getLogger(name)

antiaffinityweightopts = [
cfg.FloatOpt('antiAffinityWeigher
Multiplier',
default=1000.0,
help='Multiplier used for weighing hosts. Negative '
'numbers mean to stack vs spread.'),
]

CONF = cfg.CONF
CONF.registeropts(antiaffinityweightopts)

class AntiAffinityWeigher(weights.BaseHostWeigher):
def weightmultiplier(self):
"""Override the weight multiplier."""
return CONF.antiAffinityWeigher_Multiplier

def _weigh_object(self, host_state, weight_properties):
    group_hosts = weight_properties.get('group_hosts') or []
    LOG.debug(_("Group anti affinity Weigher: check if %(host)s not "
        "in %(configured)s"), {'host': host_state.host,
        'configured': group_hosts})
    if group_hosts:
        return group_hosts.amount() * 100000

    # No groups configured
    return 0

I know the python is at least close to correct because the scheduler
service wouldn't even restart until it was. After I got the bugs worked out
of the module, I added modified the /etc/nova/nova.conf file to have the
custom weigher like so:

schedulerweightclasses=nova.scheduler.weights.all_weighers,nova.scheduler.AntiAffinityWeigher

After restarting the scheduler service I get the following error in the
nova logs:
<178>Aug 1 16:46:11 node-25 nova-nova CRITICAL: Class AntiAffinityWeigher
cannot be found (['Traceback (most recent call last):\n', ' File
"/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py",
line 31, in importclass\n return getattr(sys.modules[modstr],
classstr)\n', "AttributeError: 'module' object has no attribute
'AntiAffinityWeigher'\n"])
Traceback (most recent call last):
File "/usr/bin/nova-scheduler", line 10, in
sys.exit(main())
File "/usr/lib/python2.6/site-packages/nova/cmd/scheduler.py", line 39,
in main
topic=CONF.scheduler
topic)
File "/usr/lib/python2.6/site-packages/nova/service.py", line 257, in
create
dballowed=dballowed)
File "/usr/lib/python2.6/site-packages/nova/service.py", line 139, in
init
self.manager = manager_class(host=self.host, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/nova/scheduler/manager.py", line
65, in __init__
self.driver = importutils.import_object(scheduler_driver)
File
"/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py",
line 40, in import_object
return import_class(import_str)(*args, **kwargs)
File
"/usr/lib/python2.6/site-packages/nova/scheduler/filter_scheduler.py", line
59, in __init__
super(FilterScheduler, self).__init__(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/nova/scheduler/driver.py", line
103, in __init__
CONF.scheduler_host_manager)
File
"/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py",
line 40, in import_object
return import_class(import_str)(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/nova/scheduler/host_manager.py",
line 297, in __init__
CONF.scheduler_weight_classes)
File "/usr/lib/python2.6/site-packages/nova/loadables.py", line 105, in
get_matching_classes
obj = importutils.import_class(cls_name)
File
"/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py",
line 35, in import_class
traceback.format_exception(*sys.exc_info())))
ImportError: Class AntiAffinityWeigher cannot be found (['Traceback (most
recent call last):\n', ' File
"/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py",
line 31, in import_class\n return getattr(sys.modules[mod_str],
class_str)\n', "AttributeError: 'module' object has no attribute
'AntiAffinityWeigher'\n"])

I have also tried a few different naming conventions such as
"AntiAffinityWeigher.AntiAffinityWeigher" and
"myWeigher.AntiAffinityWeigher" to no avail.

Any help would be greatly appreciated.

Thanks,
Danny


Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
Post to : openstack@lists.openstack.org
Unsubscribe : http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
asked Aug 5, 2014 in openstack by Danny_Beutler (120 points)   1
retagged Feb 9, 2015 by admin
...