set dynamic knobs in driver

This commit is contained in:
bohanjason 2020-05-29 21:27:34 -04:00 committed by Bohan Zhang
parent c8996382dc
commit 69ef3b7d0d
1 changed files with 46 additions and 0 deletions

View File

@ -786,6 +786,38 @@ def loop(i):
# change config # change config
change_conf(response['recommendation']) change_conf(response['recommendation'])
@task
def set_dynamic_knobs(recommendation, context):
DYNAMIC = 'dynamic' # pylint: disable=invalid-name
RESTART = 'restart' # pylint: disable=invalid-name
UNKNOWN = 'unknown' # pylint: disable=invalid-name
if dconf.DB_TYPE == 'mysql':
cmd_fmt = "mysql --user={} --password={} -e 'SET GLOBAL {}={}'".format
else:
raise Exception('database {} set dynamic knob function is not implemented.'.format(
dconf.DB_TYPE))
LOG.info('Start setting knobs dynamically.')
with hide('everything'), settings(warn_only=True): # pylint: disable=not-context-manager
for knob, value in recommendation.items():
mode = context.get(knob, UNKNOWN)
if mode == DYNAMIC:
res = run(cmd_fmt(dconf.DB_USER, dconf.DB_PASSWORD, knob, value))
elif mode == RESTART:
LOG.error('Knob %s cannot be set dynamically, restarting database is required, '
'ignore this knob.', knob)
continue
elif mode == UNKNOWN:
LOG.warning('It is unclear whether knob %s can be set dynamically or not, '
'set it anyway', knob)
res = run(cmd_fmt(dconf.DB_USER, dconf.DB_PASSWORD, knob, value))
if res.failed:
LOG.error('Failed to set knob %s to value %s', knob, value)
LOG.error(res)
LOG.info('Finish setting knobs dynamically.')
@task @task
def run_loops(max_iter=10): def run_loops(max_iter=10):
# dump database if it's not done before. # dump database if it's not done before.
@ -828,6 +860,7 @@ def run_loops(max_iter=10):
@task @task
def monitor(max_iter=1): def monitor(max_iter=1):
# Monitor the database, without tuning. OLTPBench is also disabled
for i in range(int(max_iter)): for i in range(int(max_iter)):
LOG.info('The %s-th Monitor Loop Starts / Total Loops %s', i + 1, max_iter) LOG.info('The %s-th Monitor Loop Starts / Total Loops %s', i + 1, max_iter)
clean_controller_results() clean_controller_results()
@ -836,6 +869,19 @@ def monitor(max_iter=1):
LOG.info('The %s-th Monitor Loop Ends / Total Loops %s', i + 1, max_iter) LOG.info('The %s-th Monitor Loop Ends / Total Loops %s', i + 1, max_iter)
@task
def monitor_tune(max_iter=1):
# Monitor the database, with tuning. OLTPBench is also disabled
for i in range(int(max_iter)):
LOG.info('The %s-th Monitor Loop (with Tuning) Starts / Total Loops %s', i + 1, max_iter)
clean_controller_results()
run_controller(interval_sec=dconf.CONTROLLER_OBSERVE_SEC)
upload_result()
response = get_result()
set_dynamic_knobs(response['recommendation'], response['context'])
LOG.info('The %s-th Monitor Loop (with Tuning) Ends / Total Loops %s', i + 1, max_iter)
@task @task
def rename_batch(result_dir=None): def rename_batch(result_dir=None):
result_dir = result_dir or dconf.RESULT_DIR result_dir = result_dir or dconf.RESULT_DIR