support monitor

This commit is contained in:
bohanjason 2020-05-29 00:17:35 -04:00 committed by Bohan Zhang
parent c31b9f2490
commit 09226edece
4 changed files with 42 additions and 19 deletions

View File

@ -56,6 +56,7 @@ public class Main {
private static boolean keepRunning = true; private static boolean keepRunning = true;
private static boolean firstCollecting = false; private static boolean firstCollecting = false;
@SuppressWarnings("restriction")
public static void main(String[] args) { public static void main(String[] args) {
// Initialize log4j // Initialize log4j
@ -137,13 +138,13 @@ public class Main {
} }
DBCollector collector = getCollector(config); DBCollector collector = getCollector(config);
try {
// add a signal handler
Signal.handle(new Signal("INT"), signal -> firstCollecting = true);
File f = new File("pid.txt"); File f = new File("pid.txt");
try {
// get pid of this process and write the pid to a file before recording the start time // get pid of this process and write the pid to a file before recording the start time
if (time < 0) { if (time < 0) {
// add a signal handler
Signal.handle(new Signal("INT"), signal -> firstCollecting = true);
String vmName = ManagementFactory.getRuntimeMXBean().getName(); String vmName = ManagementFactory.getRuntimeMXBean().getName();
int p = vmName.indexOf("@"); int p = vmName.indexOf("@");
int pid = Integer.valueOf(vmName.substring(0, p)); int pid = Integer.valueOf(vmName.substring(0, p));
@ -157,6 +158,9 @@ public class Main {
ioe.printStackTrace(); ioe.printStackTrace();
} }
} }
else {
firstCollecting = true;
}
LOG.info("Output the process pid to pid.txt"); LOG.info("Output the process pid to pid.txt");
while (!firstCollecting) { while (!firstCollecting) {
@ -185,9 +189,6 @@ public class Main {
knobsWriter.println(knobs); knobsWriter.println(knobs);
knobsWriter.close(); knobsWriter.close();
// add a signal handler
Signal.handle(new Signal("INT"), signal -> keepRunning = false);
// record start time // record start time
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
LOG.info("Starting the experiment ..."); LOG.info("Starting the experiment ...");
@ -196,6 +197,8 @@ public class Main {
if (time >= 0) { if (time >= 0) {
Thread.sleep(time * TO_MILLISECONDS); Thread.sleep(time * TO_MILLISECONDS);
} else { } else {
// add a signal handler
Signal.handle(new Signal("INT"), signal -> keepRunning = false);
while (keepRunning) { while (keepRunning) {
Thread.sleep(1); Thread.sleep(1);
} }

View File

@ -153,6 +153,10 @@ OLTPBENCH_BENCH = 'tpcc'
# CONTROLLER OPTIONS # CONTROLLER OPTIONS
#========================================================== #==========================================================
# Controller observation time, OLTPBench will be disabled for
# monitoring if the time is specified
CONTROLLER_OBSERVE_SEC = 100
# Path to the controller directory # Path to the controller directory
CONTROLLER_HOME = DRIVER_HOME + '/../controller' CONTROLLER_HOME = DRIVER_HOME + '/../controller'

View File

@ -308,11 +308,11 @@ def run_oltpbench_bg():
@task @task
def run_controller(): def run_controller(interval_sec=-1):
LOG.info('Controller config path: %s', dconf.CONTROLLER_CONFIG) LOG.info('Controller config path: %s', dconf.CONTROLLER_CONFIG)
create_controller_config() create_controller_config()
cmd = 'gradle run -PappArgs="-c {} -d output/" --no-daemon > {}'.\ cmd = 'gradle run -PappArgs="-c {} -t {} -d output/" --no-daemon > {}'.\
format(dconf.CONTROLLER_CONFIG, dconf.CONTROLLER_LOG) format(dconf.CONTROLLER_CONFIG, interval_sec, dconf.CONTROLLER_LOG)
with lcd(dconf.CONTROLLER_HOME): # pylint: disable=not-context-manager with lcd(dconf.CONTROLLER_HOME): # pylint: disable=not-context-manager
local(cmd) local(cmd)
@ -642,7 +642,13 @@ def clean_logs():
@task @task
def clean_oltpbench_results(): def clean_oltpbench_results():
# remove oltpbench result files # remove oltpbench result files
local('rm -f {}/results/*'.format(dconf.OLTPBENCH_HOME)) local('rm -f {}/results/outputfile*'.format(dconf.OLTPBENCH_HOME))
@task
def clean_controller_results():
# remove oltpbench result files
local('rm -f {}/output/*.json'.format(dconf.CONTROLLER_HOME))
def _set_oltpbench_property(name, line): def _set_oltpbench_property(name, line):
@ -820,6 +826,16 @@ def run_loops(max_iter=10):
LOG.info('The %s-th Loop Ends / Total Loops %s', i + 1, max_iter) LOG.info('The %s-th Loop Ends / Total Loops %s', i + 1, max_iter)
@task
def monitor(max_iter=1):
for i in range(int(max_iter)):
LOG.info('The %s-th Monitor Loop Starts / Total Loops %s', i + 1, max_iter)
clean_controller_results()
run_controller(interval_sec=dconf.CONTROLLER_OBSERVE_SEC)
upload_result()
LOG.info('The %s-th Monitor Loop 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

View File

@ -205,8 +205,8 @@ def project_sessions_view(request, project_id):
'button_create': 'create a new session', 'button_create': 'create a new session',
})) }))
form_labels['title'] = "Your Sessions" form_labels['title'] = "Your Sessions"
form_labels['description'] = "description" form_labels['description'] = "Description"
form_labels['result_count'] = "# result" form_labels['result_count'] = "# Result"
for session in sessions: for session in sessions:
session.session_type_name = Session.TUNING_OPTIONS[session.tuning_session] session.session_type_name = Session.TUNING_OPTIONS[session.tuning_session]
session.algorithm_name = AlgorithmType.name(session.algorithm) session.algorithm_name = AlgorithmType.name(session.algorithm)
@ -506,13 +506,13 @@ def handle_result_files(session, files, execution_times=None):
target_instance = target_objectives.get_instance(dbms_id, target_name) target_instance = target_objectives.get_instance(dbms_id, target_name)
if target_instance.is_udf() and len(udm_all) == 0: if target_instance.is_udf() and len(udm_all) == 0:
return HttpResponse('ERROR: user defined target objective {} is not uploaded!'.format( return HttpResponse('ERROR: user defined target objective {} is not uploaded!'.format(
target_name)) target_name), status=400)
if len(udm_all) > 0: if len(udm_all) > 0:
# Note: Here we assume that for sessions with same dbms, user defined metrics are same. # Note: Here we assume that for sessions with same dbms, user defined metrics are same.
# Otherwise there may exist inconsistency, it becomes worse after restarting web server. # Otherwise there may exist inconsistency, it becomes worse after restarting web server.
if target_instance.is_udf() and (target_name not in udm_all.keys()): if target_instance.is_udf() and (target_name not in udm_all.keys()):
return HttpResponse('ERROR: user defined target objective {} is not uploaded!'.format( return HttpResponse('ERROR: user defined target objective {} is not uploaded!'.format(
target_name)) target_name), status=400)
if not target_objectives.udm_registered(dbms_id): if not target_objectives.udm_registered(dbms_id):
target_objectives.register_udm(dbms_id, udm_all) target_objectives.register_udm(dbms_id, udm_all)
for name, info in udm_all.items(): for name, info in udm_all.items():
@ -646,7 +646,7 @@ def handle_result_files(session, files, execution_times=None):
if not re.match('^[a-zA-Z0-9_-]+$', workload_name): if not re.match('^[a-zA-Z0-9_-]+$', workload_name):
return HttpResponse('Your workload name ' + workload_name + ' contains ' return HttpResponse('Your workload name ' + workload_name + ' contains '
'invalid characters! It should only contain ' 'invalid characters! It should only contain '
'alpha-numeric, underscore(_) and hyphen(-)') 'alpha-numeric, underscore(_) and hyphen(-)', status=400)
try: try:
# Check that we support this DBMS and version # Check that we support this DBMS and version
@ -658,20 +658,20 @@ def handle_result_files(session, files, execution_times=None):
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
LOG.warning('Cannot parse dbms version %s', dbms_version) LOG.warning('Cannot parse dbms version %s', dbms_version)
return HttpResponse('{} v{} is not yet supported.'.format( return HttpResponse('{} v{} is not yet supported.'.format(
dbms_type, dbms_version)) dbms_type, dbms_version), status=400)
try: try:
# Check that we support this DBMS and version # Check that we support this DBMS and version
dbms = DBMSCatalog.objects.get( dbms = DBMSCatalog.objects.get(
type=dbms_type, version=dbms_version) type=dbms_type, version=dbms_version)
except ObjectDoesNotExist: except ObjectDoesNotExist:
return HttpResponse('{} v{} is not yet supported.'.format( return HttpResponse('{} v{} is not yet supported.'.format(
dbms_type, dbms_version)) dbms_type, dbms_version), status=400)
if dbms != session.dbms: if dbms != session.dbms:
return HttpResponse('The DBMS must match the type and version ' return HttpResponse('The DBMS must match the type and version '
'specified when creating the session. ' 'specified when creating the session. '
'(expected=' + session.dbms.full_name + ') ' '(expected=' + session.dbms.full_name + ') '
'(actual=' + dbms.full_name + ')') '(actual=' + dbms.full_name + ')', status=400)
# Load, process, and store the knobs in the DBMS's configuration # Load, process, and store the knobs in the DBMS's configuration
knob_dict, knob_diffs = parser.parse_dbms_knobs( knob_dict, knob_diffs = parser.parse_dbms_knobs(