2009-03-19 16:35:35 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2013-12-10 22:00:31 +00:00
|
|
|
// job dispatch using a score-based approach:
|
|
|
|
// - scan the job array, assigning a score to each job and building a list
|
|
|
|
// (the score reflect a variety of factors).
|
|
|
|
// - sort the list
|
|
|
|
// - send jobs in order of decreasing score until request is satisfied
|
|
|
|
// - do the above separately for each resource type
|
2009-03-19 16:35:35 +00:00
|
|
|
|
2013-04-09 18:10:50 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2009-03-19 16:35:35 +00:00
|
|
|
#include "boinc_db.h"
|
|
|
|
#include "error_numbers.h"
|
2010-10-27 22:58:16 +00:00
|
|
|
#include "util.h"
|
2009-03-19 16:35:35 +00:00
|
|
|
|
2013-04-09 19:19:00 +00:00
|
|
|
#include "sched_check.h"
|
2009-03-19 16:35:35 +00:00
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_hr.h"
|
2017-07-22 07:48:38 +00:00
|
|
|
#include "sched_keyword.h"
|
2013-04-09 19:19:00 +00:00
|
|
|
#include "sched_main.h"
|
2009-03-19 16:35:35 +00:00
|
|
|
#include "sched_msgs.h"
|
|
|
|
#include "sched_send.h"
|
2013-04-09 19:19:00 +00:00
|
|
|
#include "sched_shmem.h"
|
2009-08-10 04:49:02 +00:00
|
|
|
#include "sched_types.h"
|
2013-04-09 19:19:00 +00:00
|
|
|
#include "sched_version.h"
|
2009-03-19 16:35:35 +00:00
|
|
|
|
|
|
|
#include "sched_score.h"
|
|
|
|
|
2013-12-10 22:00:31 +00:00
|
|
|
// given the host's estimated speed, determine its size class
|
|
|
|
//
|
2013-04-25 07:27:35 +00:00
|
|
|
static int get_size_class(APP& app, double es) {
|
|
|
|
for (int i=0; i<app.n_size_classes-1; i++) {
|
|
|
|
if (es < app.size_class_quantiles[i]) return i;
|
|
|
|
}
|
|
|
|
return app.n_size_classes - 1;
|
|
|
|
}
|
|
|
|
|
2013-04-10 22:52:53 +00:00
|
|
|
// Assign a score to this job,
|
|
|
|
// representing the value of sending the job to this host.
|
|
|
|
// Also do some initial screening,
|
|
|
|
// and return false if can't send the job to host
|
|
|
|
//
|
2017-07-22 07:48:38 +00:00
|
|
|
bool JOB::get_score(int array_index) {
|
|
|
|
WU_RESULT& wu_result = ssp->wu_results[array_index];
|
2013-04-09 18:10:50 +00:00
|
|
|
score = 0;
|
2013-04-10 22:52:53 +00:00
|
|
|
|
|
|
|
if (!app->beta && wu_result.need_reliable) {
|
|
|
|
if (!bavp->reliable) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 22:52:53 +00:00
|
|
|
if (app->beta) {
|
2016-07-27 22:15:08 +00:00
|
|
|
if (g_wreq->project_prefs.allow_beta_work) {
|
2013-04-09 18:10:50 +00:00
|
|
|
score += 1;
|
|
|
|
} else {
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
2014-05-12 17:21:28 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] can't send job %lu for beta app to non-beta user\n",
|
2014-05-12 17:21:28 +00:00
|
|
|
wu_result.workunit.id
|
|
|
|
);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-10 22:52:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 04:07:07 +00:00
|
|
|
if (app_not_selected(app->id)) {
|
2017-06-28 06:45:53 +00:00
|
|
|
if (g_wreq->project_prefs.allow_non_preferred_apps) {
|
2013-04-10 22:52:53 +00:00
|
|
|
score -= 1;
|
2013-04-09 18:10:50 +00:00
|
|
|
} else {
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] app not selected for job %lu\n",
|
2014-06-12 18:33:11 +00:00
|
|
|
wu_result.workunit.id
|
|
|
|
);
|
|
|
|
}
|
2013-04-10 22:52:53 +00:00
|
|
|
return false;
|
2013-04-09 18:10:50 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-10 22:52:53 +00:00
|
|
|
|
2013-04-09 18:10:50 +00:00
|
|
|
if (wu_result.infeasible_count) {
|
|
|
|
score += 1;
|
|
|
|
}
|
|
|
|
|
2013-04-10 22:52:53 +00:00
|
|
|
if (app->locality_scheduling == LOCALITY_SCHED_LITE
|
|
|
|
&& g_request->file_infos.size()
|
|
|
|
) {
|
|
|
|
int n = nfiles_on_host(wu_result.workunit);
|
|
|
|
if (config.debug_locality_lite) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[loc_lite] job %s has %d files on this host\n",
|
|
|
|
wu_result.workunit.name, n
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
score += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-25 07:27:35 +00:00
|
|
|
if (app->n_size_classes > 1) {
|
2014-03-07 05:23:02 +00:00
|
|
|
double effective_speed = bavp->host_usage.projected_flops * available_frac(*bavp);
|
2013-04-25 07:27:35 +00:00
|
|
|
int target_size = get_size_class(*app, effective_speed);
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
2013-04-25 07:27:35 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2014-06-12 18:33:11 +00:00
|
|
|
"[send_job] size: host %d job %d speed %f\n",
|
2013-04-25 07:27:35 +00:00
|
|
|
target_size, wu_result.workunit.size_class, effective_speed
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (target_size == wu_result.workunit.size_class) {
|
|
|
|
score += 5;
|
|
|
|
} else if (target_size < wu_result.workunit.size_class) {
|
|
|
|
score -= 2;
|
|
|
|
} else {
|
|
|
|
score -= 1;
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 06:34:45 +00:00
|
|
|
|
|
|
|
score += wu_result.res_priority;
|
|
|
|
|
2017-07-22 07:48:38 +00:00
|
|
|
if (config.keyword_sched) {
|
|
|
|
double x = keyword_score(array_index);
|
|
|
|
if (x < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
score += x;
|
|
|
|
}
|
|
|
|
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
2013-04-25 07:27:35 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job]: score %f for result %lu\n", score, wu_result.resultid
|
2013-04-25 07:27:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-04-09 18:10:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool job_compare(JOB j1, JOB j2) {
|
2013-05-22 17:20:54 +00:00
|
|
|
return (j1.score > j2.score);
|
2013-04-09 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static double req_sec_save[NPROC_TYPES];
|
|
|
|
static double req_inst_save[NPROC_TYPES];
|
|
|
|
|
|
|
|
static void clear_others(int rt) {
|
|
|
|
for (int i=0; i<NPROC_TYPES; i++) {
|
|
|
|
if (i == rt) continue;
|
|
|
|
req_sec_save[i] = g_wreq->req_secs[i];
|
|
|
|
g_wreq->req_secs[i] = 0;
|
|
|
|
req_inst_save[i] = g_wreq->req_instances[i];
|
|
|
|
g_wreq->req_instances[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_others(int rt) {
|
|
|
|
for (int i=0; i<NPROC_TYPES; i++) {
|
|
|
|
if (i == rt) continue;
|
|
|
|
g_wreq->req_secs[i] += req_sec_save[i];
|
|
|
|
g_wreq->req_instances[i] += req_inst_save[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// send work for a particular processor type
|
|
|
|
//
|
|
|
|
void send_work_score_type(int rt) {
|
|
|
|
vector<JOB> jobs;
|
|
|
|
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_scan) {
|
2013-08-09 23:06:36 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2014-06-12 18:33:11 +00:00
|
|
|
"[send_scan] scanning for %s jobs\n", proc_type_name(rt)
|
2013-08-09 23:06:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-04-09 18:10:50 +00:00
|
|
|
clear_others(rt);
|
|
|
|
|
2014-07-08 19:35:45 +00:00
|
|
|
int nscan = ssp->max_wu_results;
|
2013-04-09 18:10:50 +00:00
|
|
|
int rnd_off = rand() % ssp->max_wu_results;
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_scan) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[send_scan] scanning %d slots starting at %d\n", nscan, rnd_off
|
|
|
|
);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
for (int j=0; j<nscan; j++) {
|
|
|
|
int i = (j+rnd_off) % ssp->max_wu_results;
|
|
|
|
WU_RESULT& wu_result = ssp->wu_results[i];
|
2014-06-13 07:30:03 +00:00
|
|
|
if (wu_result.state != WR_STATE_PRESENT && wu_result.state != g_pid) {
|
2013-04-09 18:10:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WORKUNIT wu = wu_result.workunit;
|
|
|
|
JOB job;
|
|
|
|
job.app = ssp->lookup_app(wu.appid);
|
2014-06-12 18:33:11 +00:00
|
|
|
if (job.app->non_cpu_intensive) {
|
|
|
|
if (config.debug_send_job) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] [RESULT#%lu] app is non compute intensive\n",
|
2014-06-12 18:33:11 +00:00
|
|
|
wu_result.resultid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
job.bavp = get_app_version(wu, true, false);
|
2014-06-12 18:33:11 +00:00
|
|
|
if (!job.bavp) {
|
|
|
|
if (config.debug_send_job) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] [RESULT#%lu] no app version available\n",
|
2014-06-12 18:33:11 +00:00
|
|
|
wu_result.resultid
|
|
|
|
);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
|
|
|
|
job.index = i;
|
|
|
|
job.result_id = wu_result.resultid;
|
2017-07-22 07:48:38 +00:00
|
|
|
if (!job.get_score(i)) {
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] [RESULT#%lu] get_score() returned false\n",
|
2014-06-12 18:33:11 +00:00
|
|
|
wu_result.resultid
|
|
|
|
);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-06-12 18:33:11 +00:00
|
|
|
if (config.debug_send_job) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[send_job] [RESULT#%lu] score: %f\n",
|
2014-06-12 18:33:11 +00:00
|
|
|
wu_result.resultid, job.score
|
|
|
|
);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
jobs.push_back(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(jobs.begin(), jobs.end(), job_compare);
|
|
|
|
|
|
|
|
bool sema_locked = false;
|
|
|
|
for (unsigned int i=0; i<jobs.size(); i++) {
|
2014-09-16 18:07:36 +00:00
|
|
|
|
|
|
|
// check limit on total jobs
|
|
|
|
//
|
2013-05-22 03:14:39 +00:00
|
|
|
if (!work_needed(false)) {
|
|
|
|
break;
|
|
|
|
}
|
2014-09-16 18:07:36 +00:00
|
|
|
|
|
|
|
// check limit on jobs for this processor type
|
|
|
|
//
|
2013-05-22 03:14:39 +00:00
|
|
|
if (!g_wreq->need_proc_type(rt)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
JOB& job = jobs[i];
|
2014-09-16 18:07:36 +00:00
|
|
|
|
|
|
|
// check limits on jobs for this (app, processor type)
|
|
|
|
//
|
|
|
|
if (config.max_jobs_in_progress.exceeded(job.app, job.bavp->host_usage.proc_type)) {
|
|
|
|
if (config.debug_quota) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[quota] limit for app/proctype exceeded\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-04-10 05:58:18 +00:00
|
|
|
// check daily limit for (host, app version)
|
|
|
|
//
|
|
|
|
if (daily_quota_exceeded(job.bavp)) {
|
|
|
|
if (config.debug_quota) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"[quota] daily host/app version quota now exceeded\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-09 18:10:50 +00:00
|
|
|
if (!sema_locked) {
|
|
|
|
lock_sema();
|
|
|
|
sema_locked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the job is still in the cache
|
|
|
|
// array is locked at this point.
|
|
|
|
//
|
|
|
|
WU_RESULT& wu_result = ssp->wu_results[job.index];
|
2014-06-13 07:30:03 +00:00
|
|
|
if (wu_result.state != WR_STATE_PRESENT && wu_result.state != g_pid) {
|
2013-04-09 18:10:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (wu_result.resultid != job.result_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WORKUNIT wu = wu_result.workunit;
|
|
|
|
int retval = wu_is_infeasible_fast(
|
|
|
|
wu,
|
|
|
|
wu_result.res_server_state, wu_result.res_priority,
|
|
|
|
wu_result.res_report_deadline,
|
|
|
|
*job.app,
|
|
|
|
*job.bavp
|
|
|
|
);
|
|
|
|
|
|
|
|
if (retval) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wu_result.state = g_pid;
|
|
|
|
|
|
|
|
// It passed fast checks.
|
2013-12-10 22:00:31 +00:00
|
|
|
// Release sema and do slow checks
|
|
|
|
//
|
2013-04-09 18:10:50 +00:00
|
|
|
unlock_sema();
|
|
|
|
sema_locked = false;
|
|
|
|
|
|
|
|
switch (slow_check(wu_result, job.app, job.bavp)) {
|
2017-07-22 07:48:38 +00:00
|
|
|
case CHECK_NO_HOST:
|
2013-04-09 18:10:50 +00:00
|
|
|
wu_result.state = WR_STATE_PRESENT;
|
|
|
|
break;
|
2017-07-22 07:48:38 +00:00
|
|
|
case CHECK_NO_ANY:
|
2013-04-09 18:10:50 +00:00
|
|
|
wu_result.state = WR_STATE_EMPTY;
|
2017-07-22 07:48:38 +00:00
|
|
|
if (config.keyword_sched) {
|
|
|
|
keyword_sched_remove_job(job.index);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// slow_check() refreshes fields of wu_result.workunit;
|
|
|
|
// update our copy too
|
|
|
|
//
|
|
|
|
wu.hr_class = wu_result.workunit.hr_class;
|
|
|
|
wu.app_version_id = wu_result.workunit.app_version_id;
|
|
|
|
|
|
|
|
// mark slot as empty AFTER we've copied out of it
|
|
|
|
// (since otherwise feeder might overwrite it)
|
|
|
|
//
|
|
|
|
wu_result.state = WR_STATE_EMPTY;
|
2017-07-28 06:36:32 +00:00
|
|
|
if (config.keyword_sched) {
|
|
|
|
keyword_sched_remove_job(job.index);
|
|
|
|
}
|
2013-04-09 18:10:50 +00:00
|
|
|
|
|
|
|
// reread result from DB, make sure it's still unsent
|
|
|
|
// TODO: from here to end of add_result_to_reply()
|
|
|
|
// (which updates the DB record) should be a transaction
|
|
|
|
//
|
|
|
|
SCHED_DB_RESULT result;
|
|
|
|
result.id = wu_result.resultid;
|
|
|
|
if (result_still_sendable(result, wu)) {
|
|
|
|
add_result_to_reply(result, wu, job.bavp, false);
|
|
|
|
|
|
|
|
// add_result_to_reply() fails only in pathological cases -
|
|
|
|
// e.g. we couldn't update the DB record or modify XML fields.
|
|
|
|
// If this happens, don't replace the record in the array
|
|
|
|
// (we can't anyway, since we marked the entry as "empty").
|
|
|
|
// The feeder will eventually pick it up again,
|
|
|
|
// and hopefully the problem won't happen twice.
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sema_locked) {
|
|
|
|
unlock_sema();
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_others(rt);
|
2013-04-10 22:52:53 +00:00
|
|
|
g_wreq->best_app_versions.clear();
|
2013-04-09 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void send_work_score() {
|
2014-09-22 04:08:09 +00:00
|
|
|
for (int i=NPROC_TYPES-1; i>= 0; i--) {
|
2013-04-09 18:10:50 +00:00
|
|
|
if (g_wreq->need_proc_type(i)) {
|
|
|
|
send_work_score_type(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|