From 8dd2f473bf6920c568c47d2fde00d0c4cb0433dd Mon Sep 17 00:00:00 2001 From: sage Date: Fri, 8 Jul 2005 07:12:03 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@424 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/mds/MDBalancer.cc | 129 ++++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 33 deletions(-) diff --git a/ceph/mds/MDBalancer.cc b/ceph/mds/MDBalancer.cc index 0a077a306b169..b0d145f0a1a15 100644 --- a/ceph/mds/MDBalancer.cc +++ b/ceph/mds/MDBalancer.cc @@ -171,6 +171,7 @@ void MDBalancer::do_rebalance() double my_load = mds_load[whoami].root_pop; mds_load_t target_load = total_load / (double)cluster_size; + double target_root = target_load.root_pop; dout(5) << " target load " << target_load << endl; @@ -185,39 +186,101 @@ void MDBalancer::do_rebalance() // determine load transfer mapping multimap my_targets; - multimap::reverse_iterator exporter = load_map.rbegin(); - multimap::iterator importer = load_map.begin(); - double imported = 0; - double exported = 0; - while (exporter != load_map.rend() && - importer != load_map.end()) { - double maxex = (*exporter).first - target_load.root_pop - exported; - double maxim = target_load.root_pop - (*importer).first - imported; - if (maxex < 0 || - maxim < 0) break; - - if (maxim < maxex) { // import takes it all - dout(5) << " - mds" << (*exporter).second << " exports " << maxim << " to mds" << (*importer).second << endl; - if ((*exporter).second == whoami) - my_targets.insert(pair((*importer).second, maxim)); - exported += maxim; - importer++; - imported = 0; - } - else if (maxim > maxex) { // export all - dout(5) << " - mds" << (*exporter).second << " exports " << maxex << " to mds" << (*importer).second << endl; - if ((*exporter).second == whoami) - my_targets.insert(pair((*importer).second, maxex)); - imported += maxex; - exporter++; - exported = 0; - } else { - // wow, perfect match! - dout(5) << " - mds" << (*exporter).second << " exports " << maxex << " to mds" << (*importer).second << endl; - if ((*exporter).second == whoami) - my_targets.insert(pair((*importer).second, maxex)); - imported = exported = 0; - importer++; importer++; + + if (0) { + // old way + + // match up big exporters with big importers + multimap::reverse_iterator exporter = load_map.rbegin(); + multimap::iterator importer = load_map.begin(); + double imported = 0; + double exported = 0; + while (exporter != load_map.rend() && + importer != load_map.end()) { + double maxex = (*exporter).first - target_load.root_pop - exported; + double maxim = target_load.root_pop - (*importer).first - imported; + if (maxex < 0 || + maxim < 0) break; + + if (maxim < maxex) { // import takes it all + dout(5) << " - mds" << (*exporter).second << " exports " << maxim << " to mds" << (*importer).second << endl; + if ((*exporter).second == whoami) + my_targets.insert(pair((*importer).second, maxim)); + exported += maxim; + importer++; + imported = 0; + } + else if (maxim > maxex) { // export all + dout(5) << " - mds" << (*exporter).second << " exports " << maxex << " to mds" << (*importer).second << endl; + if ((*exporter).second == whoami) + my_targets.insert(pair((*importer).second, maxex)); + imported += maxex; + exporter++; + exported = 0; + } else { + // wow, perfect match! + dout(5) << " - mds" << (*exporter).second << " exports " << maxex << " to mds" << (*importer).second << endl; + if ((*exporter).second == whoami) + my_targets.insert(pair((*importer).second, maxex)); + imported = exported = 0; + importer++; importer++; + } + } + } else { + // new way + + // first separate exporters and importers + multimap importers; + multimap exporters; + + for (multimap::iterator it = load_map.begin(); + it != load_map.end(); + it++) { + if (it->first < target_root) { + //dout(5) << " mds" << it->second << " is importer" << endl; + importers.insert(pair(it->first,it->second)); + } else { + //dout(5) << " mds" << it->second << " is exporter" << endl; + exporters.insert(pair(it->first,it->second)); + } + } + + // now match them up.. big exporters with small importers! + multimap::iterator ex = exporters.begin(); + multimap::iterator im = importers.begin(); + double imported = 0; + double exported = 0; + while (ex != exporters.end() && + im != importers.end()) { + double maxex = ex->first - target_load.root_pop - exported; + double maxim = target_load.root_pop - im->first - imported; + + if (maxex < 0 || + maxim < 0) break; + + if (maxim < maxex) { // import takes it all + dout(5) << " - mds" << ex->second << " exports " << maxim << " to mds" << im->second << endl; + if (ex->second == whoami) + my_targets.insert(pair(im->second, maxim)); + exported += maxim; + im++; + imported = 0; + } + else if (maxim > maxex) { // export all + dout(5) << " - mds" << ex->second << " exports " << maxex << " to mds" << im->second << endl; + if (ex->second == whoami) + my_targets.insert(pair(im->second, maxex)); + imported += maxex; + ex++; + exported = 0; + } else { + // wow, perfect match! + dout(5) << " - mds" << ex->second << " exports " << maxex << " to mds" << im->second << endl; + if (ex->second == whoami) + my_targets.insert(pair(im->second, maxex)); + imported = exported = 0; + im++; ex++; + } } } -- 2.39.5