Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

do reweight for balance the PGS of osds #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conf/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def list_required_config(self):
required_list["system"]["disk|read_ahead_kb"] = 2048
required_list["ceph_tuning"] = OrderedDict()
required_list["ceph_tuning"]["pool|rbd|size"] = 2
required_list["ceph_tuning"]["pool|rbd|reweight_enable"] = "true"
required_list["ceph_tuning"]["pool|rbd|reweight_target"] = 0.05
required_list["ceph_tuning"]["global|mon_pg_warn_max_per_osd"] = 1000
required_list["analyzer"] = OrderedDict()
required_list["analyzer"]["analyzer"] = "all"
Expand Down
62 changes: 62 additions & 0 deletions tuner/reweight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os,sys
lib_path = os.path.abspath(os.path.join('../conf/'))
sys.path.append(lib_path)
from conf import *
import time

class Reweight:
def __init__(self, target):
self.oload = 101
self.max_change = 0.01
self.max_change_osds = 2
self.target = float(target)
self.max_time_re = 300
self.max_count_re = 1000
self.t_start = 0
self.t_end = 0
self.count_re = 0
self.result = []
self.isFitTarget = False

def Doreweight(self, oload, max_change, max_change_osds):
common.bash("ceph osd reweight-by-pg %s %s %s" % (oload, max_change, max_change_osds))

def GetPgs(self):
out = common.bash("ceph osd df | awk '{print $9}'")
pgsList = [int(x) for x in out.split('\n') if x != '' and x != 'PGS']
return pgsList

def GetValueDiff(self, pgs):
if pgs:
diff = round((max(pgs)-min(pgs))*1.0/max(pgs),3)
else:
diff = -1
self.result.append([self.count_re, diff])
print self.count_re, diff, pgs
return diff

def main(self):
for i in range(3):
self.t_start = time.time()
while True:
diff = self.GetValueDiff(self.GetPgs())
self.t_end = time.time()
self.count_re += 1
if diff < self.target or self.max_count_re < self.count_re or self.max_time_re < self.t_end - self.t_start:
if diff < self.target:
self.isFitTarget = True
common.printout("LOG", "reweight complete.")
break
else:
self.Doreweight(self.oload, self.max_change, self.max_change_osds)
time.sleep(0.5)
if self.isFitTarget:
break
else:
self.target += 0.01
if not self.isFitTarget:
common.printout("WARNING", "after reweight, the diff of PGS also too large!")

def do(target):
re = Reweight(target)
re.main()
10 changes: 10 additions & 0 deletions tuner/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import argparse
import threading
import reweight

pp = pprint.PrettyPrinter(indent=4)
class Tuner:
Expand Down Expand Up @@ -324,6 +325,9 @@ def apply_tuning(self, jobname, no_check = False):
if self.worksheet[jobname]['pool'][new_poolname][param] != latest_pool_config[new_poolname][param]:
self.handle_pool(option = 'set', param = {'name':new_poolname, param:self.worksheet[jobname]['pool'][new_poolname][param]})

if not pool_exist and self.worksheet[jobname]['pool'][new_poolname]['reweight_enable'] == 'true':
self.handle_pool(option = 'reweight', param = {'reweight_target':self.worksheet[jobname]['pool'][new_poolname]['reweight_target']})

if no_check:
return

Expand Down Expand Up @@ -359,6 +363,12 @@ def handle_pool(self, option="set", param = {}):
common.printout("LOG","delete ceph pool %s" % pool)
common.pdsh(user, [controller], "ceph osd pool delete %s %s --yes-i-really-really-mean-it" % (pool, pool), option="check_return")

if option == "reweight":
common.printout("LOG", "start reweight, target: %s" % param['reweight_target'])
reweight.do(param['reweight_target'])
common.printout("LOG", "reweight complete.")


def main(args):
print args
tuner_parser = argparse.ArgumentParser(description='Tuner.')
Expand Down