Skip to content

Commit

Permalink
- client emulator: implement project availability feature
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpanderson authored and Oliver Bock committed Mar 22, 2013
1 parent 1f2f32f commit 89c9e49
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions client/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions client/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ bool CLIENT_STATE::simulate_rpc(PROJECT* p) {
int infeasible_count = 0;
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
//
double save_cpu_req_secs = rsc_work_fetch[0].req_secs;
Expand Down
1 change: 1 addition & 0 deletions client/sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RANDOM_PROCESS {
double lambda;
bool sample(double dt);
void init(double f, double l);
int parse(XML_PARSER&, const char*);
RANDOM_PROCESS();
};

Expand Down
28 changes: 24 additions & 4 deletions client/sim_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 89c9e49

Please sign in to comment.