2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-02-24 21:25:16 +00:00
|
|
|
// High-level logic for communicating with scheduling servers,
|
2002-07-15 05:34:32 +00:00
|
|
|
// and for merging the result of a scheduler RPC into the client state
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2004-01-30 22:19:19 +00:00
|
|
|
// The scheduler RPC mechanism is in scheduler_op.C
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
2004-01-08 00:27:59 +00:00
|
|
|
#include <strings.h>
|
2005-04-13 18:38:55 +00:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2004-01-10 06:40:46 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "file_names.h"
|
2002-08-22 21:47:19 +00:00
|
|
|
#include "filesys.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-02-24 21:25:16 +00:00
|
|
|
#include "util.h"
|
2003-02-21 01:38:16 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "scheduler_op.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "client_state.h"
|
|
|
|
|
2004-07-02 03:20:17 +00:00
|
|
|
using std::max;
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
static double trs;
|
|
|
|
|
2005-02-08 21:12:41 +00:00
|
|
|
//#define DEBUG_SCHED 1
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// quantities like avg CPU time decay by a factor of e every week
|
2002-07-15 05:34:32 +00:00
|
|
|
//
|
2003-02-24 21:25:16 +00:00
|
|
|
#define EXP_DECAY_RATE (1./(SECONDS_PER_DAY*7))
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-06-18 22:56:46 +00:00
|
|
|
// how often to show user "backing off" messages
|
|
|
|
//
|
2003-07-03 00:48:43 +00:00
|
|
|
const int SECONDS_BEFORE_REPORTING_MIN_RPC_TIME_AGAIN = 60*60;
|
|
|
|
|
2004-03-17 02:06:09 +00:00
|
|
|
|
2004-06-18 22:56:46 +00:00
|
|
|
// try to report results this much before their deadline
|
2004-05-05 21:15:34 +00:00
|
|
|
//
|
2004-06-18 22:56:46 +00:00
|
|
|
#define REPORT_DEADLINE_CUSHION SECONDS_PER_DAY
|
2003-08-07 23:08:15 +00:00
|
|
|
|
2005-04-13 18:38:55 +00:00
|
|
|
// try to maintain no more than this load factor on the CPU.
|
|
|
|
//
|
|
|
|
#define MAX_CPU_LOAD_FACTOR 0.8
|
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
static int proj_min_results(PROJECT* p, int ncpus) {
|
|
|
|
return (int)(ceil(ncpus*p->resource_share/trs));
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-10-25 20:16:30 +00:00
|
|
|
void PROJECT::set_min_rpc_time(double future_time) {
|
2005-04-13 23:28:47 +00:00
|
|
|
if (future_time > min_rpc_time) {
|
|
|
|
min_rpc_time = future_time;
|
|
|
|
}
|
2004-10-25 20:16:30 +00:00
|
|
|
min_report_min_rpc_time = 0;
|
2003-07-03 00:48:43 +00:00
|
|
|
}
|
|
|
|
|
2003-08-01 21:50:09 +00:00
|
|
|
// Return true iff we should not contact the project yet.
|
|
|
|
// Print a message to the user if we haven't recently
|
|
|
|
//
|
2004-10-25 20:16:30 +00:00
|
|
|
bool PROJECT::waiting_until_min_rpc_time(double now) {
|
2003-07-03 00:48:43 +00:00
|
|
|
if (min_rpc_time > now ) {
|
|
|
|
if (now >= min_report_min_rpc_time) {
|
|
|
|
min_report_min_rpc_time = now + SECONDS_BEFORE_REPORTING_MIN_RPC_TIME_AGAIN;
|
2003-08-01 21:50:09 +00:00
|
|
|
msg_printf(
|
|
|
|
this, MSG_ERROR,
|
|
|
|
"Deferring communication with project for %s\n",
|
|
|
|
timediff_format(min_rpc_time - now).c_str()
|
|
|
|
);
|
2003-07-03 00:48:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-12-27 03:58:11 +00:00
|
|
|
// find a project that needs to have its master file fetched
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
PROJECT* CLIENT_STATE::next_project_master_pending() {
|
|
|
|
unsigned int i;
|
|
|
|
PROJECT* p;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
2003-07-03 00:48:43 +00:00
|
|
|
if (p->waiting_until_min_rpc_time(now)) continue;
|
2004-12-27 03:58:11 +00:00
|
|
|
if (p->suspended_via_gui) continue;
|
2002-07-15 05:34:32 +00:00
|
|
|
if (p->master_url_fetch_pending) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-13 23:02:45 +00:00
|
|
|
// find a project that needs to contact its scheduling server
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2003-02-13 23:02:45 +00:00
|
|
|
PROJECT* CLIENT_STATE::next_project_sched_rpc_pending() {
|
|
|
|
unsigned int i;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2004-12-27 03:58:11 +00:00
|
|
|
PROJECT* p;
|
2003-02-13 23:02:45 +00:00
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
2004-12-27 03:58:11 +00:00
|
|
|
p = projects[i];
|
|
|
|
if (p->waiting_until_min_rpc_time(now)) continue;
|
|
|
|
if (p->suspended_via_gui) continue;
|
|
|
|
if (p->sched_rpc_pending) {
|
|
|
|
return p;
|
2003-02-13 23:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-22 22:09:54 +00:00
|
|
|
// return the next project after "old" that
|
|
|
|
// 1) is eligible for a scheduler RPC
|
|
|
|
// 2) has work_request > 0
|
|
|
|
// 3) has master_url_fetch_pending == false
|
2004-12-30 03:03:26 +00:00
|
|
|
// 4) has dont_request_more_work == false
|
2004-06-30 01:10:22 +00:00
|
|
|
//
|
2004-09-22 22:09:54 +00:00
|
|
|
PROJECT* CLIENT_STATE::next_project_need_work(PROJECT *old) {
|
2005-04-13 18:38:55 +00:00
|
|
|
PROJECT *p, *p_prospect = NULL;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2004-06-30 01:10:22 +00:00
|
|
|
unsigned int i;
|
2004-07-14 20:55:26 +00:00
|
|
|
bool found_old = (old == 0);
|
2004-06-30 01:10:22 +00:00
|
|
|
for (i=0; i<projects.size(); ++i) {
|
|
|
|
p = projects[i];
|
2004-07-24 01:25:10 +00:00
|
|
|
if (p == old) {
|
|
|
|
found_old = true;
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-30 01:10:22 +00:00
|
|
|
if (p->master_url_fetch_pending) continue;
|
|
|
|
if (p->waiting_until_min_rpc_time(now)) continue;
|
2004-12-27 03:58:11 +00:00
|
|
|
if (p->suspended_via_gui) continue;
|
2004-12-30 03:03:26 +00:00
|
|
|
if (p->dont_request_more_work) continue;
|
2005-04-13 18:38:55 +00:00
|
|
|
if (p->long_term_debt < 0 && !no_work_for_a_cpu()) continue;
|
|
|
|
if (p_prospect && p->long_term_debt < p_prospect->long_term_debt && !p->non_cpu_intensive) continue;
|
2004-06-30 01:10:22 +00:00
|
|
|
if (found_old && p->work_request > 0) {
|
2005-04-13 18:38:55 +00:00
|
|
|
p_prospect = p;
|
2004-06-30 01:10:22 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-13 18:38:55 +00:00
|
|
|
return p_prospect;
|
2004-06-30 01:10:22 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-09-22 22:09:54 +00:00
|
|
|
// Write a scheduler request to a disk file
|
|
|
|
// (later sent to the scheduling server)
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-07-15 05:34:32 +00:00
|
|
|
int CLIENT_STATE::make_scheduler_request(PROJECT* p, double work_req) {
|
2004-09-22 22:09:54 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
get_sched_request_filename(*p, buf);
|
|
|
|
FILE* f = boinc_fopen(buf, "wb");
|
2004-06-12 04:45:36 +00:00
|
|
|
MIOFILE mf;
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
RESULT* rp;
|
2003-03-08 23:48:05 +00:00
|
|
|
int retval;
|
2004-08-11 15:50:51 +00:00
|
|
|
#if 0
|
|
|
|
double free, possible;
|
|
|
|
#endif
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
trs = total_resource_share();
|
2004-07-06 21:51:49 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2004-06-12 04:45:36 +00:00
|
|
|
mf.init_file(f);
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<scheduler_request>\n"
|
|
|
|
" <authenticator>%s</authenticator>\n"
|
|
|
|
" <hostid>%d</hostid>\n"
|
|
|
|
" <rpc_seqno>%d</rpc_seqno>\n"
|
|
|
|
" <platform_name>%s</platform_name>\n"
|
2002-12-01 06:14:28 +00:00
|
|
|
" <core_client_major_version>%d</core_client_major_version>\n"
|
|
|
|
" <core_client_minor_version>%d</core_client_minor_version>\n"
|
2004-07-06 23:27:19 +00:00
|
|
|
" <work_req_seconds>%f</work_req_seconds>\n"
|
2004-07-14 20:55:26 +00:00
|
|
|
" <resource_share_fraction>%f</resource_share_fraction>\n"
|
2004-10-01 08:15:58 +00:00
|
|
|
" <estimated_delay>%f</estimated_delay>\n",
|
2002-04-30 22:22:54 +00:00
|
|
|
p->authenticator,
|
|
|
|
p->hostid,
|
|
|
|
p->rpc_seqno,
|
2005-04-13 23:28:47 +00:00
|
|
|
p->anonymous_platform?"anonymous":platform_name,
|
2002-12-01 06:14:28 +00:00
|
|
|
core_client_major_version,
|
|
|
|
core_client_minor_version,
|
2004-07-06 21:51:49 +00:00
|
|
|
work_req,
|
2004-07-14 20:55:26 +00:00
|
|
|
p->resource_share / trs,
|
2004-10-01 08:15:58 +00:00
|
|
|
ettprc(p, proj_min_results(p, ncpus)-1)
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2005-04-13 23:28:47 +00:00
|
|
|
if (p->anonymous_platform) {
|
|
|
|
fprintf(f, " <app_versions>\n");
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
APP_VERSION* avp = app_versions[i];
|
|
|
|
if (avp->project != p) continue;
|
|
|
|
avp->write(mf);
|
|
|
|
}
|
|
|
|
fprintf(f, " </app_versions>\n");
|
|
|
|
}
|
2004-08-11 15:50:51 +00:00
|
|
|
#if 0
|
2004-08-06 21:54:40 +00:00
|
|
|
anything_free(free);
|
|
|
|
fprintf(f, " <project_disk_free>%f</project_disk_free>\n", free);
|
|
|
|
total_potential_offender(p, possible);
|
|
|
|
fprintf(f, " <potentially_free_offender>%f</potentially_free_offender>\n", possible);
|
|
|
|
total_potential_self(p, possible);
|
|
|
|
fprintf(f, " <potentially_free_self>%f</potentially_free_self>\n", possible);
|
2004-08-11 15:50:51 +00:00
|
|
|
#endif
|
2003-02-11 19:41:08 +00:00
|
|
|
if (strlen(p->code_sign_key)) {
|
2004-08-05 21:42:26 +00:00
|
|
|
fprintf(f, " <code_sign_key>\n%s</code_sign_key>\n", p->code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// insert global preferences if present
|
|
|
|
//
|
2004-03-01 19:11:12 +00:00
|
|
|
if (boinc_file_exists(GLOBAL_PREFS_FILE_NAME)) {
|
|
|
|
FILE* fprefs = fopen(GLOBAL_PREFS_FILE_NAME, "r");
|
|
|
|
if (fprefs) {
|
|
|
|
copy_stream(fprefs, f);
|
|
|
|
fclose(fprefs);
|
|
|
|
}
|
2004-10-06 19:09:37 +00:00
|
|
|
PROJECT* pp = lookup_project(global_prefs.source_project);
|
2004-05-03 02:18:35 +00:00
|
|
|
if (pp && strlen(pp->email_hash)) {
|
|
|
|
fprintf(f,
|
|
|
|
"<global_prefs_source_email_hash>%s</global_prefs_source_email_hash>\n",
|
|
|
|
pp->email_hash
|
|
|
|
);
|
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-02-08 21:12:41 +00:00
|
|
|
// Of the projects with same email hash as this one,
|
|
|
|
// send the oldest cross-project ID.
|
|
|
|
// Use project URL as tie-breaker.
|
2004-04-18 18:40:13 +00:00
|
|
|
//
|
2005-02-08 21:12:41 +00:00
|
|
|
PROJECT* winner = p;
|
2004-04-18 18:40:13 +00:00
|
|
|
for (i=0; i<projects.size(); i++ ) {
|
|
|
|
PROJECT* project = projects[i];
|
|
|
|
if (project == p) continue;
|
|
|
|
if (strcmp(project->email_hash, p->email_hash)) continue;
|
2005-02-08 21:12:41 +00:00
|
|
|
if (project->user_create_time < winner->user_create_time) {
|
|
|
|
winner = project;
|
|
|
|
} else if (project->user_create_time == winner->user_create_time) {
|
|
|
|
if (strcmp(project->master_url, winner->master_url) < 0) {
|
|
|
|
winner = project;
|
|
|
|
}
|
2004-04-18 18:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-08 21:12:41 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<cross_project_id>%s</cross_project_id>\n",
|
|
|
|
winner->cross_project_id
|
|
|
|
);
|
2004-04-18 18:40:13 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
retval = time_stats.write(mf, true);
|
2003-03-08 23:48:05 +00:00
|
|
|
if (retval) return retval;
|
2004-09-22 21:08:26 +00:00
|
|
|
retval = net_stats.write(mf);
|
2003-03-08 23:48:05 +00:00
|
|
|
if (retval) return retval;
|
2004-06-12 04:45:36 +00:00
|
|
|
retval = host_info.write(mf);
|
2003-03-08 23:48:05 +00:00
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2003-02-06 19:01:49 +00:00
|
|
|
rp = results[i];
|
2003-09-23 23:19:41 +00:00
|
|
|
if (rp->project == p && rp->ready_to_report) {
|
2004-06-12 04:45:36 +00:00
|
|
|
rp->write(mf, true);
|
2003-06-18 23:41:31 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-07-06 17:37:58 +00:00
|
|
|
|
2004-01-08 00:27:59 +00:00
|
|
|
read_trickle_files(p, f);
|
2004-09-10 00:41:48 +00:00
|
|
|
|
|
|
|
// report sticky files as needed
|
|
|
|
//
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
FILE_INFO* fip = file_infos[i];
|
|
|
|
if (fip->project != p) continue;
|
|
|
|
if (!fip->report_on_rpc) continue;
|
2005-01-31 23:42:19 +00:00
|
|
|
if (fip->marked_for_delete) continue;
|
2004-09-10 00:41:48 +00:00
|
|
|
fprintf(f,
|
|
|
|
" <file_info>\n"
|
|
|
|
" <name>%s</name>\n"
|
2005-01-28 20:03:57 +00:00
|
|
|
" <nbytes>%f</nbytes>\n"
|
|
|
|
" <status>%d</status>\n"
|
2004-09-10 21:02:11 +00:00
|
|
|
" <report_on_rpc/>\n"
|
2004-09-10 00:41:48 +00:00
|
|
|
" </file_info>\n",
|
2005-01-28 20:03:57 +00:00
|
|
|
fip->name, fip->nbytes, fip->status
|
2004-09-10 00:41:48 +00:00
|
|
|
);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(f, "</scheduler_request>\n");
|
2004-07-06 17:37:58 +00:00
|
|
|
|
2004-07-06 18:31:56 +00:00
|
|
|
fclose(f);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// find a project with results that are overdue to report,
|
|
|
|
// and which we're allowed to contact.
|
|
|
|
//
|
2004-06-18 22:56:46 +00:00
|
|
|
PROJECT* CLIENT_STATE::find_project_with_overdue_results() {
|
2002-07-15 05:34:32 +00:00
|
|
|
unsigned int i;
|
|
|
|
RESULT* r;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
for (i=0; i<results.size(); i++) {
|
2003-02-06 19:01:49 +00:00
|
|
|
r = results[i];
|
2003-08-07 23:08:15 +00:00
|
|
|
// return the project for this result to report if:
|
|
|
|
// - we're not backing off a scheduler request for its project
|
2003-09-23 23:19:41 +00:00
|
|
|
// - we're ready_to_report (compute done; files uploaded)
|
2004-06-18 22:56:46 +00:00
|
|
|
// - we're almost at the report_deadline
|
2003-09-23 23:19:41 +00:00
|
|
|
//
|
|
|
|
|
2004-12-27 03:58:11 +00:00
|
|
|
PROJECT* p = r->project;
|
|
|
|
if (p->waiting_until_min_rpc_time(now)) continue;
|
|
|
|
if (p->suspended_via_gui) continue;
|
2003-09-23 23:19:41 +00:00
|
|
|
|
2004-06-18 22:56:46 +00:00
|
|
|
if (!r->ready_to_report) continue;
|
2004-06-18 23:25:48 +00:00
|
|
|
if (return_results_immediately ||
|
|
|
|
(r->report_deadline <= (now + REPORT_DEADLINE_CUSHION))
|
|
|
|
) {
|
2004-12-27 03:58:11 +00:00
|
|
|
return p;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2002-07-15 05:34:32 +00:00
|
|
|
}
|
2003-02-06 01:02:56 +00:00
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-10 20:46:33 +00:00
|
|
|
#if 0
|
2002-07-15 05:34:32 +00:00
|
|
|
// return true if we're allowed to do a scheduler RPC to at least one project
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::some_project_rpc_ok() {
|
|
|
|
unsigned int i;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
if (projects[i]->min_rpc_time < now) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-10 20:46:33 +00:00
|
|
|
#endif
|
2002-07-15 05:34:32 +00:00
|
|
|
|
2005-02-06 21:26:21 +00:00
|
|
|
// return the expected number of CPU seconds completed by the client
|
|
|
|
// for project p in a second of wall-clock time.
|
|
|
|
// May be > 1 on a multiprocessor.
|
2004-06-30 01:10:22 +00:00
|
|
|
//
|
2004-07-14 20:55:26 +00:00
|
|
|
double CLIENT_STATE::avg_proc_rate(PROJECT *p) {
|
2005-02-06 21:26:21 +00:00
|
|
|
double running_frac = time_stats.on_frac * time_stats.active_frac;
|
|
|
|
if (running_frac < 0.1) running_frac = 0.1;
|
|
|
|
if (running_frac > 1) running_frac = 1;
|
2005-04-13 23:28:47 +00:00
|
|
|
return (p ? (p->resource_share / trs) : 1) * ncpus * running_frac;
|
2004-07-14 20:55:26 +00:00
|
|
|
}
|
2004-06-30 01:10:22 +00:00
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
// "estimated time to project result count"
|
2005-02-06 21:26:21 +00:00
|
|
|
// return the estimated wall-clock time until the
|
2004-07-14 20:55:26 +00:00
|
|
|
// number of results for project p will reach k
|
|
|
|
//
|
|
|
|
double CLIENT_STATE::ettprc(PROJECT *p, int k) {
|
|
|
|
int num_results_to_skip = k;
|
|
|
|
double est = 0;
|
|
|
|
|
|
|
|
// total up the estimated time for this project's unstarted
|
|
|
|
// and partially completed results,
|
|
|
|
// omitting the last k
|
|
|
|
//
|
|
|
|
for (vector<RESULT*>::reverse_iterator iter = results.rbegin();
|
|
|
|
iter != results.rend(); iter++
|
|
|
|
) {
|
|
|
|
RESULT *rp = *iter;
|
|
|
|
if (rp->project != p
|
2004-10-07 19:18:37 +00:00
|
|
|
|| rp->state > RESULT_FILES_DOWNLOADED
|
2004-07-14 20:55:26 +00:00
|
|
|
|| rp->ready_to_report
|
|
|
|
) continue;
|
|
|
|
if (num_results_to_skip > 0) {
|
|
|
|
--num_results_to_skip;
|
|
|
|
continue;
|
|
|
|
}
|
2004-10-20 21:11:29 +00:00
|
|
|
est += rp->estimated_cpu_time_remaining();
|
2004-06-30 01:10:22 +00:00
|
|
|
}
|
2005-02-08 21:12:41 +00:00
|
|
|
double apr = avg_proc_rate(p);
|
|
|
|
return est/apr;
|
2004-07-14 20:55:26 +00:00
|
|
|
}
|
2004-06-30 01:10:22 +00:00
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
// set work_request for each project and return the urgency level for
|
|
|
|
// requesting more work
|
|
|
|
// only set non-zero work requests for projects that are allowed to do
|
|
|
|
// a scheduler RPC
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::compute_work_requests() {
|
|
|
|
int urgency = DONT_NEED_WORK;
|
|
|
|
unsigned int i;
|
|
|
|
double work_min_period = global_prefs.work_buf_min_days * SECONDS_PER_DAY;
|
2004-10-25 20:16:30 +00:00
|
|
|
double now = dtime();
|
2004-07-14 20:55:26 +00:00
|
|
|
|
|
|
|
trs = total_resource_share();
|
|
|
|
|
|
|
|
// for each project, compute
|
|
|
|
// min_results = min # of results for project needed by CPU scheduling,
|
|
|
|
// to avoid "starvation".
|
|
|
|
// Then estimate how long it's going to be until we have fewer
|
|
|
|
// than this # of results remaining.
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); ++i) {
|
2004-06-30 01:10:22 +00:00
|
|
|
PROJECT *p = projects[i];
|
2004-07-14 20:55:26 +00:00
|
|
|
|
2004-06-30 01:10:22 +00:00
|
|
|
p->work_request = 0;
|
2004-07-14 20:55:26 +00:00
|
|
|
if (p->min_rpc_time >= now) continue;
|
2004-12-30 03:03:26 +00:00
|
|
|
if (p->dont_request_more_work) continue;
|
2005-01-10 20:46:33 +00:00
|
|
|
if (p->suspended_via_gui) continue;
|
2005-04-13 18:38:55 +00:00
|
|
|
if (p->long_term_debt < 0 && !no_work_for_a_cpu()) continue;
|
2005-01-10 20:46:33 +00:00
|
|
|
|
|
|
|
int min_results = proj_min_results(p, ncpus);
|
|
|
|
double estimated_time_to_starvation = ettprc(p, min_results-1);
|
2004-06-30 01:10:22 +00:00
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
// determine urgency
|
|
|
|
//
|
|
|
|
if (estimated_time_to_starvation < work_min_period) {
|
|
|
|
if (estimated_time_to_starvation == 0) {
|
2005-02-08 21:12:41 +00:00
|
|
|
#if DEBUG_SCHED
|
|
|
|
msg_printf(p, MSG_INFO, "is starved");
|
|
|
|
#endif
|
2004-07-14 20:55:26 +00:00
|
|
|
urgency = NEED_WORK_IMMEDIATELY;
|
|
|
|
} else {
|
2005-02-08 21:12:41 +00:00
|
|
|
#if DEBUG_SCHED
|
2004-10-14 22:01:05 +00:00
|
|
|
msg_printf(p, MSG_INFO, "will starve in %.2f sec",
|
|
|
|
estimated_time_to_starvation
|
|
|
|
);
|
2004-10-14 22:21:35 +00:00
|
|
|
#endif
|
2004-07-14 20:55:26 +00:00
|
|
|
urgency = max(NEED_WORK, urgency);
|
2004-06-30 01:10:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 20:55:26 +00:00
|
|
|
// determine work requests for each project
|
2004-10-14 22:01:05 +00:00
|
|
|
// NOTE: don't need to divide by active_frac etc.;
|
|
|
|
// the scheduler does that (see sched/sched_send.C)
|
2004-07-14 20:55:26 +00:00
|
|
|
//
|
2004-10-14 22:01:05 +00:00
|
|
|
p->work_request = max(0.0,
|
|
|
|
//(2*work_min_period - estimated_time_to_starvation)
|
|
|
|
(work_min_period - estimated_time_to_starvation)
|
|
|
|
* ncpus
|
|
|
|
);
|
2005-02-08 21:12:41 +00:00
|
|
|
#if DEBUG_SCHED
|
|
|
|
msg_printf(p, MSG_INFO, "work req: %f sec", p->work_request);
|
|
|
|
#endif
|
2004-07-14 20:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (urgency == DONT_NEED_WORK) {
|
|
|
|
for (i=0; i<projects.size(); ++i) {
|
|
|
|
projects[i]->work_request = 0;
|
2004-06-30 01:10:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return urgency;
|
|
|
|
}
|
|
|
|
|
2002-07-15 05:34:32 +00:00
|
|
|
// called from the client's polling loop.
|
|
|
|
// initiate scheduler RPC activity if needed and possible
|
|
|
|
//
|
2004-10-14 22:01:05 +00:00
|
|
|
bool CLIENT_STATE::scheduler_rpc_poll(double now) {
|
2004-07-14 20:55:26 +00:00
|
|
|
int urgency = DONT_NEED_WORK;
|
|
|
|
PROJECT *p;
|
|
|
|
bool action=false;
|
2004-10-14 22:01:05 +00:00
|
|
|
static double last_time=0;
|
|
|
|
|
|
|
|
if (now - last_time < 1.0) return false;
|
|
|
|
last_time = now;
|
2002-07-15 05:34:32 +00:00
|
|
|
|
|
|
|
switch(scheduler_op->state) {
|
|
|
|
case SCHEDULER_OP_STATE_IDLE:
|
2004-08-05 21:42:26 +00:00
|
|
|
if (network_suspended) break;
|
2005-04-13 23:28:47 +00:00
|
|
|
if (should_get_work()) {
|
|
|
|
urgency = compute_work_requests();
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
2004-07-14 20:55:26 +00:00
|
|
|
|
|
|
|
// highest priority is to report overdue results
|
|
|
|
//
|
|
|
|
p = find_project_with_overdue_results();
|
|
|
|
if (p) {
|
2004-09-22 22:09:54 +00:00
|
|
|
scheduler_op->init_return_results(p);
|
2004-07-14 20:55:26 +00:00
|
|
|
action = true;
|
|
|
|
} else if (!(exit_when_idle && contacted_sched_server) && urgency != DONT_NEED_WORK) {
|
|
|
|
if (urgency == NEED_WORK) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2004-08-05 09:35:30 +00:00
|
|
|
"May run out of work in %.2f days; requesting more",
|
2004-07-14 20:55:26 +00:00
|
|
|
global_prefs.work_buf_min_days
|
|
|
|
);
|
|
|
|
} else if (urgency == NEED_WORK_IMMEDIATELY) {
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
scheduler_op->init_get_work(false);
|
2003-02-13 23:02:45 +00:00
|
|
|
action = true;
|
2003-02-14 08:22:55 +00:00
|
|
|
} else if ((p=next_project_master_pending())) {
|
2005-04-13 18:38:55 +00:00
|
|
|
scheduler_op->init_get_work(true);
|
2003-02-13 23:02:45 +00:00
|
|
|
action = true;
|
2003-02-14 08:22:55 +00:00
|
|
|
} else if ((p=next_project_sched_rpc_pending())) {
|
2004-09-22 22:09:54 +00:00
|
|
|
scheduler_op->init_return_results(p);
|
2002-07-15 05:34:32 +00:00
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
scheduler_op->poll();
|
|
|
|
if (scheduler_op->state == SCHEDULER_OP_STATE_IDLE) {
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Handle the reply from a scheduler
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2003-01-02 23:12:05 +00:00
|
|
|
int CLIENT_STATE::handle_scheduler_reply(
|
|
|
|
PROJECT* project, char* scheduler_url, int& nresults
|
2002-07-15 05:34:32 +00:00
|
|
|
) {
|
2002-04-30 22:22:54 +00:00
|
|
|
SCHEDULER_REPLY sr;
|
|
|
|
FILE* f;
|
|
|
|
int retval;
|
|
|
|
unsigned int i;
|
2004-10-01 08:15:58 +00:00
|
|
|
bool signature_valid, update_global_prefs=false, update_project_prefs=false;
|
2004-09-22 22:09:54 +00:00
|
|
|
char buf[256], filename[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-01-02 23:12:05 +00:00
|
|
|
nresults = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
contacted_sched_server = true;
|
2004-04-08 08:15:23 +00:00
|
|
|
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCHED_OP);
|
2003-07-02 02:02:18 +00:00
|
|
|
|
2004-09-22 22:09:54 +00:00
|
|
|
get_sched_reply_filename(*project, filename);
|
|
|
|
scope_messages.printf_file(filename, "reply: ");
|
|
|
|
|
|
|
|
f = fopen(filename, "r");
|
2003-01-02 23:12:05 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2003-07-03 05:01:29 +00:00
|
|
|
retval = sr.parse(f, project);
|
2002-08-29 04:19:51 +00:00
|
|
|
fclose(f);
|
2003-02-08 00:22:38 +00:00
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-01-31 22:19:03 +00:00
|
|
|
for (i=0; i<sr.messages.size(); i++) {
|
|
|
|
USER_MESSAGE& um = sr.messages[i];
|
|
|
|
sprintf(buf, "Message from server: %s", um.message.c_str());
|
|
|
|
int prio = (!strcmp(um.priority.c_str(), "high"))?MSG_ERROR:MSG_INFO;
|
2003-12-02 22:47:32 +00:00
|
|
|
show_message(project, buf, prio);
|
2002-05-17 22:33:57 +00:00
|
|
|
}
|
|
|
|
|
2004-06-22 22:56:50 +00:00
|
|
|
// if project is down, return error (so that we back off)
|
|
|
|
// and don't do anything else
|
|
|
|
//
|
|
|
|
if (sr.project_is_down) {
|
|
|
|
return ERR_PROJECT_DOWN;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
|
2005-03-03 23:49:49 +00:00
|
|
|
// The project returns a hostid only if it has created a new host record.
|
|
|
|
// In that case we should reset RPC seqno
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
if (sr.hostid) {
|
2004-10-01 08:15:58 +00:00
|
|
|
project->hostid = sr.hostid;
|
2002-04-30 22:22:54 +00:00
|
|
|
project->rpc_seqno = 0;
|
2004-10-01 08:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see if we have a new venue from this project
|
|
|
|
//
|
2005-04-13 23:28:47 +00:00
|
|
|
if (strlen(sr.host_venue) && strcmp(project->host_venue, sr.host_venue)) {
|
2004-10-01 08:15:58 +00:00
|
|
|
safe_strcpy(project->host_venue, sr.host_venue);
|
|
|
|
msg_printf(project, MSG_INFO, "New host venue: %s", sr.host_venue);
|
|
|
|
update_project_prefs = true;
|
|
|
|
if (project == global_prefs_source_project()) {
|
|
|
|
strcpy(main_host_venue, sr.host_venue);
|
|
|
|
update_global_prefs = true;
|
2004-08-12 13:36:05 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// if the scheduler reply includes global preferences,
|
|
|
|
// insert extra elements, write to disk, and parse
|
2002-06-21 06:52:47 +00:00
|
|
|
//
|
2002-09-29 00:32:11 +00:00
|
|
|
if (sr.global_prefs_xml) {
|
2003-12-24 00:50:51 +00:00
|
|
|
f = boinc_fopen(GLOBAL_PREFS_FILE_NAME, "w");
|
2003-01-02 23:12:05 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2002-06-21 06:52:47 +00:00
|
|
|
fprintf(f,
|
2002-09-29 00:32:11 +00:00
|
|
|
"<global_preferences>\n"
|
2004-03-23 01:44:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// tag with the project and scheduler URL,
|
|
|
|
// but only if not already tagged
|
|
|
|
//
|
|
|
|
if (!strstr(sr.global_prefs_xml, "<source_project>")) {
|
|
|
|
fprintf(f,
|
|
|
|
" <source_project>%s</source_project>\n"
|
|
|
|
" <source_scheduler>%s</source_scheduler>\n",
|
|
|
|
project->master_url,
|
|
|
|
scheduler_url
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fprintf(f,
|
2002-09-29 00:32:11 +00:00
|
|
|
"%s"
|
|
|
|
"</global_preferences>\n",
|
|
|
|
sr.global_prefs_xml
|
2002-06-21 06:52:47 +00:00
|
|
|
);
|
2003-08-14 00:02:15 +00:00
|
|
|
fclose(f);
|
2005-04-13 23:28:47 +00:00
|
|
|
update_global_prefs = true;
|
|
|
|
}
|
2003-08-13 20:00:20 +00:00
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
if (update_global_prefs) {
|
2004-03-30 23:05:34 +00:00
|
|
|
bool found_venue;
|
|
|
|
retval = global_prefs.parse_file(
|
2004-10-01 08:15:58 +00:00
|
|
|
GLOBAL_PREFS_FILE_NAME, project->host_venue, found_venue
|
2004-03-30 23:05:34 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
2004-08-12 12:44:55 +00:00
|
|
|
msg_printf(project, MSG_ERROR, "Can't parse general preferences");
|
2004-03-30 23:05:34 +00:00
|
|
|
} else {
|
|
|
|
show_global_prefs_source(found_venue);
|
|
|
|
install_global_prefs();
|
|
|
|
}
|
2002-09-29 00:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deal with project preferences (should always be there)
|
2003-11-28 19:19:11 +00:00
|
|
|
// If they've changed, write to account file,
|
|
|
|
// then parse to get our venue, and pass to running apps
|
2002-09-29 00:32:11 +00:00
|
|
|
//
|
|
|
|
if (sr.project_prefs_xml) {
|
2003-11-28 19:19:11 +00:00
|
|
|
if (strcmp(project->project_prefs.c_str(), sr.project_prefs_xml)) {
|
|
|
|
project->project_prefs = string(sr.project_prefs_xml);
|
2004-10-01 08:15:58 +00:00
|
|
|
update_project_prefs = true;
|
2003-05-20 00:03:39 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-10-01 08:15:58 +00:00
|
|
|
if (update_project_prefs) {
|
2004-10-01 18:48:34 +00:00
|
|
|
retval = project->write_account_file();
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR, "Can't write account file: %d", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
2004-10-01 08:15:58 +00:00
|
|
|
project->parse_account_file();
|
|
|
|
project->parse_preferences_for_user_files();
|
|
|
|
active_tasks.request_reread_prefs(project);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-07 20:39:24 +00:00
|
|
|
// if the scheduler reply includes a code-signing key,
|
|
|
|
// accept it if we don't already have one from the project.
|
|
|
|
// Otherwise verify its signature, using the key we already have.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (sr.code_sign_key) {
|
2003-02-11 00:52:44 +00:00
|
|
|
if (!strlen(project->code_sign_key)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->code_sign_key, sr.code_sign_key);
|
2002-07-07 20:39:24 +00:00
|
|
|
} else {
|
2002-08-25 07:54:33 +00:00
|
|
|
if (sr.code_sign_key_signature) {
|
|
|
|
retval = verify_string2(
|
|
|
|
sr.code_sign_key, sr.code_sign_key_signature,
|
|
|
|
project->code_sign_key, signature_valid
|
|
|
|
);
|
|
|
|
if (!retval && signature_valid) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(project->code_sign_key, sr.code_sign_key);
|
2002-08-25 07:54:33 +00:00
|
|
|
} else {
|
2004-08-12 12:44:55 +00:00
|
|
|
msg_printf(project, MSG_ERROR, "New code signing key doesn't validate");
|
2002-08-25 07:54:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-08-12 12:44:55 +00:00
|
|
|
msg_printf(project, MSG_ERROR, "Missing code sign key signature");
|
2002-08-25 07:54:33 +00:00
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy new entities to client state
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sr.apps.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.apps[i].name);
|
2003-05-20 22:32:03 +00:00
|
|
|
if (!app) {
|
2002-04-30 22:22:54 +00:00
|
|
|
app = new APP;
|
|
|
|
*app = sr.apps[i];
|
|
|
|
retval = link_app(project, app);
|
2004-08-12 12:44:55 +00:00
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't link app %s in sched reply", app->name
|
|
|
|
);
|
|
|
|
delete app;
|
|
|
|
} else {
|
|
|
|
apps.push_back(app);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-06 17:37:58 +00:00
|
|
|
FILE_INFO* fip;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<sr.file_infos.size(); i++) {
|
2004-07-06 17:37:58 +00:00
|
|
|
fip = lookup_file_info(project, sr.file_infos[i].name);
|
2004-08-12 10:13:01 +00:00
|
|
|
if (fip) {
|
2004-07-06 18:31:56 +00:00
|
|
|
fip->merge_info(sr.file_infos[i]);
|
|
|
|
} else {
|
2004-07-06 17:37:58 +00:00
|
|
|
fip = new FILE_INFO;
|
2002-04-30 22:22:54 +00:00
|
|
|
*fip = sr.file_infos[i];
|
2004-09-22 21:08:26 +00:00
|
|
|
retval = link_file_info(project, fip);
|
2004-08-12 12:44:55 +00:00
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't link file_info %s in sched reply", fip->name
|
|
|
|
);
|
|
|
|
delete fip;
|
|
|
|
} else {
|
|
|
|
file_infos.push_back(fip);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-08-05 21:42:26 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<sr.file_deletes.size(); i++) {
|
2005-03-09 23:28:37 +00:00
|
|
|
fip = lookup_file_info(project, sr.file_deletes[i].c_str());
|
2004-08-12 10:13:01 +00:00
|
|
|
if (fip) {
|
2005-01-31 23:42:19 +00:00
|
|
|
msg_printf(project, MSG_INFO, "Got server request to delete file %s\n", fip->name);
|
|
|
|
fip->marked_for_delete = true;
|
2004-08-05 21:42:26 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<sr.app_versions.size(); i++) {
|
|
|
|
APP* app = lookup_app(project, sr.app_versions[i].app_name);
|
2003-05-20 22:32:03 +00:00
|
|
|
APP_VERSION* avp = lookup_app_version(app, sr.app_versions[i].version_num);
|
2004-09-02 16:23:21 +00:00
|
|
|
if (avp) {
|
|
|
|
// if we had download failures, clear them
|
|
|
|
//
|
|
|
|
avp->clear_errors();
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-16 14:30:41 +00:00
|
|
|
avp = new APP_VERSION;
|
|
|
|
*avp = sr.app_versions[i];
|
|
|
|
retval = link_app_version(project, avp);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't link app version %s %d in sched reply",
|
|
|
|
avp->app_name, avp->version_num
|
|
|
|
);
|
|
|
|
delete avp;
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-08-16 14:30:41 +00:00
|
|
|
app_versions.push_back(avp);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<sr.workunits.size(); i++) {
|
2004-08-16 14:30:41 +00:00
|
|
|
if (lookup_workunit(project, sr.workunits[i].name)) continue;
|
|
|
|
WORKUNIT* wup = new WORKUNIT;
|
|
|
|
*wup = sr.workunits[i];
|
|
|
|
int vnum = choose_version_num(wup->app_name, sr);
|
|
|
|
if (vnum < 0) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't find app version for WU %s", wup->name
|
|
|
|
);
|
|
|
|
delete wup;
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-08-16 14:30:41 +00:00
|
|
|
|
|
|
|
wup->version_num = vnum;
|
|
|
|
retval = link_workunit(project, wup);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't link workunit %s in sched reply", wup->name
|
|
|
|
);
|
|
|
|
delete wup;
|
|
|
|
continue;
|
|
|
|
}
|
2005-01-13 18:57:27 +00:00
|
|
|
wup->clear_errors();
|
2004-08-16 14:30:41 +00:00
|
|
|
workunits.push_back(wup);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<sr.results.size(); i++) {
|
2004-08-16 14:30:41 +00:00
|
|
|
if (lookup_result(project, sr.results[i].name)) {
|
2004-08-12 12:44:55 +00:00
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Already have result %s\n", sr.results[i].name
|
|
|
|
);
|
2004-08-16 14:30:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RESULT* rp = new RESULT;
|
|
|
|
*rp = sr.results[i];
|
|
|
|
retval = link_result(project, rp);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_ERROR,
|
|
|
|
"Can't link result %s in sched reply", rp->name
|
|
|
|
);
|
|
|
|
delete rp;
|
|
|
|
continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-08-16 14:30:41 +00:00
|
|
|
results.push_back(rp);
|
|
|
|
rp->state = RESULT_NEW;
|
|
|
|
nresults++;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update records for ack'ed results
|
|
|
|
//
|
|
|
|
for (i=0; i<sr.result_acks.size(); i++) {
|
|
|
|
RESULT* rp = lookup_result(project, sr.result_acks[i].name);
|
2004-11-03 22:13:13 +00:00
|
|
|
scope_messages.printf(
|
|
|
|
"CLIENT_STATE::handle_scheduler_reply(): got ack for result %s\n",
|
|
|
|
sr.result_acks[i].name
|
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (rp) {
|
2003-09-23 23:19:41 +00:00
|
|
|
rp->got_server_ack = true;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2004-08-12 12:44:55 +00:00
|
|
|
msg_printf(project, MSG_ERROR,
|
2004-11-04 19:10:56 +00:00
|
|
|
"Got ack for result %s, can't find", sr.result_acks[i].name
|
2003-06-17 18:59:36 +00:00
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-08 00:27:59 +00:00
|
|
|
|
|
|
|
// remove acked trickle files
|
|
|
|
//
|
2004-07-06 04:01:15 +00:00
|
|
|
if (sr.message_ack) {
|
2004-01-08 00:27:59 +00:00
|
|
|
remove_trickle_files(project);
|
|
|
|
}
|
2004-07-06 18:31:56 +00:00
|
|
|
if (sr.send_file_list) {
|
|
|
|
project->send_file_list = true;
|
|
|
|
}
|
2003-02-13 23:02:45 +00:00
|
|
|
project->sched_rpc_pending = false;
|
2005-01-24 22:13:32 +00:00
|
|
|
|
|
|
|
// handle delay request
|
|
|
|
//
|
|
|
|
if (sr.request_delay) {
|
|
|
|
double x = dtime() + sr.request_delay;
|
|
|
|
if (x > project->min_rpc_time) project->min_rpc_time = x;
|
|
|
|
} else {
|
|
|
|
project->min_rpc_time = 0;
|
|
|
|
}
|
|
|
|
|
2002-08-22 21:29:58 +00:00
|
|
|
set_client_state_dirty("handle_scheduler_reply");
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::handle_scheduler_reply(): State after handle_scheduler_reply():\n");
|
|
|
|
print_summary();
|
2003-01-02 23:12:05 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-04-13 18:38:55 +00:00
|
|
|
bool CLIENT_STATE::should_get_work() {
|
2005-04-13 23:28:47 +00:00
|
|
|
// if there are fewer wus available then CPUS, then we need more work.
|
|
|
|
if (no_work_for_a_cpu()) return true;
|
2005-04-13 18:38:55 +00:00
|
|
|
|
|
|
|
double tot_cpu_time_remaining = 0;
|
|
|
|
for (unsigned int i = 0; i < results.size();++i) {
|
|
|
|
tot_cpu_time_remaining += results[i]->estimated_cpu_time_remaining();
|
|
|
|
}
|
|
|
|
if (tot_cpu_time_remaining < global_prefs.work_buf_min_days * SECONDS_PER_DAY) return true;
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// if the CPU started this time period overloaded,
|
2005-04-14 04:25:56 +00:00
|
|
|
// let it process for a while to get out of the CPU overload state.
|
2005-04-13 23:28:47 +00:00
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
if (!work_fetch_no_new_work) {
|
|
|
|
set_cpu_scheduler_modes();
|
|
|
|
}
|
|
|
|
bool ret = !work_fetch_no_new_work;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPU idle check.
|
|
|
|
bool CLIENT_STATE::no_work_for_a_cpu() {
|
2005-04-13 23:28:47 +00:00
|
|
|
return (unsigned int)ncpus > results.size();
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
|
2005-04-14 04:25:56 +00:00
|
|
|
// decide on the CPU scheduler state
|
2005-04-13 23:28:47 +00:00
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
void CLIENT_STATE::set_cpu_scheduler_modes() {
|
2005-04-14 04:25:56 +00:00
|
|
|
std::map<double, RESULT*> results_by_deadline;
|
|
|
|
std::set<PROJECT*> projects_with_work;
|
2005-04-13 23:28:47 +00:00
|
|
|
|
|
|
|
std::vector<RESULT*>::iterator it_u;
|
2005-04-14 04:25:56 +00:00
|
|
|
for (it_u = results.begin(); it_u != results.end(); ++it_u) {
|
2005-04-13 18:38:55 +00:00
|
|
|
if (RESULT_COMPUTE_ERROR > (*it_u)->state && !(*it_u)->project->non_cpu_intensive) {
|
|
|
|
results_by_deadline[(*it_u)->report_deadline] = *it_u;
|
|
|
|
projects_with_work.insert((*it_u)->project);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
bool should_not_fetch_work = false;
|
2005-04-14 04:25:56 +00:00
|
|
|
bool use_earliest_deadline_first = false;
|
2005-04-13 23:28:47 +00:00
|
|
|
double now;
|
2005-04-13 18:38:55 +00:00
|
|
|
double frac_booked;
|
|
|
|
std::vector <double> booked_to;
|
2005-04-13 23:28:47 +00:00
|
|
|
now = dtime();
|
|
|
|
frac_booked = 0;
|
2005-04-14 04:25:56 +00:00
|
|
|
for (int i=0; i<ncpus; i++) {
|
2005-04-13 23:28:47 +00:00
|
|
|
booked_to.push_back(now);
|
|
|
|
}
|
2005-04-13 18:38:55 +00:00
|
|
|
|
|
|
|
std::map<double, RESULT*>::iterator it;
|
2005-04-13 23:28:47 +00:00
|
|
|
double up_frac = avg_proc_rate(0);
|
2005-04-14 04:25:56 +00:00
|
|
|
for (
|
|
|
|
it = results_by_deadline.begin();
|
|
|
|
it != results_by_deadline.end() && !should_not_fetch_work;
|
|
|
|
it++
|
|
|
|
) {
|
2005-04-13 18:38:55 +00:00
|
|
|
RESULT *r = (*it).second;
|
2005-04-13 23:28:47 +00:00
|
|
|
if (RESULT_COMPUTE_ERROR > ((*it).second)->state) {
|
2005-04-13 18:38:55 +00:00
|
|
|
double lowest_book = booked_to[0];
|
|
|
|
int lowest_booked_cpu = 0;
|
2005-04-13 23:28:47 +00:00
|
|
|
for(int i = 1; i < ncpus; ++i) {
|
2005-04-13 18:38:55 +00:00
|
|
|
if (booked_to[i] < lowest_book) {
|
|
|
|
lowest_book = booked_to[i];
|
|
|
|
lowest_booked_cpu = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
booked_to[lowest_booked_cpu] += ((*it).second)->estimated_cpu_time_remaining();
|
|
|
|
|
|
|
|
// Are the deadlines too tight to meet reliably?
|
2005-04-13 23:28:47 +00:00
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
if (booked_to[lowest_booked_cpu] - now > (r->report_deadline - now) * MAX_CPU_LOAD_FACTOR * up_frac) {
|
|
|
|
should_not_fetch_work = true;
|
2005-04-14 04:25:56 +00:00
|
|
|
use_earliest_deadline_first = true;
|
|
|
|
if (!cpu_earliest_deadline_first || !work_fetch_no_new_work) {
|
2005-04-13 18:38:55 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"Host is overcommitted"
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-14 04:25:56 +00:00
|
|
|
// Is the nearest deadline within a day?
|
2005-04-13 23:28:47 +00:00
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
if (r->report_deadline - now < 60 * 60 * 24) {
|
2005-04-14 04:25:56 +00:00
|
|
|
use_earliest_deadline_first = true;
|
|
|
|
if (!cpu_earliest_deadline_first) {
|
2005-04-13 18:38:55 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"Less than 1 day until deadline."
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// is there a deadline < twice the users connect period?
|
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
if (r->report_deadline - now < global_prefs.work_buf_min_days * SECONDS_PER_DAY * 2) {
|
2005-04-14 04:25:56 +00:00
|
|
|
use_earliest_deadline_first = true;
|
|
|
|
if (!cpu_earliest_deadline_first) {
|
2005-04-13 18:38:55 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"Deadline is before reconnect time"
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frac_booked += r->estimated_cpu_time_remaining() / (r->report_deadline - now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frac_booked > MAX_CPU_LOAD_FACTOR * up_frac * ncpus) {
|
|
|
|
should_not_fetch_work = true;
|
|
|
|
if (!work_fetch_no_new_work) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-13 23:28:47 +00:00
|
|
|
"Work fetch policy - nearly overcommitted."
|
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// check for too many projects that have work
|
|
|
|
//
|
2005-04-13 18:38:55 +00:00
|
|
|
if (projects_with_work.size() >= (unsigned int)global_prefs.max_projects_on_client) {
|
|
|
|
should_not_fetch_work = true;
|
|
|
|
if (!work_fetch_no_new_work) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-13 23:28:47 +00:00
|
|
|
"Work fetch policy - max projects exceeded."
|
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// display only when the policy changes to avoid once per second
|
|
|
|
//
|
|
|
|
if (work_fetch_no_new_work && !should_not_fetch_work) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"New work fetch policy: work fetch allowed."
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
2005-04-13 23:28:47 +00:00
|
|
|
|
|
|
|
if (!work_fetch_no_new_work && should_not_fetch_work) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"New work fetch policy: no work fetch allowed."
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
2005-04-13 23:28:47 +00:00
|
|
|
|
2005-04-14 04:25:56 +00:00
|
|
|
if (cpu_earliest_deadline_first && !use_earliest_deadline_first) {
|
2005-04-13 23:28:47 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"New CPU scheduler policy: highest debt first."
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
2005-04-14 04:25:56 +00:00
|
|
|
if (!cpu_earliest_deadline_first && use_earliest_deadline_first) {
|
2005-04-13 23:28:47 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-04-14 04:25:56 +00:00
|
|
|
"New CPU scheduler policy: earliest deadline first."
|
2005-04-13 23:28:47 +00:00
|
|
|
);
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
work_fetch_no_new_work = should_not_fetch_work;
|
2005-04-14 04:25:56 +00:00
|
|
|
cpu_earliest_deadline_first = use_earliest_deadline_first;
|
2005-04-13 18:38:55 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_d35a4a7711 = "$Id$";
|