2011-11-19 00:29:55 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2011 University of California
|
|
|
|
//
|
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-11-03 03:29:07 +00:00
|
|
|
// ssim - simulator for distributed storage
|
2011-11-19 00:29:55 +00:00
|
|
|
//
|
|
|
|
// Simulates the storage of files on a dynamic set of hosts.
|
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
// usage: ssim
|
2012-08-03 16:41:00 +00:00
|
|
|
// --policy filename
|
|
|
|
// default is at start of main()
|
|
|
|
// --host_life_mean x
|
|
|
|
// default: 100 days
|
|
|
|
// --connect_interval x
|
|
|
|
// default: 1 day
|
|
|
|
// --mean_xfer_rate x
|
|
|
|
// default: 200000
|
|
|
|
// --file_size x
|
|
|
|
// default: 1e12
|
2013-05-09 21:53:26 +00:00
|
|
|
// --debug_status
|
|
|
|
// --debug_ft
|
|
|
|
// write recovery details to stdout
|
|
|
|
// --log_actions
|
|
|
|
// write actions to stdout
|
|
|
|
// --sim_duration_years;
|
|
|
|
// --random
|
|
|
|
// srand to pid
|
2012-01-18 02:24:18 +00:00
|
|
|
//
|
|
|
|
// outputs:
|
|
|
|
// stdout: log info
|
|
|
|
// summary.txt: format
|
|
|
|
// fault tolerance min
|
|
|
|
// disk_usage mean
|
|
|
|
// upload_mean
|
|
|
|
// download_mean
|
|
|
|
|
|
|
|
#include <set>
|
2012-02-10 22:54:00 +00:00
|
|
|
#include <limits.h>
|
2012-08-01 21:21:38 +00:00
|
|
|
#include <cmath>
|
2013-05-25 20:54:50 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2012-01-18 02:24:18 +00:00
|
|
|
|
|
|
|
#include "des.h"
|
2012-06-14 17:14:52 +00:00
|
|
|
#include "stats.h"
|
2012-01-23 08:04:41 +00:00
|
|
|
#include "vda_lib.h"
|
2012-01-18 02:24:18 +00:00
|
|
|
|
|
|
|
using std::set;
|
|
|
|
|
2013-05-09 21:53:26 +00:00
|
|
|
bool log_actions = false;
|
|
|
|
|
2013-05-14 19:27:04 +00:00
|
|
|
double min_failures_time[100];
|
|
|
|
int min_min_failures = 100;
|
|
|
|
|
2011-11-19 00:29:55 +00:00
|
|
|
// We simulate policies based on coding and replication.
|
|
|
|
//
|
|
|
|
// Coding means that data is divided into M = N+K units,
|
2011-11-29 04:47:10 +00:00
|
|
|
// of which any N are sufficient to reconstruct the original data.
|
2011-12-14 01:34:51 +00:00
|
|
|
// When we need to reconstruct an encoded unit on the server,
|
|
|
|
// we try to upload N_UPLOAD subunits,
|
|
|
|
// where N <= N_UPLOAD <= M
|
|
|
|
// The units in an encoding can themselves be encoded.
|
2012-01-15 18:17:49 +00:00
|
|
|
//
|
2011-12-14 01:34:51 +00:00
|
|
|
// The bottom-level data units ("chunks") are stored on hosts,
|
|
|
|
// possibly with replication
|
2011-11-19 00:29:55 +00:00
|
|
|
|
2012-01-15 18:17:49 +00:00
|
|
|
struct PARAMS {
|
|
|
|
// The model of the host population is:
|
|
|
|
// - the population is unbounded
|
|
|
|
// - host lifetime is exponentially distributed
|
|
|
|
// - the time needed to transfer n bytes of data to/from a host is
|
2012-01-18 02:24:18 +00:00
|
|
|
// U1*connect_interval + (U2+.5)*n/mean_xfer_rate;
|
2012-01-15 18:17:49 +00:00
|
|
|
// where U1 and U2 are uniform random vars
|
|
|
|
// (U1 is per-transfer, U2 is per-host)
|
|
|
|
//
|
|
|
|
double host_life_mean;
|
|
|
|
double connect_interval;
|
2012-01-18 02:24:18 +00:00
|
|
|
double mean_xfer_rate;
|
2012-01-19 20:11:52 +00:00
|
|
|
double file_size;
|
|
|
|
double sim_duration;
|
2012-01-15 18:17:49 +00:00
|
|
|
|
|
|
|
PARAMS() {
|
|
|
|
// default parameters
|
|
|
|
//
|
|
|
|
host_life_mean = 100.*86400;
|
|
|
|
connect_interval = 86400.;
|
2012-01-18 02:24:18 +00:00
|
|
|
mean_xfer_rate = .2e6;
|
2012-08-03 16:41:00 +00:00
|
|
|
file_size = 1e10;
|
2012-01-19 20:11:52 +00:00
|
|
|
sim_duration = 1000.*86400;
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
2012-01-20 20:21:29 +00:00
|
|
|
} params;
|
|
|
|
|
2011-11-19 00:29:55 +00:00
|
|
|
// Terminology:
|
|
|
|
//
|
2011-12-10 22:03:43 +00:00
|
|
|
// A data unit is "recoverable" if it can be recovered on the server
|
|
|
|
// by uploading data from hosts.
|
|
|
|
// A chunk is recoverable if it's present on the server or on at least 1 host.
|
|
|
|
// (note: if it's downloading, it's still present on the server)
|
|
|
|
// An encoded data unit is recoverable if at least N
|
2011-11-19 00:29:55 +00:00
|
|
|
// of its subunits are recoverable.
|
|
|
|
|
2011-12-06 04:21:27 +00:00
|
|
|
// Figures of merit
|
|
|
|
//
|
|
|
|
// for each file, we compute:
|
|
|
|
// - the average and peak server network rate, up and down
|
|
|
|
// - the average and peak disk usage
|
|
|
|
// - the average and min fault tolerance level
|
|
|
|
// (i.e. number of simultaneous host failures needed to lose the file)
|
|
|
|
//
|
|
|
|
// These are measured starting from the time when the file's
|
|
|
|
// initial downloads have all succeeded or failed
|
|
|
|
|
2011-11-03 03:29:07 +00:00
|
|
|
SIMULATOR sim;
|
2011-12-14 01:34:51 +00:00
|
|
|
int next_file_id=0;
|
|
|
|
int next_host_id=0;
|
2011-11-03 03:29:07 +00:00
|
|
|
|
|
|
|
inline double drand() {
|
|
|
|
return (double)rand()/(double)RAND_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ran_exp(double mean) {
|
2011-12-06 04:21:27 +00:00
|
|
|
return -log(drand())*mean;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* now_str() {
|
|
|
|
return time_str(sim.now);
|
2011-11-03 03:29:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 17:14:52 +00:00
|
|
|
void show_msg(char* msg) {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: %s", time_str(sim.now), msg);
|
|
|
|
}
|
2012-06-14 17:14:52 +00:00
|
|
|
}
|
|
|
|
|
2011-11-19 00:29:55 +00:00
|
|
|
struct CHUNK;
|
2011-12-14 01:34:51 +00:00
|
|
|
struct CHUNK_ON_HOST;
|
2011-11-19 00:29:55 +00:00
|
|
|
struct META_CHUNK;
|
2012-02-10 22:54:00 +00:00
|
|
|
struct SIM_HOST;
|
|
|
|
set<SIM_HOST*> hosts;
|
2011-11-03 03:29:07 +00:00
|
|
|
|
2011-12-14 01:34:51 +00:00
|
|
|
// Represents a host.
|
|
|
|
// The associated EVENT is the disappearance of the host
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
struct SIM_HOST : EVENT {
|
2011-11-20 09:18:12 +00:00
|
|
|
int id;
|
2012-01-15 18:17:49 +00:00
|
|
|
double transfer_rate;
|
2011-12-14 01:34:51 +00:00
|
|
|
set<CHUNK_ON_HOST*> chunks; // chunks present or downloading
|
2011-11-19 00:29:55 +00:00
|
|
|
virtual void handle();
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_HOST() {
|
2012-01-20 20:21:29 +00:00
|
|
|
t = sim.now + ran_exp(params.host_life_mean);
|
2011-11-20 09:18:12 +00:00
|
|
|
id = next_host_id++;
|
2012-01-20 20:21:29 +00:00
|
|
|
transfer_rate = params.mean_xfer_rate*(drand() + .5);
|
2011-11-20 09:18:12 +00:00
|
|
|
hosts.insert(this);
|
|
|
|
}
|
2011-11-03 03:29:07 +00:00
|
|
|
};
|
|
|
|
|
2012-01-15 18:17:49 +00:00
|
|
|
#if 0
|
2011-12-14 01:34:51 +00:00
|
|
|
// The host arrival process.
|
|
|
|
// The associated EVENT is the arrival of a host
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
struct HOST_ARRIVAL : EVENT {
|
2011-11-03 03:29:07 +00:00
|
|
|
virtual void handle() {
|
2012-02-10 22:54:00 +00:00
|
|
|
sim.insert(new SIM_HOST);
|
2011-11-03 03:29:07 +00:00
|
|
|
t += ran_exp(86400./HOSTS_PER_DAY);
|
|
|
|
sim.insert(this);
|
|
|
|
}
|
|
|
|
};
|
2012-01-15 18:17:49 +00:00
|
|
|
#endif
|
2011-11-03 03:29:07 +00:00
|
|
|
|
2011-11-20 09:18:12 +00:00
|
|
|
void die(const char* msg) {
|
2011-12-06 04:21:27 +00:00
|
|
|
printf("%s: %s\n", now_str(), msg);
|
2011-11-20 09:18:12 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-12-14 01:34:51 +00:00
|
|
|
// The status of a chunk on a particular host.
|
|
|
|
// The associated event is the completion of an upload or download
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
struct CHUNK_ON_HOST : VDA_CHUNK_HOST, EVENT {
|
|
|
|
SIM_HOST* host;
|
2011-12-14 01:34:51 +00:00
|
|
|
CHUNK* chunk;
|
|
|
|
virtual void handle();
|
2012-01-15 18:17:49 +00:00
|
|
|
void start_upload();
|
|
|
|
void start_download();
|
2012-01-18 02:24:18 +00:00
|
|
|
void remove();
|
2011-12-14 01:34:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// represents a file to be stored.
|
|
|
|
// The associated EVENT is the arrival of the file
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
struct SIM_FILE : VDA_FILE_AUX, EVENT {
|
2011-11-19 00:29:55 +00:00
|
|
|
double size;
|
2011-11-20 09:18:12 +00:00
|
|
|
int id;
|
2012-01-15 18:17:49 +00:00
|
|
|
#if 0
|
2012-02-10 22:54:00 +00:00
|
|
|
set<SIM_HOST*> unused_hosts;
|
2011-12-14 01:34:51 +00:00
|
|
|
// hosts that don't have any chunks of this file
|
2012-01-15 18:17:49 +00:00
|
|
|
#endif
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
SIM_FILE(double s) {
|
2011-11-20 09:18:12 +00:00
|
|
|
id = next_file_id++;
|
2012-01-15 18:17:49 +00:00
|
|
|
#if 0
|
2011-11-20 09:18:12 +00:00
|
|
|
unused_hosts = hosts;
|
2012-01-15 18:17:49 +00:00
|
|
|
#endif
|
2011-11-20 09:18:12 +00:00
|
|
|
size = s;
|
2012-01-18 02:24:18 +00:00
|
|
|
disk_usage.init("Disk usage", "disk.dat", DISK);
|
|
|
|
upload_rate.init("Upload rate", "upload.dat", NETWORK);
|
|
|
|
download_rate.init("Download rate", "download.dat", NETWORK);
|
|
|
|
fault_tolerance.init("Fault tolerance", "fault_tol.dat", FAULT_TOLERANCE);
|
2011-11-20 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 20:58:45 +00:00
|
|
|
// the first event is the creation of a file;
|
|
|
|
// the 2nd is its retrieval
|
2011-11-19 00:29:55 +00:00
|
|
|
//
|
2011-11-03 03:29:07 +00:00
|
|
|
virtual void handle() {
|
2012-02-29 20:58:45 +00:00
|
|
|
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);
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("created file %d: size %f GB encoded size %f GB\n",
|
|
|
|
id, size/1e9, disk_usage.value/1e9
|
|
|
|
);
|
|
|
|
}
|
2012-02-29 20:58:45 +00:00
|
|
|
t = sim.now + 500.*86400;
|
|
|
|
sim.insert(this);
|
|
|
|
}
|
2011-12-12 22:07:37 +00:00
|
|
|
meta_chunk->recovery_plan();
|
2012-02-10 22:54:00 +00:00
|
|
|
meta_chunk->recovery_action(sim.now);
|
2012-02-29 20:58:45 +00:00
|
|
|
if (meta_chunk->data_now_present) {
|
|
|
|
printf("File is present on server\n");
|
|
|
|
}
|
2011-12-16 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 22:07:37 +00:00
|
|
|
void recover() {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf("recovery_plan():\n");
|
|
|
|
}
|
2011-12-12 22:07:37 +00:00
|
|
|
meta_chunk->recovery_plan();
|
2013-05-09 21:53:26 +00:00
|
|
|
if (meta_chunk->status == UNRECOVERABLE) {
|
|
|
|
printf("FILE IS LOST!!\n");
|
2013-05-14 19:27:04 +00:00
|
|
|
sim.done = true;
|
|
|
|
min_min_failures = 0;
|
|
|
|
min_failures_time[0] = sim.now;
|
|
|
|
return;
|
2013-05-09 21:53:26 +00:00
|
|
|
}
|
|
|
|
if (debug_status) {
|
|
|
|
printf("decide_reconstruct():\n");
|
|
|
|
}
|
2012-08-03 16:41:00 +00:00
|
|
|
meta_chunk->decide_reconstruct();
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf("reconstruct_and_cleanup():\n");
|
|
|
|
}
|
2012-08-03 16:41:00 +00:00
|
|
|
meta_chunk->reconstruct_and_cleanup();
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf("recovery_action():\n");
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
meta_chunk->recovery_action(sim.now);
|
2012-08-15 21:27:38 +00:00
|
|
|
meta_chunk->compute_min_failures();
|
2013-05-14 19:27:04 +00:00
|
|
|
int mf = meta_chunk->min_failures;
|
|
|
|
printf(" Min failures: %d\n", mf);
|
2012-02-10 22:54:00 +00:00
|
|
|
fault_tolerance.sample(
|
2013-05-14 19:27:04 +00:00
|
|
|
mf-1, collecting_stats(), sim.now
|
2012-02-10 22:54:00 +00:00
|
|
|
);
|
2013-05-14 19:27:04 +00:00
|
|
|
while (mf < min_min_failures) {
|
|
|
|
min_min_failures--;
|
|
|
|
min_failures_time[min_min_failures] = sim.now;
|
|
|
|
}
|
2011-12-06 04:21:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
void print_stats(double now) {
|
2011-12-06 04:21:27 +00:00
|
|
|
printf("Statistics for file %d\n", id);
|
|
|
|
printf(" Server disk usage:\n");
|
2012-02-10 22:54:00 +00:00
|
|
|
disk_usage.print(now);
|
2011-12-06 04:21:27 +00:00
|
|
|
printf(" Upload rate:\n");
|
2012-02-10 22:54:00 +00:00
|
|
|
upload_rate.print(now);
|
2011-12-06 04:21:27 +00:00
|
|
|
printf(" Download rate:\n");
|
2012-02-10 22:54:00 +00:00
|
|
|
download_rate.print(now);
|
2011-12-06 04:21:27 +00:00
|
|
|
printf(" Fault tolerance level:\n");
|
2012-02-10 22:54:00 +00:00
|
|
|
fault_tolerance.print(now);
|
2012-01-18 09:04:35 +00:00
|
|
|
|
|
|
|
FILE* f = fopen("summary.txt", "w");
|
2012-02-10 22:54:00 +00:00
|
|
|
fault_tolerance.print_summary(f, now);
|
|
|
|
disk_usage.print_summary(f, now);
|
|
|
|
upload_rate.print_summary(f, now);
|
|
|
|
download_rate.print_summary(f, now);
|
2012-01-18 09:04:35 +00:00
|
|
|
fclose(f);
|
2011-12-06 04:21:27 +00:00
|
|
|
}
|
2011-11-03 03:29:07 +00:00
|
|
|
};
|
|
|
|
|
2011-11-19 00:29:55 +00:00
|
|
|
//////////////////// method defs ////////////////////
|
|
|
|
|
2012-01-15 18:17:49 +00:00
|
|
|
void CHUNK_ON_HOST::start_upload() {
|
|
|
|
transfer_in_progress = true;
|
|
|
|
transfer_wait = true;
|
2012-01-20 20:21:29 +00:00
|
|
|
t = sim.now + drand()*params.connect_interval;
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: waiting to start upload of %s\n", now_str(), physical_file_name);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
sim.insert(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUNK_ON_HOST::start_download() {
|
|
|
|
transfer_in_progress = true;
|
|
|
|
transfer_wait = true;
|
2012-01-20 20:21:29 +00:00
|
|
|
t = sim.now + drand()*params.connect_interval;
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: waiting to start download of %s\n", now_str(), physical_file_name);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
sim.insert(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// transfer or transfer wait has finished
|
2011-11-19 00:29:55 +00:00
|
|
|
//
|
|
|
|
void CHUNK_ON_HOST::handle() {
|
2012-01-15 18:17:49 +00:00
|
|
|
if (transfer_wait) {
|
|
|
|
transfer_wait = false;
|
|
|
|
if (present_on_host) {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: starting upload of %s\n",
|
|
|
|
now_str(), physical_file_name
|
|
|
|
);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
chunk->parent->dfile->upload_rate.sample_inc(
|
|
|
|
host->transfer_rate,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-15 18:17:49 +00:00
|
|
|
);
|
|
|
|
} else {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: starting download of %s\n",
|
|
|
|
now_str(), physical_file_name
|
|
|
|
);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
chunk->parent->dfile->download_rate.sample_inc(
|
|
|
|
host->transfer_rate,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-15 18:17:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
t = sim.now + chunk->size/host->transfer_rate;
|
|
|
|
sim.insert(this);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-19 00:29:55 +00:00
|
|
|
transfer_in_progress = false;
|
|
|
|
if (present_on_host) {
|
|
|
|
// it was an upload
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: upload of %s completed\n",
|
|
|
|
now_str(), physical_file_name
|
|
|
|
);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
chunk->parent->dfile->upload_rate.sample_inc(
|
|
|
|
-host->transfer_rate,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-15 18:17:49 +00:00
|
|
|
);
|
|
|
|
chunk->upload_complete();
|
2011-11-19 00:29:55 +00:00
|
|
|
} else {
|
|
|
|
present_on_host = true;
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: download of %s completed\n",
|
|
|
|
now_str(), physical_file_name
|
|
|
|
);
|
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
chunk->parent->dfile->download_rate.sample_inc(
|
|
|
|
-host->transfer_rate,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-15 18:17:49 +00:00
|
|
|
);
|
2011-11-20 09:18:12 +00:00
|
|
|
chunk->download_complete();
|
2011-11-19 00:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
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,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-18 02:24:18 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
chunk->parent->dfile->download_rate.sample_inc(
|
|
|
|
-host->transfer_rate,
|
2012-02-10 22:54:00 +00:00
|
|
|
chunk->parent->dfile->collecting_stats(),
|
|
|
|
sim.now
|
2012-01-18 02:24:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 04:21:27 +00:00
|
|
|
// the host has failed
|
2011-11-19 00:29:55 +00:00
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
void SIM_HOST::handle() {
|
|
|
|
set<SIM_HOST*>::iterator i = hosts.find(this);
|
2011-11-19 00:29:55 +00:00
|
|
|
hosts.erase(i);
|
|
|
|
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: host %d failed\n", now_str(), id);
|
|
|
|
}
|
2011-11-19 00:29:55 +00:00
|
|
|
set<CHUNK_ON_HOST*>::iterator p;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (p = chunks.begin(); p != chunks.end(); ++p) {
|
2011-11-19 00:29:55 +00:00
|
|
|
CHUNK_ON_HOST* c = *p;
|
|
|
|
c->chunk->host_failed(c);
|
2012-01-18 02:24:18 +00:00
|
|
|
c->remove();
|
2011-11-19 00:29:55 +00:00
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:18:12 +00:00
|
|
|
CHUNK::CHUNK(META_CHUNK* mc, double s, int index) {
|
|
|
|
parent = mc;
|
2011-12-12 22:07:37 +00:00
|
|
|
present_on_server = true;
|
2011-11-20 09:18:12 +00:00
|
|
|
size = s;
|
|
|
|
sprintf(name, "%s.%d", parent->name, index);
|
2012-02-10 22:54:00 +00:00
|
|
|
VDA_FILE_AUX* fp = parent->dfile;
|
|
|
|
fp->pending_init_downloads += fp->policy.replication;
|
2013-05-09 21:53:26 +00:00
|
|
|
fp->disk_usage.sample_inc(size, false, sim.now, "init");
|
2011-11-20 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
2011-12-10 22:03:43 +00:00
|
|
|
// if there aren't enough replicas of this chunk,
|
|
|
|
// pick new hosts and start downloads
|
|
|
|
//
|
2012-02-21 20:55:09 +00:00
|
|
|
int CHUNK::assign() {
|
|
|
|
if (!present_on_server) return 0;
|
2012-02-10 22:54:00 +00:00
|
|
|
VDA_FILE_AUX* fp = parent->dfile;
|
|
|
|
while ((int)(hosts.size()) < fp->policy.replication) {
|
2012-01-15 18:17:49 +00:00
|
|
|
#if 0
|
2011-11-20 09:18:12 +00:00
|
|
|
if (parent->dfile->unused_hosts.size() == 0) {
|
|
|
|
die("no more hosts!\n");
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
set<SIM_HOST*>::iterator i = fp->unused_hosts.begin();
|
|
|
|
SIM_HOST* h = *i;
|
|
|
|
fp->unused_hosts.erase(i);
|
2012-01-15 18:17:49 +00:00
|
|
|
#else
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_HOST* h = new SIM_HOST;
|
2012-01-15 18:17:49 +00:00
|
|
|
sim.insert(h);
|
|
|
|
#endif
|
2011-11-19 00:29:55 +00:00
|
|
|
CHUNK_ON_HOST *c = new CHUNK_ON_HOST();
|
2012-07-25 21:41:32 +00:00
|
|
|
sprintf(c->physical_file_name, "chunk %s on host %d", name, h->id);
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: assigning chunk %s to host %d\n",
|
|
|
|
now_str(), name, h->id
|
|
|
|
);
|
|
|
|
}
|
2011-11-19 00:29:55 +00:00
|
|
|
c->host = h;
|
|
|
|
c->chunk = this;
|
2011-11-20 09:18:12 +00:00
|
|
|
h->chunks.insert(c);
|
2012-01-15 18:17:49 +00:00
|
|
|
hosts.insert(c);
|
|
|
|
c->start_download();
|
2011-11-19 00:29:55 +00:00
|
|
|
}
|
2012-02-21 20:55:09 +00:00
|
|
|
return 0;
|
2011-11-19 00:29:55 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 22:55:11 +00:00
|
|
|
int CHUNK::start_upload() {
|
2011-12-14 01:34:51 +00:00
|
|
|
// if no upload of this chunk is in progress, start one.
|
|
|
|
// NOTE: all instances are inherently present_on_host,
|
|
|
|
// since this is only called if chunk is not present on server
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
set<VDA_CHUNK_HOST*>::iterator i;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (i=hosts.begin(); i!=hosts.end(); ++i) {
|
2012-02-10 22:54:00 +00:00
|
|
|
CHUNK_ON_HOST* c = (CHUNK_ON_HOST*)*i;
|
2012-02-24 22:55:11 +00:00
|
|
|
if (c->transfer_in_progress) return 0;
|
2011-12-14 01:34:51 +00:00
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
CHUNK_ON_HOST* c = (CHUNK_ON_HOST*)*(hosts.begin());
|
2012-01-15 18:17:49 +00:00
|
|
|
c->start_upload();
|
2012-02-24 22:55:11 +00:00
|
|
|
return 0;
|
2011-12-14 01:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
void CHUNK::host_failed(VDA_CHUNK_HOST* p) {
|
|
|
|
set<VDA_CHUNK_HOST*>::iterator i = hosts.find(p);
|
2011-12-14 01:34:51 +00:00
|
|
|
hosts.erase(i);
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: handling loss of %s\n", now_str(), p->physical_file_name);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_FILE* sfp = (SIM_FILE*)parent->dfile;
|
|
|
|
sfp->recover();
|
2011-12-14 01:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHUNK::upload_complete() {
|
|
|
|
if (!present_on_server) {
|
|
|
|
present_on_server = true;
|
|
|
|
parent->dfile->disk_usage.sample_inc(
|
|
|
|
size,
|
2012-02-10 22:54:00 +00:00
|
|
|
parent->dfile->collecting_stats(),
|
2013-05-09 21:53:26 +00:00
|
|
|
sim.now,
|
|
|
|
"upload_complete"
|
2011-12-14 01:34:51 +00:00
|
|
|
);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_FILE* sfp = (SIM_FILE*)parent->dfile;
|
|
|
|
sfp->recover();
|
2011-12-14 01:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHUNK::download_complete() {
|
|
|
|
if (parent->dfile->pending_init_downloads) {
|
|
|
|
parent->dfile->pending_init_downloads--;
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_FILE* sfp = (SIM_FILE*)parent->dfile;
|
|
|
|
sfp->recover();
|
2011-12-12 22:07:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 21:27:38 +00:00
|
|
|
int CHUNK::upload_all() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int META_CHUNK::upload_all() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-13 23:15:50 +00:00
|
|
|
int META_CHUNK::encode(bool) {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: encoding metachunk %s\n", now_str(), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// new chunks count toward server disk usage
|
|
|
|
//
|
|
|
|
if (bottom_level) {
|
|
|
|
for (unsigned int i=0; i<children.size(); i++) {
|
|
|
|
CHUNK& c = *(CHUNK*)children[i];
|
|
|
|
if (!c.present_on_server) {
|
|
|
|
dfile->disk_usage.sample_inc(
|
|
|
|
c.size, dfile->collecting_stats(), sim.now, "encode"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-11 01:51:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int META_CHUNK::decode() {
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_actions) {
|
|
|
|
printf("%s: decoding metachunk %s\n", now_str(), name);
|
|
|
|
}
|
2012-03-11 01:51:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DATA_UNIT::delete_file() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
set<SIM_FILE*> dfiles;
|
2011-11-03 03:29:07 +00:00
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
int main(int argc, char** argv) {
|
2012-02-10 22:54:00 +00:00
|
|
|
POLICY policy;
|
2013-05-09 21:53:26 +00:00
|
|
|
bool log_disk_usage = false;
|
|
|
|
bool log_fault_tolerance = false;
|
|
|
|
bool log_download = false;
|
|
|
|
bool log_upload = false;
|
2012-01-20 20:21:29 +00:00
|
|
|
|
|
|
|
// default policy
|
|
|
|
//
|
2012-08-07 22:49:40 +00:00
|
|
|
#if 0
|
2012-08-03 16:41:00 +00:00
|
|
|
policy.replication = 2;
|
|
|
|
policy.coding_levels = 1;
|
|
|
|
policy.codings[0].n = 4;
|
|
|
|
policy.codings[0].k = 2;
|
|
|
|
policy.codings[0].m = 6;
|
|
|
|
#else
|
2012-08-07 22:49:40 +00:00
|
|
|
policy.replication = 1;
|
2012-06-18 17:57:33 +00:00
|
|
|
policy.coding_levels = 2;
|
2012-08-07 22:49:40 +00:00
|
|
|
policy.codings[0].n = 4;
|
|
|
|
policy.codings[0].k = 2;
|
|
|
|
policy.codings[0].m = 6;
|
|
|
|
policy.codings[0].n_upload = 5;
|
|
|
|
policy.codings[1].n = 4;
|
|
|
|
policy.codings[1].k = 2;
|
|
|
|
policy.codings[1].m = 6;
|
|
|
|
policy.codings[1].n_upload = 5;
|
2012-08-03 16:41:00 +00:00
|
|
|
#endif
|
2012-01-20 20:21:29 +00:00
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "--policy")) {
|
2012-01-20 20:21:29 +00:00
|
|
|
int retval = policy.parse(argv[++i]);
|
|
|
|
if (retval) exit(1);
|
2012-01-18 02:24:18 +00:00
|
|
|
} else if (!strcmp(argv[i], "--host_life_mean")) {
|
2012-01-20 20:21:29 +00:00
|
|
|
params.host_life_mean = atof(argv[++i]);
|
2012-01-18 02:24:18 +00:00
|
|
|
} else if (!strcmp(argv[i], "--connect_interval")) {
|
2012-01-20 20:21:29 +00:00
|
|
|
params.connect_interval = atof(argv[++i]);
|
2012-01-18 02:24:18 +00:00
|
|
|
} else if (!strcmp(argv[i], "--mean_xfer_rate")) {
|
2012-01-20 20:21:29 +00:00
|
|
|
params.mean_xfer_rate = atof(argv[++i]);
|
2012-01-19 20:11:52 +00:00
|
|
|
} else if (!strcmp(argv[i], "--file_size")) {
|
2012-01-20 20:21:29 +00:00
|
|
|
params.file_size = atof(argv[++i]);
|
2013-05-09 21:53:26 +00:00
|
|
|
} else if (!strcmp(argv[i], "--debug_status")) {
|
|
|
|
debug_status = true;
|
|
|
|
} else if (!strcmp(argv[i], "--debug_ft")) {
|
|
|
|
debug_ft = true;
|
|
|
|
} else if (!strcmp(argv[i], "--log_actions")) {
|
|
|
|
log_actions = true;
|
|
|
|
} else if (!strcmp(argv[i], "--log_disk_usage")) {
|
|
|
|
log_disk_usage = true;
|
|
|
|
} else if (!strcmp(argv[i], "--log_fault_tolerance")) {
|
|
|
|
log_fault_tolerance = true;
|
|
|
|
} else if (!strcmp(argv[i], "--log_download")) {
|
|
|
|
log_download = true;
|
|
|
|
} else if (!strcmp(argv[i], "--log_upload")) {
|
|
|
|
log_upload = true;
|
|
|
|
} else if (!strcmp(argv[i], "--sim_duration_years")) {
|
|
|
|
params.sim_duration = atof(argv[++i])*86400*365;
|
|
|
|
} else if (!strcmp(argv[i], "--random")) {
|
|
|
|
srand(getpid());
|
2012-01-18 02:24:18 +00:00
|
|
|
} else {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("bad arg %s\n", argv[i]);
|
2012-01-18 02:24:18 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:18:12 +00:00
|
|
|
#if 0
|
2011-11-03 03:29:07 +00:00
|
|
|
HOST_ARRIVAL *h = new HOST_ARRIVAL;
|
|
|
|
h->t = 0;
|
|
|
|
sim.insert(h);
|
2011-11-20 09:18:12 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-15 18:17:49 +00:00
|
|
|
#if 0
|
2011-12-14 01:34:51 +00:00
|
|
|
for (int i=0; i<500; i++) {
|
2012-02-10 22:54:00 +00:00
|
|
|
sim.insert(new SIM_HOST);
|
2011-11-20 09:18:12 +00:00
|
|
|
}
|
2012-01-15 18:17:49 +00:00
|
|
|
#endif
|
2012-02-10 22:54:00 +00:00
|
|
|
SIM_FILE* dfile = new SIM_FILE(params.file_size);
|
|
|
|
dfile->policy = policy;
|
2013-05-09 21:53:26 +00:00
|
|
|
if (log_disk_usage) dfile->disk_usage.log_changes = true;
|
|
|
|
if (log_fault_tolerance) dfile->fault_tolerance.log_changes = true;
|
|
|
|
if (log_download) dfile->download_rate.log_changes = true;
|
|
|
|
if (log_upload) dfile->upload_rate.log_changes = true;
|
2011-12-06 04:21:27 +00:00
|
|
|
sim.insert(dfile);
|
2011-11-03 03:29:07 +00:00
|
|
|
|
2012-01-20 20:21:29 +00:00
|
|
|
sim.simulate(params.sim_duration);
|
2011-12-06 04:21:27 +00:00
|
|
|
|
|
|
|
printf("%s: simulation finished\n", now_str());
|
2012-02-10 22:54:00 +00:00
|
|
|
dfile->print_stats(sim.now);
|
2013-05-14 19:27:04 +00:00
|
|
|
|
|
|
|
FILE* f = fopen("mft.dat", "w");
|
|
|
|
for (int i=0; i<=policy.max_ft; i++) {
|
|
|
|
fprintf(f, "%d %f\n", i, min_failures_time[i]);
|
|
|
|
}
|
|
|
|
fclose(f);
|
2011-11-03 03:29:07 +00:00
|
|
|
}
|