diff --git a/client/project.cpp b/client/project.cpp index e44eb9382c..b1547c8107 100644 --- a/client/project.cpp +++ b/client/project.cpp @@ -302,6 +302,12 @@ int PROJECT::parse_state(XML_PARSER& xp) { 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) { msg_printf(0, MSG_INFO, "[unparsed_xml] PROJECT::parse_state(): unrecognized: %s", diff --git a/client/sim.cpp b/client/sim.cpp index c41cddd372..da7b3d8d40 100644 --- a/client/sim.cpp +++ b/client/sim.cpp @@ -343,6 +343,21 @@ bool CLIENT_STATE::simulate_rpc(PROJECT* p) { int infeasible_count = 0; vector 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
", 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 // double save_cpu_req_secs = rsc_work_fetch[0].req_secs; diff --git a/client/sim.h b/client/sim.h index 70d6a3948f..eccf977899 100644 --- a/client/sim.h +++ b/client/sim.h @@ -80,6 +80,7 @@ public: double lambda; bool sample(double dt); void init(double f, double l); + int parse(XML_PARSER&, const char*); RANDOM_PROCESS(); }; diff --git a/client/sim_util.cpp b/client/sim_util.cpp index d9dcc782f1..39ea84efab 100644 --- a/client/sim_util.cpp +++ b/client/sim_util.cpp @@ -175,8 +175,7 @@ bool RANDOM_PROCESS::sample(double diff) { } #if 0 msg_printf(0, MSG_INFO, - "value: %d lambda: %f time_left %f", - value, lambda, time_left + "value: %d lambda: %f time_left %f", value, lambda, time_left ); #endif return value; @@ -191,9 +190,30 @@ void RANDOM_PROCESS::init(double f, double l) { frac = f; lambda = l; last_time = 0; - value = true; - time_left = exponential(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) {