X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftest%2Fold%2Ftestcrush.cc;fp=src%2Fceph%2Fsrc%2Ftest%2Fold%2Ftestcrush.cc;h=56bb7240eaafbd3d5c1480f825f437e90f5ee01d;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/test/old/testcrush.cc b/src/ceph/src/test/old/testcrush.cc new file mode 100644 index 0000000..56bb724 --- /dev/null +++ b/src/ceph/src/test/old/testcrush.cc @@ -0,0 +1,219 @@ +#include "../crush/crush.h" +using namespace crush; + +#include + +#include +#include +using namespace std; + +void make_disks(int n, int& no, vector& d) +{ + d.clear(); + while (n) { + d.push_back(no); + no++; + n--; + } +} + +Bucket *make_bucket(Crush& c, vector& wid, int h, int& ndisks, int& nbuckets) +{ + if (h == 0) { + // uniform + Hash hash(123); + vector disks; + for (int i=0; imake_primes(hash); + c.add_bucket(b); + return b; + } else { + // mixed + MixedBucket *b = new MixedBucket(nbuckets--, h+1); + for (int i=0; iadd_item(n->get_id(), n->get_weight()); + } + c.add_bucket(b); + return b; + } +} + +int make_hierarchy(Crush& c, vector& wid, int& ndisks, int& nbuckets) +{ + Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks, nbuckets); + return b->get_id(); +} + + + +int main() +{ + Hash h(73232313); + + // crush + Crush c; + + // buckets + vector disks; + int root = -1; + int nbuckets = -1; + int ndisks = 0; + + if (0) { + make_disks(12, ndisks, disks); + UniformBucket ub1(-1, 1, 0, 30, disks); + ub1.make_primes(h); + cout << "ub1 primes are " << ub1.primes << endl; + c.add_bucket(&ub1); + + make_disks(17, ndisks, disks); + UniformBucket ub2(-2, 1, 0, 30, disks); + ub2.make_primes(h); + cout << "ub2 primes are " << ub2.primes << endl; + c.add_bucket(&ub2); + + make_disks(4, ndisks, disks); + UniformBucket ub3(-3, 1, 0, 30, disks); + ub3.make_primes(h); + cout << "ub3 primes are " << ub3.primes << endl; + c.add_bucket(&ub3); + + make_disks(20, ndisks, disks); + MixedBucket umb1(-4, 1); + for (int i=0; i<20; i++) + umb1.add_item(disks[i], 30); + c.add_bucket(&umb1); + + MixedBucket b(-100, 1); + b.add_item(-4, umb1.get_weight()); + } + + if (0) { + int bucket = -1; + MixedBucket *root = new MixedBucket(bucket--, 2); + + for (int i=0; i<5; i++) { + MixedBucket *b = new MixedBucket(bucket--, 1); + + int n = 5; + + if (1) { + // add n buckets of n disks + for (int j=0; jadd_item(disks[k], 10); + + c.add_bucket(d); + b->add_item(d->get_id(), d->get_weight()); + } + + c.add_bucket(b); + root->add_item(b->get_id(), b->get_weight()); + } else { + // add n*n disks + make_disks(n*n, ndisks, disks); + for (int k=0; kadd_item(disks[k], 10); + + c.add_bucket(b); + root->add_item(b->get_id(), b->get_weight()); + } + } + + c.add_bucket(root); + } + + + if (1) { + vector wid; + for (int d=0; d<5; d++) + wid.push_back(10); + root = make_hierarchy(c, wid, ndisks, nbuckets); + } + + // rule + int numrep = 1; + + Rule rule; + if (0) { + rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -100)); + rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0)); + } + if (1) { + rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root)); + rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 1, 0)); + rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT)); + } + + int pg_per = 100; + int numpg = pg_per*ndisks/numrep; + + vector ocount(ndisks); + cout << ndisks << " disks, " << 1-nbuckets << " buckets" << endl; + cout << pg_per << " pgs per disk" << endl; + cout << numpg << " logical pgs" << endl; + cout << "numrep is " << numrep << endl; + + + int place = 1000000; + int times = place / numpg; + if (!times) times = 1; + + cout << "looping " << times << " times" << endl; + + float tvar = 0; + int tvarnum = 0; + + int x = 0; + for (int t=0; t v(numrep); + + for (int z=0; z