#include "../crush.h" using namespace crush; #include "../../common/Clock.h" #include #include #include using namespace std; Clock g_clock; Bucket *make_bucket(Crush& c, vector& wid, int h, int& ndisks) { if (h == 0) { // uniform Hash hash(123); vector disks; for (int i=0; imake_primes(hash); c.add_bucket(b); //cout << h << " uniformbucket with " << wid[h] << " disks weight " << w << endl; return b; } else { // mixed Bucket *b = new TreeBucket(h+1); for (int i=0; iadd_item(n->get_id(), n->get_weight()); } c.add_bucket(b); //cout << h << " mixedbucket with " << wid[h] << endl; return b; } } int make_hierarchy(Crush& c, vector& wid, int& ndisks) { Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks); return b->get_id(); } float go(int dep, int utilization ) { Hash h(73232313); int overloadcutoff = (int)((float)10000.0 / (float)utilization); //cout << "util " << utilization << " cutoff " << overloadcutoff << endl; // crush Crush c; // buckets int root = -1; int ndisks = 0; vector wid; for (int d=0; d ocount(ndisks); //cout << ndisks << " disks, " << endl; //cout << pg_per << " pgs per disk" << endl; // cout << numpg << " logical pgs" << endl; //cout << "numrep is " << numrep << endl; int place = 100000; int times = place / numpg; if (!times) times = 1; //cout << "looping " << times << " times" << endl; float tavg[10]; float tvar[10]; for (int j=0;j<10;j++) { tvar[j] = 0; tavg[j] = 0; } int tvarnum = 0; float overloadsum = 0.0; float adjustsum = 0.0; float afteroverloadsum = 0.0; float aslowdown = 0.0; int chooses = 0; int xs = 1; for (int t=0; t v(numrep); c.overload.clear(); for (int z=0; z cutoff) overloaded++; if (ocount[i] > adjoff) { adjusted++; c.overload[i] = (float)target / (float)ocount[i]; //cout << "setting overload " << i << " to " << c.overload[i] << endl; //cout << "disk " << i << " has " << ocount[i] << endl; } ocount[i] = 0; } //cout << overloaded << " overloaded" << endl; overloadsum += (float)overloaded / (float)ndisks; adjustsum += (float)adjusted / (float)ndisks; // keep adjusting! for (int bla=0; bla<5; bla++) { utime_t t2a = g_clock.now(); // second pass for (int x=xs; x= adjoff) { numover++; if (c.overload.count(i) == 0) { c.overload[i] = 1.0; adjusted++; } //else cout << "(re)adjusting " << i << endl; c.overload[i] *= (float)target / (float)ocount[i]; //cout << "setting overload " << i << " to " << c.overload[i] << endl; //cout << "disk " << i << " has " << ocount[i] << endl; } ocount[i] = 0; } if (!numover) break; cout << "readjusting" << endl; } utime_t t3a = g_clock.now(); for (int x=xs; x cutoff) { still++; //c.overload[ocount[i]] = 100.0 / (float)ocount[i]; if (c.overload.count(i)) cout << "[adjusted] "; cout << "disk " << i << " has " << ocount[i] << endl; } } //if (still) cout << "overload was " << overloaded << " now " << still << endl; afteroverloadsum += (float)still / (float)ndisks; //cout << "collisions: " << c.collisions << endl; //cout << "r bumps: " << c.bumps << endl; int n = ndisks/10; float avg[10]; float var[10]; for (int i=0;i<10;i++) { int s = n*i; avg[i] = 0.0; for (int j=0; j