1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00

F #5214: Add support for USER_PRIORITY to set dispatch order.

This commit is contained in:
Ruben S. Montero 2017-07-06 16:00:38 +02:00
parent 593600f707
commit 1f571426ab
7 changed files with 73 additions and 30 deletions

View File

@ -927,6 +927,7 @@ VM_RESTRICTED_ATTR = "MEMORY_COST"
VM_RESTRICTED_ATTR = "DISK_COST"
VM_RESTRICTED_ATTR = "PCI"
VM_RESTRICTED_ATTR = "EMULATOR"
VM_RESTRICTED_ATTR = "USER_PRIORITY"
#VM_RESTRICTED_ATTR = "USER_INPUTS/CPU"
#VM_RESTRICTED_ATTR = "USER_INPUTS/MEMORY"
#VM_RESTRICTED_ATTR = "USER_INPUTS/VCPU"

View File

@ -120,6 +120,11 @@ protected:
ds_policies.push_back(policy);
}
void add_vm_policy(SchedulerPolicy *policy)
{
vm_policies.push_back(policy);
}
// ---------------------------------------------------------------
// Scheduler main methods
// ---------------------------------------------------------------
@ -159,6 +164,7 @@ private:
vector<SchedulerPolicy *> host_policies;
vector<SchedulerPolicy *> ds_policies;
vector<SchedulerPolicy *> vm_policies;
// ---------------------------------------------------------------
// Configuration attributes

View File

@ -55,7 +55,7 @@ public:
policy(obj, priority);
//2. Scale priorities
sw.max =fabs(*max_element(priority.begin(), priority.end(), abs_cmp));
sw.max = fabs(*max_element(priority.begin(), priority.end(), abs_cmp));
transform(priority.begin(), priority.end(), priority.begin(), sw);

View File

@ -85,12 +85,19 @@ public:
};
/**
*
*
* Returns a vector of matched hosts
*/
void clear()
const vector<Resource *> get_vm_resources()
{
flush();
return vm_resources.get_resources();
}
/**
* Sort the VMs in the pool
*/
void sort_vm_resources()
{
vm_resources.sort_resources();
}
protected:
@ -110,6 +117,12 @@ protected:
* Do live migrations to resched VMs
*/
bool live_resched;
private:
/**
* Stores the list of vms, and it associated user prioty vm_resources.
*/
ResourceMatch vm_resources;
};
/* -------------------------------------------------------------------------- */

View File

@ -26,14 +26,22 @@ int VirtualMachinePoolXML::set_up()
if ( rc == 0 )
{
map<int, ObjectXML*>::iterator it;
if (objects.empty())
{
return -2;
}
vm_resources.clear();
for ( it = objects.begin(); it != objects.end(); ++it )
{
vm_resources.add_resource(it->first);
}
if (NebulaLog::log_level() >= Log::DDDEBUG)
{
map<int,ObjectXML*>::iterator it;
oss << "Pending/rescheduling VM and capacity requirements:" << endl;

View File

@ -1077,27 +1077,37 @@ void Scheduler::dispatch()
bool dispatched, matched;
char * estr;
map<int, ObjectXML*>::const_iterator vm_it;
vector<Resource *>::const_reverse_iterator i, j, k;
vector<Resource *>::const_reverse_iterator i, j;
vector<SchedulerPolicy *>::iterator sp_it;
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
//--------------------------------------------------------------------------
// Schedule pending VMs according to the VM policies (e.g. User priority)
//--------------------------------------------------------------------------
for (sp_it = vm_policies.begin() ; sp_it != vm_policies.end() ; ++sp_it)
{
(*sp_it)->schedule(0);
}
dss << "Dispatching VMs to hosts:\n" << "\tVMID\tHost\tSystem DS\n"
<< "\t-------------------------\n";
vmpool->sort_vm_resources();
const vector<Resource *> vm_rs = vmpool->get_vm_resources();
//--------------------------------------------------------------------------
dss << "Dispatching VMs to hosts:\n"
<< "\tVMID\tPriority\tHost\tSystem DS\n"
<< "\t--------------------------------------------------------------\n";
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Dispatch each VM till we reach the dispatch limit
//--------------------------------------------------------------------------
for (vm_it = pending_vms.begin();
vm_it != pending_vms.end() &&
( dispatch_limit <= 0 || dispatched_vms < dispatch_limit );
vm_it++)
for (k = vm_rs.rbegin(); k != vm_rs.rend() &&
( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); ++k)
{
dispatched = false;
vm = static_cast<VirtualMachineXML*>(vm_it->second);
vm = vmpool->get((*k)->oid);
const vector<Resource *> resources = vm->get_match_hosts();
@ -1273,12 +1283,15 @@ void Scheduler::dispatch()
//------------------------------------------------------------------
// Dispatch and update host and DS capacity, and dispatch counters
//------------------------------------------------------------------
if (vmpool->dispatch(vm_it->first, hid, dsid, vm->is_resched()) != 0)
if (vmpool->dispatch((*k)->oid, hid, dsid, vm->is_resched()) != 0)
{
continue;
}
dss << "\t" << vm_it->first << "\t" << hid << "\t" << dsid << "\n";
//------------------------------------------------------------------
dss << "\t" << (*k)->oid << "\t" << (*k)->priority << "\t\t" << hid
<< "\t" << dsid << "\n";
//------------------------------------------------------------------
// DS capacity skip VMs deployed in public cloud hosts
if (!host->is_public_cloud())
@ -1347,10 +1360,10 @@ void Scheduler::dispatch()
}
}
if (vm_it != pending_vms.end())
if (k != vm_rs.rend())
{
dss << endl << "MAX_DISPATCH limit of " << dispatch_limit << " reached, "
<< std::distance(vm_it, pending_vms.end())
<< std::distance(k, vm_rs.rend())
<< " VMs were not dispatched";
}

View File

@ -17,6 +17,7 @@
#include "Scheduler.h"
#include "SchedulerTemplate.h"
#include "RankPolicy.h"
#include "UserPriorityPolicy.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -32,19 +33,14 @@ class RankScheduler : public Scheduler
{
public:
RankScheduler():Scheduler(),rp_host(0),rp_ds(0){};
RankScheduler():Scheduler(),rp_host(0),rp_ds(0),rp_vm(0){};
~RankScheduler()
{
if ( rp_host != 0 )
{
delete rp_host;
}
delete rp_host;
delete rp_ds;
if ( rp_ds != 0 )
{
delete rp_ds;
}
delete rp_vm;
};
void register_policies(const SchedulerTemplate& conf)
@ -56,11 +52,17 @@ public:
rp_ds = new RankDatastorePolicy(dspool, conf.get_ds_policy(), 1.0);
add_ds_policy(rp_ds);
rp_vm = new UserPriorityPolicy(vmpool, 1.0);
add_vm_policy(rp_vm);
};
private:
RankPolicy * rp_host;
RankPolicy * rp_ds;
UserPriorityPolicy * rp_vm;
};
int main(int argc, char **argv)