diff --git a/include/NebulaTemplate.h b/include/NebulaTemplate.h index 0626e1cdd1..c9bbc5e9f1 100644 --- a/include/NebulaTemplate.h +++ b/include/NebulaTemplate.h @@ -95,6 +95,13 @@ public: values = 0; }; + void get(const char *name, float& value) const + { + string _name(name); + + Template::get(_name,value); + }; + // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- diff --git a/include/Template.h b/include/Template.h index 1ab6278211..fc18f140a1 100644 --- a/include/Template.h +++ b/include/Template.h @@ -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); /** diff --git a/src/scheduler/etc/sched.conf b/src/scheduler/etc/sched.conf index 73a4a91c6d..f8072681a9 100644 --- a/src/scheduler/etc/sched.conf +++ b/src/scheduler/etc/sched.conf @@ -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 ] diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index 5d300026b8..a91533496e 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -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 diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 454f62fddd..e5df1af2bb 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -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 diff --git a/src/scheduler/src/pool/HostXML.cc b/src/scheduler/src/pool/HostXML.cc index 9f1b2d7d44..874320da14 100644 --- a/src/scheduler/src/pool/HostXML.cc +++ b/src/scheduler/src/pool/HostXML.cc @@ -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 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(threshold * static_cast(max_cpu)) ) + if ( cpu >= static_cast(cpu_threshold * static_cast(max_cpu)) ) { cpu = static_cast(ceil(static_cast(cpu)/100.0) * 100); } + + if ( memory >= static_cast(mem_threshold * static_cast(max_mem)) ) + { + memory = static_cast(ceil(static_cast(memory)/100.0) * 100); + } } /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index d40bb1740b..77c77dd013 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -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)) { diff --git a/src/template/Template.cc b/src/template/Template.cc index 3b3ed7a1fa..bd82d1360f 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -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::const_iterator it;