From 3dbd88f4de51c296896d577cebd476ede9e5e321 Mon Sep 17 00:00:00 2001 From: gentle_hu Date: Thu, 4 Jan 2024 15:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E4=B8=8B=E5=BC=80=E7=AE=B1?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=95=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/impl/perf_config/probes/db.py | 37 ++++++++++++++----- script/impl/perf_config/tuners/gucs/common.py | 16 ++++++-- script/impl/perf_config/tuners/setup.py | 12 ++++-- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/script/impl/perf_config/probes/db.py b/script/impl/perf_config/probes/db.py index f441fd4..5a5f7a6 100644 --- a/script/impl/perf_config/probes/db.py +++ b/script/impl/perf_config/probes/db.py @@ -35,8 +35,8 @@ class DBSeverMode(Enum): class DBInfo(Probe): def __init__(self): super(DBInfo, self).__init__() - self.ip = None - self.port = None + self.ip = ['*'] + self.port = 5432 self.omm = Project.role.user_name self.omm_uid = Project.role.user_uid self.omm_gid = Project.role.user_gid @@ -44,22 +44,39 @@ class DBInfo(Probe): self.gauss_data = Project.environ.gauss_data self.gauss_log = Project.environ.gauss_log self.postgresql_conf = os.path.join(self.gauss_data, 'postgresql.conf') + self.init_done = True + self.is_single_node = True def detect(self): + if not os.access(self.postgresql_conf, os.F_OK): + Project.log(f'detect that database is not init done.') + self.init_done = False + self._detect_ip_port() + self._detect_is_single_node() def _detect_ip_port(self): + if not self.init_done: + return + listen_addresses = self._read_guc_in_postgresql_conf('listen_addresses') - if listen_addresses is None: - listen_addresses = '*' - Project.log(f'detect database listen_addresses: {listen_addresses}') - self.ip = [ip.strip() for ip in listen_addresses.split(',')] + if listen_addresses is not None: + Project.log(f'detect that database listen_addresses: {listen_addresses}') + self.ip = [ip.strip() for ip in listen_addresses.split(',')] port = self._read_guc_in_postgresql_conf('port') - if port is None: - port = 5432 - Project.log(f'detect database port: {port}') - self.port = port + if port is not None: + Project.log(f'detect that database port: {port}') + self.port = port + + def _detect_is_single_node(self): + if not self.init_done: + return + + replconninfo = self._read_guc_in_postgresql_conf('replconninfo1') + if replconninfo is not None: + self.is_single_node = False + Project.log('detect that database is cluster mode.') def _read_guc_in_postgresql_conf(self, guc): cmd = f'grep "{guc}" {self.postgresql_conf} -i' diff --git a/script/impl/perf_config/tuners/gucs/common.py b/script/impl/perf_config/tuners/gucs/common.py index 46bea01..b487885 100644 --- a/script/impl/perf_config/tuners/gucs/common.py +++ b/script/impl/perf_config/tuners/gucs/common.py @@ -238,10 +238,18 @@ class ThreadPoolGUC(GUCTuneGroup): def _calc_thread_count(self, infos, numa_bind_info): max_count = len(numa_bind_info['threadpool']) * 7.25 min_count = len(numa_bind_info['threadpool']) - value = infos.business.parallel / (1.2 if infos.business.scenario == BsScenario.TP_PERFORMANCE else 2) - - res = math.floor(max(min(max_count, value), min_count)) - return res + + ratio = 0.5 + if infos.db.is_single_node: + if infos.business.scenario == BsScenario.TP_PERFORMANCE: + ratio = 0.83 + elif infos.business.scenario == BsScenario.TP_PRODUCE: + ratio = 0.6 + + Project.log(f'ratio (thread count / parallel) is {ratio}.') + thread_count = infos.business.parallel * ratio + + return math.floor(max(min(max_count, thread_count), min_count)) class UpgradeGUC(GUCTuneGroup): diff --git a/script/impl/perf_config/tuners/setup.py b/script/impl/perf_config/tuners/setup.py index d7c4965..0a35a20 100644 --- a/script/impl/perf_config/tuners/setup.py +++ b/script/impl/perf_config/tuners/setup.py @@ -31,10 +31,11 @@ class SetupTuner(TunerGroup): super(SetupTuner, self).__init__() def calculate(self): - self._calculate_isolated_xlog() - - def _calculate_isolated_xlog(self): infos = Project.getGlobalPerfProbe() + self._calculate_isolated_xlog(infos) + self._calculate_data_split_tablespace(infos) + + def _calculate_isolated_xlog(self, infos): if infos.business.isolated_xlog is None: return @@ -48,3 +49,8 @@ class SetupTuner(TunerGroup): self.add(ShellTunePoint(cmd, anti, desc)) + def _calculate_data_split_tablespace(self, infos): + if len(infos.disk) > 2 and infos.business.data_size > 1024: + Project.report.suggest( + 'Detect that you have multiple disks, you can allocate data to different disks through tablespaces.') +