1 #include "../crush/crush.h"
10 void make_disks(int n, int& no, vector<int>& d)
20 Bucket *make_bucket(Crush& c, vector<int>& wid, int h, int& ndisks, int& nbuckets)
26 for (int i=0; i<wid[h]; i++)
27 disks.push_back(ndisks++);
28 UniformBucket *b = new UniformBucket(nbuckets--, 1, 0, 10, disks);
34 MixedBucket *b = new MixedBucket(nbuckets--, h+1);
35 for (int i=0; i<wid[h]; i++) {
36 Bucket *n = make_bucket(c, wid, h-1, ndisks, nbuckets);
37 b->add_item(n->get_id(), n->get_weight());
44 int make_hierarchy(Crush& c, vector<int>& wid, int& ndisks, int& nbuckets)
46 Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks, nbuckets);
66 make_disks(12, ndisks, disks);
67 UniformBucket ub1(-1, 1, 0, 30, disks);
69 cout << "ub1 primes are " << ub1.primes << endl;
72 make_disks(17, ndisks, disks);
73 UniformBucket ub2(-2, 1, 0, 30, disks);
75 cout << "ub2 primes are " << ub2.primes << endl;
78 make_disks(4, ndisks, disks);
79 UniformBucket ub3(-3, 1, 0, 30, disks);
81 cout << "ub3 primes are " << ub3.primes << endl;
84 make_disks(20, ndisks, disks);
85 MixedBucket umb1(-4, 1);
86 for (int i=0; i<20; i++)
87 umb1.add_item(disks[i], 30);
90 MixedBucket b(-100, 1);
91 b.add_item(-4, umb1.get_weight());
96 MixedBucket *root = new MixedBucket(bucket--, 2);
98 for (int i=0; i<5; i++) {
99 MixedBucket *b = new MixedBucket(bucket--, 1);
104 // add n buckets of n disks
105 for (int j=0; j<n; j++) {
107 MixedBucket *d = new MixedBucket(bucket--, 1);
109 make_disks(n, ndisks, disks);
110 for (int k=0; k<n; k++)
111 d->add_item(disks[k], 10);
114 b->add_item(d->get_id(), d->get_weight());
118 root->add_item(b->get_id(), b->get_weight());
121 make_disks(n*n, ndisks, disks);
122 for (int k=0; k<n*n; k++)
123 b->add_item(disks[k], 10);
126 root->add_item(b->get_id(), b->get_weight());
136 for (int d=0; d<5; d++)
138 root = make_hierarchy(c, wid, ndisks, nbuckets);
146 rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -100));
147 rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0));
150 rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root));
151 rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 1, 0));
152 rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT));
156 int numpg = pg_per*ndisks/numrep;
158 vector<int> ocount(ndisks);
159 cout << ndisks << " disks, " << 1-nbuckets << " buckets" << endl;
160 cout << pg_per << " pgs per disk" << endl;
161 cout << numpg << " logical pgs" << endl;
162 cout << "numrep is " << numrep << endl;
166 int times = place / numpg;
167 if (!times) times = 1;
169 cout << "looping " << times << " times" << endl;
175 for (int t=0; t<times; t++) {
176 vector<int> v(numrep);
178 for (int z=0; z<ndisks; z++) ocount[z] = 0;
180 for (int xx=1; xx<numpg; xx++) {
183 c.do_rule(rule, x, v);
186 for (int i=0; i<numrep; i++) {
188 for (int j=i+1; j<numrep; j++) {
194 cout << "bad set " << x << ": " << v << endl;
197 cout << "collisions: " << c.collisions << endl;
198 cout << "r bumps: " << c.bumps << endl;
202 for (int i=0; i<ocount.size(); i++)
204 avg /= ocount.size();
206 for (int i=0; i<ocount.size(); i++)
207 var += (ocount[i] - avg) * (ocount[i] - avg);
208 var /= ocount.size();
210 cout << "avg " << avg << " var " << var << " sd " << sqrt(var) << endl;
218 cout << "total variance " << tvar << endl;