Skip to content

Commit

Permalink
decay: separate fixed DecayRate from DecayCounter
Browse files Browse the repository at this point in the history
Avoid eating a double per instance.
  • Loading branch information
liewegas committed Mar 8, 2010
1 parent fdb85ca commit fb5ecb9
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 127 deletions.
6 changes: 0 additions & 6 deletions src/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ bugs
- osd pg split breaks if not all osds are up...
- mislinked directory? (cpusr.sh, mv /c/* /c/t, more cpusr, ls /c/t)

?- kclient: after reconnect,
cp: writing `/c/ceph2.2/bin/gs-gpl': Bad file descriptor
- need to somehow wake up unreconnected caps? hrm!!

?- kclient: socket creation

- snaprealm thing
ceph3:~# find /c
/c
Expand Down
53 changes: 27 additions & 26 deletions src/common/DecayCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,22 @@
*
*/

class DecayRate {
double k; // k = ln(.5)/half_life

friend class DecayCounter;

public:
DecayRate() : k(0) {}
DecayRate(double hl) { set_halflife(hl); }
void set_halflife(double hl) {
k = log(.5) / hl;
}
};

class DecayCounter {
protected:
public:
double k; // k = ln(.5)/half_life
double val; // value
double delta; // delta since last decay
double vel; // recent velocity
Expand All @@ -41,9 +53,8 @@ class DecayCounter {
public:

void encode(bufferlist& bl) const {
__u8 struct_v = 2;
__u8 struct_v = 3;
::encode(struct_v, bl);
::encode(k, bl);
::encode(val, bl);
::encode(delta, bl);
::encode(vel, bl);
Expand All @@ -55,31 +66,25 @@ class DecayCounter {
double half_life;
::decode(half_life, p);
}
::decode(k, p);
if (struct_v < 3) {
double k;
::decode(k, p);
}
::decode(val, p);
::decode(delta, p);
::decode(vel, p);
}

DecayCounter() : val(0), delta(0), vel(0) {
set_halflife( g_conf.mds_decay_halflife );
reset();
}
DecayCounter(double hl) : val(0), delta(0), vel(0) {
set_halflife( hl );
reset();
}

/**
* reading
*/

double get() {
return get(g_clock.now());
}

double get(utime_t now) {
decay(now);
double get(utime_t now, const DecayRate& rate) {
decay(now, rate);
return val;
}

Expand All @@ -99,17 +104,17 @@ class DecayCounter {
* adjusting
*/

double hit(utime_t now, double v = 1.0) {
decay(now);
double hit(utime_t now, const DecayRate& rate, double v = 1.0) {
decay(now, rate);
delta += v;
return val+delta;
}

void adjust(double a) {
val += a;
}
void adjust(utime_t now, double a) {
decay(now);
void adjust(utime_t now, const DecayRate& rate, double a) {
decay(now, rate);
val += a;
}
void scale(double f) {
Expand All @@ -122,10 +127,6 @@ class DecayCounter {
* decay etc.
*/

void set_halflife(double hl) {
k = log(.5) / hl;
}

void reset() {
reset(g_clock.now());
}
Expand All @@ -134,18 +135,18 @@ class DecayCounter {
val = delta = 0;
}

void decay(utime_t now) {
void decay(utime_t now, const DecayRate &rate) {
utime_t el = now;
el -= last_decay;

if (el.sec() >= 1) {
// calculate new value
double newval = (val+delta) * exp((double)el * k);
double newval = (val+delta) * exp((double)el * rate.k);
if (newval < .01) newval = 0.0;

// calculate velocity approx
vel += (newval - val) * (double)el;
vel *= exp((double)el * k);
vel *= exp((double)el * rate.k);

val = newval;
delta = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/mds/CDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,15 @@ void CDir::split(int bits, list<CDir*>& subs, list<Context*>& waiters, bool repl
f->set_version(get_version());

f->pop_me = pop_me;
f->pop_me *= fac;
f->pop_me.scale(fac);

// FIXME; this is an approximation
f->pop_nested = pop_nested;
f->pop_nested *= fac;
f->pop_nested.scale(fac);
f->pop_auth_subtree = pop_auth_subtree;
f->pop_auth_subtree *= fac;
f->pop_auth_subtree.scale(fac);
f->pop_auth_subtree_nested = pop_auth_subtree_nested;
f->pop_auth_subtree_nested *= fac;
f->pop_auth_subtree_nested.scale(fac);

dout(10) << " subfrag " << *p << " " << *f << dendl;
subfrags[n++] = f;
Expand Down Expand Up @@ -1743,14 +1743,14 @@ void CDir::encode_export(bufferlist& bl)

void CDir::finish_export(utime_t now)
{
pop_auth_subtree_nested -= pop_auth_subtree;
pop_auth_subtree_nested.sub(now, cache->decayrate, pop_auth_subtree);
pop_me.zero(now);
pop_auth_subtree.zero(now);
put(PIN_TEMPEXPORTING);
dirty_old_rstat.clear();
}

void CDir::decode_import(bufferlist::iterator& blp)
void CDir::decode_import(bufferlist::iterator& blp, utime_t now)
{
::decode(first, blp);
::decode(fnode, blp);
Expand All @@ -1769,7 +1769,7 @@ void CDir::decode_import(bufferlist::iterator& blp)

::decode(pop_me, blp);
::decode(pop_auth_subtree, blp);
pop_auth_subtree_nested += pop_auth_subtree;
pop_auth_subtree_nested.add(now, cache->decayrate, pop_auth_subtree);

::decode(dir_rep_by, blp);
::decode(replica_map, blp);
Expand Down
2 changes: 1 addition & 1 deletion src/mds/CDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class CDir : public MDSCacheObject {
void abort_export() {
put(PIN_TEMPEXPORTING);
}
void decode_import(bufferlist::iterator& blp);
void decode_import(bufferlist::iterator& blp, utime_t now);


// -- auth pins --
Expand Down
60 changes: 30 additions & 30 deletions src/mds/MDBalancer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ double mds_load_t::mds_load()
return 0;
}

mds_load_t MDBalancer::get_load()
mds_load_t MDBalancer::get_load(utime_t now)
{
mds_load_t load;

Expand All @@ -150,8 +150,8 @@ mds_load_t MDBalancer::get_load()
for (list<CDir*>::iterator p = ls.begin();
p != ls.end();
p++) {
load.auth += (*p)->pop_auth_subtree_nested;
load.all += (*p)->pop_nested;
load.auth.add(now, mds->mdcache->decayrate, (*p)->pop_auth_subtree_nested);
load.all.add(now, mds->mdcache->decayrate, (*p)->pop_nested);
}
} else {
dout(20) << "get_load no root, no load" << dendl;
Expand Down Expand Up @@ -182,7 +182,7 @@ void MDBalancer::send_heartbeat()
beat_epoch++;

// my load
mds_load_t load = get_load();
mds_load_t load = get_load(now);
mds_load[ mds->get_nodeid() ] = load;

// import_map -- how much do i import from whom
Expand All @@ -196,7 +196,7 @@ void MDBalancer::send_heartbeat()
int from = im->inode->authority().first;
if (from == mds->get_nodeid()) continue;
if (im->get_inode()->is_stray()) continue;
import_map[from] += im->pop_auth_subtree.meta_load(now);
import_map[from] += im->pop_auth_subtree.meta_load(now, mds->mdcache->decayrate);
}
mds_import_map[ mds->get_nodeid() ] = import_map;

Expand Down Expand Up @@ -359,7 +359,7 @@ void MDBalancer::prep_rebalance(int beat)
// rescale! turn my mds_load back into meta_load units
double load_fac = 1.0;
if (mds_load[whoami].mds_load() > 0) {
double metald = mds_load[whoami].auth.meta_load(rebalance_time);
double metald = mds_load[whoami].auth.meta_load(rebalance_time, mds->mdcache->decayrate);
double mdsld = mds_load[whoami].mds_load();
load_fac = metald / mdsld;
dout(7) << " load_fac is " << load_fac
Expand Down Expand Up @@ -530,7 +530,7 @@ void MDBalancer::try_rebalance()
CDir *im = *it;
if (im->get_inode()->is_stray()) continue;

double pop = im->pop_auth_subtree.meta_load(rebalance_time);
double pop = im->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate);
if (g_conf.mds_bal_idle_threshold > 0 &&
pop < g_conf.mds_bal_idle_threshold &&
im->inode != mds->mdcache->get_root() &&
Expand Down Expand Up @@ -597,7 +597,7 @@ void MDBalancer::try_rebalance()

if (dir->inode->is_root()) continue;
if (dir->is_freezing() || dir->is_frozen()) continue; // export pbly already in progress
double pop = dir->pop_auth_subtree.meta_load(rebalance_time);
double pop = dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate);
assert(dir->inode->authority().first == target); // cuz that's how i put it in the map, dummy

if (pop <= amount-have) {
Expand Down Expand Up @@ -665,7 +665,7 @@ void MDBalancer::try_rebalance()
dout(-5) << " - exporting "
<< (*it)->pop_auth_subtree
<< " "
<< (*it)->pop_auth_subtree.meta_load(rebalance_time)
<< (*it)->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate)
<< " to mds" << target
<< " " << **it
<< dendl;
Expand Down Expand Up @@ -729,7 +729,7 @@ void MDBalancer::find_exports(CDir *dir,
list<CDir*> bigger_rep, bigger_unrep;
multimap<double, CDir*> smaller;

double dir_pop = dir->pop_auth_subtree.meta_load(rebalance_time);
double dir_pop = dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate);
dout(7) << " find_exports in " << dir_pop << " " << *dir << " need " << need << " (" << needmin << " - " << needmax << ")" << dendl;

double subdir_sum = 0;
Expand All @@ -752,7 +752,7 @@ void MDBalancer::find_exports(CDir *dir,
if (subdir->is_frozen()) continue; // can't export this right now!

// how popular?
double pop = subdir->pop_auth_subtree.meta_load(rebalance_time);
double pop = subdir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate);
subdir_sum += pop;
dout(15) << " subdir pop " << pop << " " << *subdir << dendl;

Expand Down Expand Up @@ -833,7 +833,7 @@ void MDBalancer::find_exports(CDir *dir,
void MDBalancer::hit_inode(utime_t now, CInode *in, int type, int who)
{
// hit inode
in->pop.get(type).hit(now);
in->pop.get(type).hit(now, mds->mdcache->decayrate);

if (in->get_parent_dn())
hit_dir(now, in->get_parent_dn()->get_dir(), type, who);
Expand Down Expand Up @@ -892,15 +892,15 @@ void MDBalancer::hit_dir(utime_t now, CDir *dir, int type, int who, double amoun

// replicate?
if (type == META_POP_IRD && who >= 0) {
dir->pop_spread.hit(now, who);
dir->pop_spread.hit(now, mds->mdcache->decayrate, who);
}

double rd_adj = 0;
if (type == META_POP_IRD &&
dir->last_popularity_sample < last_sample) {
float dir_pop = dir->pop_auth_subtree.get(type).get(now); // hmm??
float dir_pop = dir->pop_auth_subtree.get(type).get(now, mds->mdcache->decayrate); // hmm??
dir->last_popularity_sample = last_sample;
float pop_sp = dir->pop_spread.get(now);
float pop_sp = dir->pop_spread.get(now, mds->mdcache->decayrate);
dir_pop += pop_sp * 10;

//if (dir->ino() == inodeno_t(0x10000000002))
Expand All @@ -917,7 +917,7 @@ void MDBalancer::hit_dir(utime_t now, CDir *dir, int type, int who, double amoun
if (!dir->is_rep() &&
dir_pop >= g_conf.mds_bal_replicate_threshold) {
// replicate
float rdp = dir->pop_me.get(META_POP_IRD).get(now);
float rdp = dir->pop_me.get(META_POP_IRD).get(now, mds->mdcache->decayrate);
rd_adj = rdp / mds->get_mds_map()->get_num_mds() - rdp;
rd_adj /= 2.0; // temper somewhat

Expand Down Expand Up @@ -950,18 +950,18 @@ void MDBalancer::hit_dir(utime_t now, CDir *dir, int type, int who, double amoun
while (1) {
dir->pop_nested.get(type).hit(now, amount);
if (rd_adj != 0.0)
dir->pop_nested.get(META_POP_IRD).adjust(now, rd_adj);
dir->pop_nested.get(META_POP_IRD).adjust(now, mds->mdcache->decayrate, rd_adj);

if (hit_subtree) {
dir->pop_auth_subtree.get(type).hit(now, amount);
if (rd_adj != 0.0)
dir->pop_auth_subtree.get(META_POP_IRD).adjust(now, rd_adj);
dir->pop_auth_subtree.get(META_POP_IRD).adjust(now, mds->mdcache->decayrate, rd_adj);
}

if (hit_subtree_nested) {
dir->pop_auth_subtree_nested.get(type).hit(now, amount);
dir->pop_auth_subtree_nested.get(type).hit(now, mds->mdcache->decayrate, amount);
if (rd_adj != 0.0)
dir->pop_auth_subtree_nested.get(META_POP_IRD).adjust(now, rd_adj);
dir->pop_auth_subtree_nested.get(META_POP_IRD).adjust(now, mds->mdcache->decayrate, rd_adj);
}

if (dir->is_subtree_root())
Expand All @@ -981,30 +981,30 @@ void MDBalancer::hit_dir(utime_t now, CDir *dir, int type, int who, double amoun
* NOTE: call me _after_ forcing *dir into a subtree root,
* but _before_ doing the encode_export_dirs.
*/
void MDBalancer::subtract_export(CDir *dir)
void MDBalancer::subtract_export(CDir *dir, utime_t now)
{
dirfrag_load_vec_t subload = dir->pop_auth_subtree;

while (true) {
dir = dir->inode->get_parent_dir();
if (!dir) break;

dir->pop_nested -= subload;
dir->pop_auth_subtree_nested -= subload;
dir->pop_nested.sub(now, mds->mdcache->decayrate, subload);
dir->pop_auth_subtree_nested.sub(now, mds->mdcache->decayrate, subload);
}
}


void MDBalancer::add_import(CDir *dir)
void MDBalancer::add_import(CDir *dir, utime_t now)
{
dirfrag_load_vec_t subload = dir->pop_auth_subtree;

while (true) {
dir = dir->inode->get_parent_dir();
if (!dir) break;

dir->pop_nested += subload;
dir->pop_auth_subtree_nested += subload;
dir->pop_nested.add(now, mds->mdcache->decayrate, subload);
dir->pop_auth_subtree_nested.add(now, mds->mdcache->decayrate, subload);
}
}

Expand Down Expand Up @@ -1057,10 +1057,10 @@ void MDBalancer::dump_pop_map()
++p) {
CDir *dir = *p;

myfile << (int)dir->pop_me.meta_load(now) << "\t";
myfile << (int)dir->pop_nested.meta_load(now) << "\t";
myfile << (int)dir->pop_auth_subtree.meta_load(now) << "\t";
myfile << (int)dir->pop_auth_subtree_nested.meta_load(now) << "\t";
myfile << (int)dir->pop_me.meta_load(now, mds->mdcache->decayrate) << "\t";
myfile << (int)dir->pop_nested.meta_load(now, mds->mdcache->decayrate) << "\t";
myfile << (int)dir->pop_auth_subtree.meta_load(now, mds->mdcache->decayrate) << "\t";
myfile << (int)dir->pop_auth_subtree_nested.meta_load(now, mds->mdcache->decayrate) << "\t";

// filename last
string p;
Expand Down
Loading

0 comments on commit fb5ecb9

Please sign in to comment.