1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-21 18:03:38 +03:00

Bug #1202: Make cpu & mem threshold configurable in sched.conf

This commit is contained in:
Carlos Martín 2012-07-02 16:46:46 +02:00
parent fb3372e73c
commit 4bad0444bf
8 changed files with 77 additions and 7 deletions

View File

@ -95,6 +95,13 @@ public:
values = 0;
};
void get(const char *name, float& value) const
{
string _name(name);
Template::get(_name,value);
};
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------

View File

@ -251,6 +251,18 @@ public:
const string& name,
int& value) const;
/**
* Gets the value of a Single attributes (float) with the given name.
* @param name the attribute name.
* @param value the attribute value, an int, 0 if the attribute is not
* defined or not Single
*
* @return True if the Single attribute was found
*/
virtual bool get(
const string& name,
float& value) const;
friend ostream& operator<<(ostream& os, const Template& t);
/**

View File

@ -20,6 +20,14 @@
#
# LIVE_RESCHEDS: Perform live (1) or cold migrations (0) when rescheduling a VM
#
# CPU_THRESHOLD: Fraction of the actual amount of CPU
# (HOST/HOST_SHARE/MAX_CPU) that the scheduler will use.
# E.g. 0.9 means that only 90% of the total CPU will be used
#
# MEM_THRESHOLD: Fraction of the actual amount of MEMORY
# (HOST/HOST_SHARE/MAX_MEM) that the scheduler will use.
# E.g. 0.9 means that only 90% of the total MEMORY will be used
#
# DEFAULT_SCHED: Definition of the default scheduling algorithm
# - policy:
# 0 = Packing. Heuristic that minimizes the number of hosts in use by
@ -45,6 +53,9 @@ MAX_HOST = 1
LIVE_RESCHEDS = 0
CPU_THRESHOLD = 0.9
MEM_THRESHOLD = 1
DEFAULT_SCHED = [
policy = 1
]

View File

@ -44,9 +44,11 @@ public:
* Gets the current host capacity
* @param cpu the host free cpu, scaled according to a given threshold
* @param memory the host free memory
* @param threshold to consider the host totally free
* @param cpu_threshold to consider the host totally free
* @param mem_threshold to consider the host totally free
*/
void get_capacity(int& cpu, int& memory, float threshold) const;
void get_capacity(int& cpu, int& memory,
float cpu_threshold, float mem_threshold) const;
/**
* Tests whether a new VM can be hosted by the host or not

View File

@ -54,7 +54,8 @@ protected:
machines_limit(0),
dispatch_limit(0),
host_dispatch_limit(0),
threshold(0.9),
cpu_threshold(0.9),
mem_threshold(1),
client(0)
{
am.addListener(this);
@ -158,7 +159,12 @@ private:
/**
* Threshold value to round up freecpu
*/
float threshold;
float cpu_threshold;
/**
* Threshold value to round up freemem
*/
float mem_threshold;
/**
* XML_RPC client

View File

@ -18,7 +18,8 @@
#include "HostXML.h"
void HostXML::get_capacity(int& cpu, int& memory, float threshold) const
void HostXML::get_capacity(int& cpu, int& memory,
float cpu_threshold, float mem_threshold) const
{
vector<string> result;
@ -26,10 +27,15 @@ void HostXML::get_capacity(int& cpu, int& memory, float threshold) const
cpu = free_cpu;
/* eg. 96.7 >= 0.9 * 100, We need to round */
if ( cpu >= static_cast<int>(threshold * static_cast<float>(max_cpu)) )
if ( cpu >= static_cast<int>(cpu_threshold * static_cast<float>(max_cpu)) )
{
cpu = static_cast<int>(ceil(static_cast<float>(cpu)/100.0) * 100);
}
if ( memory >= static_cast<int>(mem_threshold * static_cast<float>(max_mem)) )
{
memory = static_cast<int>(ceil(static_cast<float>(memory)/100.0) * 100);
}
}
/* -------------------------------------------------------------------------- */

View File

@ -139,6 +139,9 @@ void Scheduler::start()
conf.get("MAX_HOST", host_dispatch_limit);
conf.get("CPU_THRESHOLD", cpu_threshold);
conf.get("MEM_THRESHOLD", mem_threshold);
conf.get("LIVE_RESCHEDS", live_rescheds);
oss.str("");
@ -425,7 +428,7 @@ void Scheduler::match()
vm->get_requirements(vm_cpu,vm_memory,vm_disk);
host->get_capacity(host_cpu, host_memory, threshold);
host->get_capacity(host_cpu, host_memory, cpu_threshold, mem_threshold);
if ((vm_memory <= host_memory) && (vm_cpu <= host_cpu))
{

View File

@ -436,6 +436,29 @@ bool Template::get(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Template::get(
const string& name,
float& value) const
{
string sval;
get(name, sval);
if ( sval == "" )
{
value = 0;
return false;
}
istringstream iss(sval);
iss >> value;
return true;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& Template::to_xml(string& xml) const
{
multimap<string,Attribute *>::const_iterator it;