virtual void handle() { HOST* h = new HOST; h->t = t + ran_exp(HOST_LIFE_MEAN); hosts.insert(h); sim.insert(h); t += ran_exp(86400./HOSTS_PER_DAY); sim.insert(this); }
int main() { HOST_ARRIVAL *h = new HOST_ARRIVAL; h->t = 0; sim.insert(h); REPORT_STATS* r = new REPORT_STATS; r->t = 0; sim.insert(r); sim.simulate(200*86400); }
int main(int argc, char** argv) { POLICY policy; // default policy // policy.replication = 2; policy.coding_levels = 2; policy.codings[0].n = 10; policy.codings[0].k = 6; policy.codings[0].m = 16; policy.codings[0].n_upload = 12; policy.codings[1].n = 10; policy.codings[1].k = 6; policy.codings[1].m = 16; policy.codings[1].n_upload = 12; for (int i=1; i<argc; i++) { if (!strcmp(argv[i], "--policy")) { int retval = policy.parse(argv[++i]); if (retval) exit(1); } else if (!strcmp(argv[i], "--host_life_mean")) { params.host_life_mean = atof(argv[++i]); } else if (!strcmp(argv[i], "--connect_interval")) { params.connect_interval = atof(argv[++i]); } else if (!strcmp(argv[i], "--mean_xfer_rate")) { params.mean_xfer_rate = atof(argv[++i]); } else if (!strcmp(argv[i], "--file_size")) { params.file_size = atof(argv[++i]); } else { fprintf(stderr, "bad arg %s\n", argv[i]); exit(1); } } #if 0 HOST_ARRIVAL *h = new HOST_ARRIVAL; h->t = 0; sim.insert(h); #endif #if 0 for (int i=0; i<500; i++) { sim.insert(new SIM_HOST); } #endif SIM_FILE* dfile = new SIM_FILE(params.file_size); dfile->policy = policy; sim.insert(dfile); sim.simulate(params.sim_duration); printf("%s: simulation finished\n", now_str()); dfile->print_stats(sim.now); }
// if there aren't enough replicas of this chunk, // pick new hosts and start downloads // int CHUNK::assign() { if (!present_on_server) return 0; VDA_FILE_AUX* fp = parent->dfile; while ((int)(hosts.size()) < fp->policy.replication) { #if 0 if (parent->dfile->unused_hosts.size() == 0) { die("no more hosts!\n"); } set<SIM_HOST*>::iterator i = fp->unused_hosts.begin(); SIM_HOST* h = *i; fp->unused_hosts.erase(i); #else SIM_HOST* h = new SIM_HOST; sim.insert(h); #endif CHUNK_ON_HOST *c = new CHUNK_ON_HOST(); sprintf(c->physical_file_name, "chunk %s on host %d", name, h->id); #ifdef EVENT_DEBUG printf("%s: assigning chunk %s to host %d\n", now_str(), name, h->id); #endif c->host = h; c->chunk = this; h->chunks.insert(c); hosts.insert(c); c->start_download(); } return 0; }
// if there aren't enough replicas of this chunk, // pick new hosts and start downloads // void CHUNK::assign() { if (!present_on_server) return; while ((int)(hosts.size()) < p.replication) { #if 0 if (parent->dfile->unused_hosts.size() == 0) { die("no more hosts!\n"); } set<HOST*>::iterator i = parent->dfile->unused_hosts.begin(); HOST* h = *i; parent->dfile->unused_hosts.erase(i); #else HOST* h = new HOST; sim.insert(h); #endif CHUNK_ON_HOST *c = new CHUNK_ON_HOST(); sprintf(c->name, "chunk %s on host %d", name, h->id); #ifdef EVENT_DEBUG printf("%s: assigning chunk %s to host %d\n", now_str(), name, h->id); #endif c->host = h; c->chunk = this; h->chunks.insert(c); hosts.insert(c); c->start_download(); } }
void BELIEF_PROBA_STATE::Free(const SIMULATOR& simulator) { if( MH ) delete[] MH; MH = 0; if( _uniqueState ) simulator.FreeState(_uniqueState); _uniqueState = 0; }
void BELIEF_STATE::Copy(const BELIEF_STATE* beliefs, const SIMULATOR& simulator) { for (std::vector<STATE*>::const_iterator i_state = beliefs->Samples.begin(); i_state != beliefs->Samples.end(); ++i_state) { AddSample(simulator.Copy(**i_state)); } }
void CHUNK_ON_HOST::start_download() { transfer_in_progress = true; transfer_wait = true; t = sim.now + drand()*p.connect_interval; #ifdef EVENT_DEBUG printf("%s: waiting to start download of %s\n", now_str(), name); #endif sim.insert(this); }
void BELIEF_STATE::Free(const SIMULATOR& simulator) { for (std::vector<STATE*>::iterator i_state = Samples.begin(); i_state != Samples.end(); ++i_state) { simulator.FreeState(*i_state); } Samples.clear(); }
int main() { #if 0 HOST_ARRIVAL *h = new HOST_ARRIVAL; h->t = 0; sim.insert(h); #endif #if 0 for (int i=0; i<500; i++) { sim.insert(new HOST); } #endif DFILE* dfile = new DFILE(1e2); sim.insert(dfile); sim.simulate(200*86400); printf("%s: simulation finished\n", now_str()); dfile->print_stats(); }
// transfer or transfer wait has finished // void CHUNK_ON_HOST::handle() { if (transfer_wait) { transfer_wait = false; if (present_on_host) { #ifdef EVENT_DEBUG printf("%s: starting upload of %s\n", now_str(), physical_file_name); #endif chunk->parent->dfile->upload_rate.sample_inc( host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); } else { #ifdef EVENT_DEBUG printf("%s: starting download of %s\n", now_str(), physical_file_name); #endif chunk->parent->dfile->download_rate.sample_inc( host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); } t = sim.now + chunk->size/host->transfer_rate; sim.insert(this); return; } transfer_in_progress = false; if (present_on_host) { // it was an upload #ifdef EVENT_DEBUG printf("%s: upload of %s completed\n", now_str(), physical_file_name); #endif chunk->parent->dfile->upload_rate.sample_inc( -host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); chunk->upload_complete(); } else { present_on_host = true; #ifdef EVENT_DEBUG printf("%s: download of %s completed\n", now_str(), physical_file_name); #endif chunk->parent->dfile->download_rate.sample_inc( -host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); chunk->download_complete(); } }
// the host has failed // void HOST::handle() { set<HOST*>::iterator i = hosts.find(this); hosts.erase(i); #ifdef EVENT_DEBUG printf("%s: host %d failed\n", now_str(), id); #endif set<CHUNK_ON_HOST*>::iterator p; for (p = chunks.begin(); p != chunks.end(); p++) { CHUNK_ON_HOST* c = *p; c->chunk->host_failed(c); if (c->transfer_in_progress) { sim.remove(c); } delete c; } }
EXPERIMENT::EXPERIMENT(const SIMULATOR& real, const SIMULATOR& simulator, const string& outputFile, EXPERIMENT::PARAMS& expParams, MCTS::PARAMS& searchParams) : Real(real), Simulator(simulator), OutputFile(outputFile.c_str()), ExpParams(expParams), SearchParams(searchParams) { if (ExpParams.AutoExploration) { if (SearchParams.UseRave) SearchParams.ExplorationConstant = 0; else SearchParams.ExplorationConstant = simulator.GetRewardRange(); } MCTS::InitFastUCB(SearchParams.ExplorationConstant); }
// the first event is the creation of a file; // the 2nd is its retrieval // virtual void handle() { if (meta_chunk) { printf("%s: Retrieving file\n", now_str()); meta_chunk->data_needed = true; } else { meta_chunk = new META_CHUNK(this, NULL, size, 0, id); #ifdef EVENT_DEBUG printf("created file %d: size %f GB encoded size %f GB\n", id, size/1e9, disk_usage.value/1e9 ); t = sim.now + 500.*86400; sim.insert(this); #endif } meta_chunk->recovery_plan(); meta_chunk->recovery_action(sim.now); if (meta_chunk->data_now_present) { printf("File is present on server\n"); } }
void CHUNK_ON_HOST::remove() { if (transfer_in_progress) { sim.remove(this); if (!transfer_wait) { if (present_on_host) { chunk->parent->dfile->upload_rate.sample_inc( -host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); } else { chunk->parent->dfile->download_rate.sample_inc( -host->transfer_rate, chunk->parent->dfile->collecting_stats(), sim.now ); } } } }
virtual void handle() { sim.insert(new HOST); t += ran_exp(86400./HOSTS_PER_DAY); sim.insert(this); }
virtual void handle() { printf("%f: %d hosts\n", t, hosts.size()); t += 86400; sim.insert(this); }