From a4fd4b79fe2ab149fdd23b914a34d303f004d660 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 6 Jun 2024 16:15:34 +0800 Subject: [PATCH 1/2] fix:default create db vgroups set to half cpu count --- inc/toolsdef.h | 1 + src/benchInsert.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/inc/toolsdef.h b/inc/toolsdef.h index aaf918b8..f2a5104b 100644 --- a/inc/toolsdef.h +++ b/inc/toolsdef.h @@ -223,6 +223,7 @@ int32_t toolsCloseDir(TdDirPtr *ppDir); int64_t atomic_add_fetch_64(int64_t volatile* ptr, int64_t val); int32_t toolsGetNumberOfCores(); +int32_t toolsGetPhysicalMemory(); int64_t toolsGetTimestamp(int32_t precision); void toolsMsleep(int32_t mseconds); diff --git a/src/benchInsert.c b/src/benchInsert.c index 4a3d3be1..ced22ae0 100644 --- a/src/benchInsert.c +++ b/src/benchInsert.c @@ -493,6 +493,32 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) { } #endif // TD_VER_COMPATIBLE_3_0_0_0 +// export from taos osSysinfo.c +int32_t taosGetTotalMemory(int64_t *totalKB); + +int32_t toolsGetDefaultVGroups() { + int32_t cores = toolsGetNumberOfCores(); + if (cores < 3 ) { + return 1; + } + + int64_t MemKB = 0; + taosGetTotalMemory(&MemKB); + if (MemKB <= 2*1024*1024) { // 2G + return 1; + } else if (MemKB <= 4*1024*1024) { // 4G + return 2; + } else if (MemKB <= 8*1024*1024) { // 8G + return 3; + } else if (MemKB <= 16*1024*1024) { // 16G + return 4; + } else if (MemKB <= 32*1024*1024) { // 32G + return 5; + } else { + return cores / 2; + } +} + int geneDbCreateCmd(SDataBase *database, char *command, int remainVnodes) { int dataLen = 0; int n; @@ -505,7 +531,7 @@ int geneDbCreateCmd(SDataBase *database, char *command, int remainVnodes) { database->dbName, (-1 != g_arguments->inputted_vgroups)? g_arguments->inputted_vgroups: - min(remainVnodes, toolsGetNumberOfCores())); + min(remainVnodes, toolsGetDefaultVGroups())); } else { n = snprintf(command + dataLen, SHORT_1K_SQL_BUFF_LEN - dataLen, g_arguments->escape_character From 6f933515713bf5fd6e7276d5b0aa1db0b4a3ac94 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 6 Jun 2024 16:30:05 +0800 Subject: [PATCH 2/2] fix: add information cpu and memory --- src/benchInsert.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/benchInsert.c b/src/benchInsert.c index ced22ae0..106fedb7 100644 --- a/src/benchInsert.c +++ b/src/benchInsert.c @@ -504,6 +504,8 @@ int32_t toolsGetDefaultVGroups() { int64_t MemKB = 0; taosGetTotalMemory(&MemKB); + + infoPrint("check local machine CPU: %d Memory:%d MB \n", cores, (int32_t)(MemKB/1024)); if (MemKB <= 2*1024*1024) { // 2G return 1; } else if (MemKB <= 4*1024*1024) { // 4G