From cd87334e3f7b7803fd878a1d81d5f803a7f5ddb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=89=BA=E4=B8=B9?= <53546877+Craven1701@users.noreply.github.com> Date: Fri, 16 May 2025 16:51:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.config=5Ftuning=E4=B8=AD=E4=B8=BA?= =?UTF-8?q?=E8=B4=9F=E8=BD=BD=E7=9A=84default=5Fconfig=E5=8F=A0=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E8=B0=83=E4=BC=98=E6=8E=A8=E8=8D=90=E7=9A=84next=5Fco?= =?UTF-8?q?nfig=E6=9C=80=E4=B8=BA=E6=9C=80=E7=BB=88=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E7=9A=84next=5Fconfig=202.=E4=BF=AE=E6=94=B9=5Frefresh=5Fbest?= =?UTF-8?q?=5Fconfig=E4=B8=BA=5Fprocess=5Fload=5Fconfig,=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=9C=A8=E5=89=8D=E5=8F=B0=E5=8A=AB=E6=8C=81?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=90=8E=EF=BC=8C=E6=98=AF=E5=90=A6=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=AF=B9load=E4=B8=AD=E5=B7=B2=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E5=90=84=E7=A7=8D=E9=85=8D=E7=BD=AE=E5=80=BC=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=B7=E6=96=B0=204.=E4=BC=98=E5=8C=96tuning=5Fresult?= =?UTF-8?q?=E4=B8=ADruntime=E5=87=BD=E6=95=B0=E5=92=8Ctrace=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=B3=E4=BA=8E=E7=A9=BA=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=203.=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/omniadvisor/interface/config_tuning.py | 5 ++++- .../omniadvisor/interface/hijack_recommend.py | 15 ++++++++++++--- .../service/tuning_result/tuning_result.py | 18 ++++++++++-------- .../interface/test_hijack_recommend.py | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/omniadvisor/src/omniadvisor/interface/config_tuning.py b/omniadvisor/src/omniadvisor/interface/config_tuning.py index c0a5523d4..6b8f6ee1a 100644 --- a/omniadvisor/src/omniadvisor/interface/config_tuning.py +++ b/omniadvisor/src/omniadvisor/interface/config_tuning.py @@ -46,7 +46,6 @@ def unified_tuning(load, retest_way: str, tuning_method: str): if tuning_method == OA_CONF.TuningMethod.iterative: perf_history = get_tuning_result_history(load) next_config = SmacAppendTuning.tune(perf_history.tuning_history) - TuningRecordRepository.create(load=load, config=next_config, method=OA_CONF.TuningMethod.iterative) elif tuning_method == OA_CONF.TuneMethod.expert: perf_history = get_tuning_result_history(load) next_config = ExpertTuning.tune(perf_history.tuning_history) @@ -54,6 +53,10 @@ def unified_tuning(load, retest_way: str, tuning_method: str): else: raise ValueError(f'Not supported tuning method: {tuning_method}') + # 用户的default_config上叠加next_config叠加 + next_config = load.default_config.copy().update(next_config) if load else next_config + TuningRecordRepository.create(load=load, config=next_config, method=tuning_method) + # 复测 if retest_way == OA_CONF.RetestWay.backend: retest(load, next_config) diff --git a/omniadvisor/src/omniadvisor/interface/hijack_recommend.py b/omniadvisor/src/omniadvisor/interface/hijack_recommend.py index 5578b88a9..4ea917abe 100644 --- a/omniadvisor/src/omniadvisor/interface/hijack_recommend.py +++ b/omniadvisor/src/omniadvisor/interface/hijack_recommend.py @@ -57,9 +57,18 @@ def _get_exec_config_from_load(load: Load): return load.default_config -def _refresh_best_config(load: Load): +def _process_load_config(load: Load): + """ + 1.检查当前负载中test_config是否完成复测流程 + 2.根据复测情况判断是否需要清空load中的test_config + 3.根据测试性能判断是否需要刷新load中保存的best_config + :param load: 本次测试用负载 + :return: + """ tuning_result = get_tuning_result(load, load.test_config) - if tuning_result.exam_times >= OA_CONF.tuning_retest_times: + if tuning_result.status == OA_CONF.ExecStatus.fail: + LoadRepository.update_test_config(load, {}) + elif tuning_result.status == OA_CONF.ExecStatus.success: # 获取当前best_config的平均测试性能 best_config_results = get_tuning_result(load, load.best_config) # 若调优性能优于最佳性能 刷新当前的best_config @@ -106,7 +115,7 @@ def hijack_recommend(spark_sql_cmd: str): print(output) if exec_config == load.test_config: - _refresh_best_config(load=load) + _process_load_config(load=load) def main(): diff --git a/omniadvisor/src/omniadvisor/service/tuning_result/tuning_result.py b/omniadvisor/src/omniadvisor/service/tuning_result/tuning_result.py index 34a993943..e61d9629a 100644 --- a/omniadvisor/src/omniadvisor/service/tuning_result/tuning_result.py +++ b/omniadvisor/src/omniadvisor/service/tuning_result/tuning_result.py @@ -95,27 +95,29 @@ class TuningResult: @property def runtime(self): - # 若配置未复测过,则runtime为失败返回值 - if not self._exam_records: - return OA_CONF.exec_fail_return_value - # 计算执行状态为success的平均runtime success_runtimes = [ exam_record.runtime for exam_record in self._exam_records if exam_record.status == OA_CONF.ExecStatus.success ] + + # 若配置成功复测的次数为0,则runtime为失败返回值 + if not success_runtimes: + return OA_CONF.exec_fail_return_runtime + return sum(success_runtimes) / len(success_runtimes) @property def trace(self): - # 若配置未复测过,则trace为失败返回值 - if not self._exam_records: - return OA_CONF.exec_fail_return_trace - success_exam_results = [ exam_record for exam_record in self._exam_records if exam_record.status == OA_CONF.ExecStatus.success ] + + # 若配置成功复测的次数为0,则trac为失败返回值 + if not success_exam_results: + return OA_CONF.exec_fail_return_trace + best_exam_record = min(success_exam_results, key=lambda exam_record: exam_record.runtime) return best_exam_record.trace diff --git a/omniadvisor/tests/omniadvisor/interface/test_hijack_recommend.py b/omniadvisor/tests/omniadvisor/interface/test_hijack_recommend.py index 7dfe1e947..8335adae7 100644 --- a/omniadvisor/tests/omniadvisor/interface/test_hijack_recommend.py +++ b/omniadvisor/tests/omniadvisor/interface/test_hijack_recommend.py @@ -48,7 +48,7 @@ class TestHijackRecommend(unittest.TestCase): @patch("omniadvisor.interface.hijack_recommend.SparkParameterParser") @patch("omniadvisor.interface.hijack_recommend.LoadRepository") @patch("omniadvisor.interface.hijack_recommend.spark_run") - @patch("omniadvisor.interface.hijack_recommend._refresh_best_config") + @patch("omniadvisor.interface.hijack_recommend._process_load_config") def test_hijack_recommend_failure_with_fallback(self, mock_refreshed_load, mock_spark_run, mock_load_repo, mock_parser): """ 测试 hijack_recommend 在任务失败且需要回退到用户默认配置时的行为。 -- Gitee From 86e25164da003b6becbff58d19e80a1b9e4c664d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=89=BA=E4=B8=B9?= <53546877+Craven1701@users.noreply.github.com> Date: Mon, 19 May 2025 10:30:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.next=5Fconfig=E4=B8=8Edefault=5Fconfig?= =?UTF-8?q?=E7=9A=84=E5=8F=A0=E5=8A=A0=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=202.=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- omniadvisor/src/omniadvisor/interface/config_tuning.py | 6 +++++- .../tests/omniadvisor/interface/test_config_tuning.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/omniadvisor/src/omniadvisor/interface/config_tuning.py b/omniadvisor/src/omniadvisor/interface/config_tuning.py index 6b8f6ee1a..221a22961 100644 --- a/omniadvisor/src/omniadvisor/interface/config_tuning.py +++ b/omniadvisor/src/omniadvisor/interface/config_tuning.py @@ -54,7 +54,11 @@ def unified_tuning(load, retest_way: str, tuning_method: str): raise ValueError(f'Not supported tuning method: {tuning_method}') # 用户的default_config上叠加next_config叠加 - next_config = load.default_config.copy().update(next_config) if load else next_config + if load: + next_config = {**load.default_config, **next_config} + else: + raise ValueError("Invalid load: configuration cannot be loaded") + TuningRecordRepository.create(load=load, config=next_config, method=tuning_method) # 复测 diff --git a/omniadvisor/tests/omniadvisor/interface/test_config_tuning.py b/omniadvisor/tests/omniadvisor/interface/test_config_tuning.py index 16c350e25..c437e60aa 100644 --- a/omniadvisor/tests/omniadvisor/interface/test_config_tuning.py +++ b/omniadvisor/tests/omniadvisor/interface/test_config_tuning.py @@ -12,7 +12,8 @@ class TestTuning: def setup_class(self): # 创建表 - self.load = None + self.load = MagicMock() + self.load.default_config = {"test_config": "1"} self.retest_times = 3 self.tuning_method = OA_CONF.TuningMethod.iterative @@ -88,7 +89,7 @@ class TestTuning: :return: """ sys.argv = ['config_tuning.py', - '--load-id', self.load, + '--load-id', None, '--retest-way', OA_CONF.RetestWay.backend, '--tuning-method', self.tuning_method] -- Gitee