- client emulator: implement project availability feature

This commit is contained in:
David Anderson 2013-03-19 00:28:12 -07:00 committed by Oliver Bock
parent 1f2f32f115
commit 89c9e49bc6
4 changed files with 46 additions and 4 deletions

View File

@ -302,6 +302,12 @@ int PROJECT::parse_state(XML_PARSER& xp) {
continue; continue;
} }
if (xp.parse_double("desired_disk_usage", desired_disk_usage)) continue; if (xp.parse_double("desired_disk_usage", desired_disk_usage)) continue;
#ifdef SIM
if (xp.match_tag("available")) {
available.parse(xp, "/available");
continue;
}
#endif
if (log_flags.unparsed_xml) { if (log_flags.unparsed_xml) {
msg_printf(0, MSG_INFO, msg_printf(0, MSG_INFO,
"[unparsed_xml] PROJECT::parse_state(): unrecognized: %s", "[unparsed_xml] PROJECT::parse_state(): unrecognized: %s",

View File

@ -343,6 +343,21 @@ bool CLIENT_STATE::simulate_rpc(PROJECT* p) {
int infeasible_count = 0; int infeasible_count = 0;
vector<RESULT*> new_results; vector<RESULT*> new_results;
bool avail;
if (p->last_rpc_time) {
double delta = now - p->last_rpc_time;
avail = p->available.sample(delta);
} else {
avail = p->available.sample(0);
}
p->last_rpc_time = now;
if (!avail) {
sprintf(buf, "RPC to %s skipped - project down<br>", p->project_name);
html_msg += buf;
msg_printf(p, MSG_INFO, "RPC skipped: project down");
return false;
}
// save request params for WORK_FETCH::handle_reply // save request params for WORK_FETCH::handle_reply
// //
double save_cpu_req_secs = rsc_work_fetch[0].req_secs; double save_cpu_req_secs = rsc_work_fetch[0].req_secs;

View File

@ -80,6 +80,7 @@ public:
double lambda; double lambda;
bool sample(double dt); bool sample(double dt);
void init(double f, double l); void init(double f, double l);
int parse(XML_PARSER&, const char*);
RANDOM_PROCESS(); RANDOM_PROCESS();
}; };

View File

@ -175,8 +175,7 @@ bool RANDOM_PROCESS::sample(double diff) {
} }
#if 0 #if 0
msg_printf(0, MSG_INFO, msg_printf(0, MSG_INFO,
"value: %d lambda: %f time_left %f", "value: %d lambda: %f time_left %f", value, lambda, time_left
value, lambda, time_left
); );
#endif #endif
return value; return value;
@ -191,9 +190,30 @@ void RANDOM_PROCESS::init(double f, double l) {
frac = f; frac = f;
lambda = l; lambda = l;
last_time = 0; last_time = 0;
value = true;
time_left = exponential(lambda);
off_lambda = lambda/frac - lambda; off_lambda = lambda/frac - lambda;
if (drand() > frac) {
value = false;
time_left = exponential(off_lambda);
} else {
value = true;
time_left = exponential(lambda);
}
}
int RANDOM_PROCESS::parse(XML_PARSER& xp, const char* end_tag) {
while (!xp.get_tag()) {
if (!xp.is_tag) return ERR_XML_PARSE;
if (xp.parse_double("lambda", lambda)) continue;
else if (xp.parse_double("frac", frac)) continue;
else if (xp.match_tag(end_tag)) {
init(frac, lambda);
return 0;
} else {
printf("unrecognized: %s\n", xp.parsed_tag);
return ERR_XML_PARSE;
}
}
return ERR_XML_PARSE;
} }
int UNIFORM_DIST::parse(XML_PARSER& xp, const char* end_tag) { int UNIFORM_DIST::parse(XML_PARSER& xp, const char* end_tag) {