Merge pull request #22623 from taosdata/feat/TD-25964-3.0
feat: get cpu cores from quota
This commit is contained in:
commit
ed9085281d
|
@ -39,7 +39,7 @@ int64_t taosGetOsUptime();
|
||||||
int32_t taosGetEmail(char *email, int32_t maxLen);
|
int32_t taosGetEmail(char *email, int32_t maxLen);
|
||||||
int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen);
|
int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen);
|
||||||
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores);
|
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores);
|
||||||
int32_t taosGetCpuCores(float *numOfCores);
|
int32_t taosGetCpuCores(float *numOfCores, bool physical);
|
||||||
void taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
void taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
||||||
int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma);
|
int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma);
|
||||||
int32_t taosGetTotalMemory(int64_t *totalKB);
|
int32_t taosGetTotalMemory(int64_t *totalKB);
|
||||||
|
|
|
@ -56,7 +56,7 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need
|
||||||
|
|
||||||
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
||||||
taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine);
|
taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine);
|
||||||
taosGetCpuCores(&pInfo->cpu_cores);
|
taosGetCpuCores(&pInfo->cpu_cores, false);
|
||||||
taosGetProcMemory(&pInfo->mem_engine);
|
taosGetProcMemory(&pInfo->mem_engine);
|
||||||
taosGetSysMemory(&pInfo->mem_system);
|
taosGetSysMemory(&pInfo->mem_system);
|
||||||
pInfo->mem_total = tsTotalMemoryKB;
|
pInfo->mem_total = tsTotalMemoryKB;
|
||||||
|
|
|
@ -121,7 +121,8 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
||||||
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
|
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
|
||||||
|
|
||||||
float numCpuCores = 4;
|
float numCpuCores = 4;
|
||||||
taosGetCpuCores(&numCpuCores);
|
taosGetCpuCores(&numCpuCores, false);
|
||||||
|
numCpuCores = TMAX(numCpuCores, 2);
|
||||||
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2);
|
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2);
|
||||||
|
|
||||||
char pathTaosdLdLib[512] = {0};
|
char pathTaosdLdLib[512] = {0};
|
||||||
|
|
|
@ -121,6 +121,8 @@ LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS exception);
|
||||||
static pid_t tsProcId;
|
static pid_t tsProcId;
|
||||||
static char tsSysNetFile[] = "/proc/net/dev";
|
static char tsSysNetFile[] = "/proc/net/dev";
|
||||||
static char tsSysCpuFile[] = "/proc/stat";
|
static char tsSysCpuFile[] = "/proc/stat";
|
||||||
|
static char tsCpuPeriodFile[] = "/sys/fs/cgroup/cpu/cpu.cfs_period_us";
|
||||||
|
static char tsCpuQuotaFile[] = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us";
|
||||||
static char tsProcCpuFile[25] = {0};
|
static char tsProcCpuFile[25] = {0};
|
||||||
static char tsProcMemFile[25] = {0};
|
static char tsProcMemFile[25] = {0};
|
||||||
static char tsProcIOFile[25] = {0};
|
static char tsProcIOFile[25] = {0};
|
||||||
|
@ -234,7 +236,7 @@ bool taosCheckSystemIsLittleEnd() {
|
||||||
|
|
||||||
void taosGetSystemInfo() {
|
void taosGetSystemInfo() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
taosGetCpuCores(&tsNumOfCores);
|
taosGetCpuCores(&tsNumOfCores, false);
|
||||||
taosGetTotalMemory(&tsTotalMemoryKB);
|
taosGetTotalMemory(&tsTotalMemoryKB);
|
||||||
taosGetCpuUsage(NULL, NULL);
|
taosGetCpuUsage(NULL, NULL);
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
@ -245,7 +247,7 @@ void taosGetSystemInfo() {
|
||||||
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
#else
|
#else
|
||||||
taosGetProcIOnfos();
|
taosGetProcIOnfos();
|
||||||
taosGetCpuCores(&tsNumOfCores);
|
taosGetCpuCores(&tsNumOfCores, false);
|
||||||
taosGetTotalMemory(&tsTotalMemoryKB);
|
taosGetTotalMemory(&tsTotalMemoryKB);
|
||||||
taosGetCpuUsage(NULL, NULL);
|
taosGetCpuUsage(NULL, NULL);
|
||||||
taosGetCpuInstructions(&tsSSE42Enable, &tsAVXEnable, &tsAVX2Enable, &tsFMAEnable);
|
taosGetCpuInstructions(&tsSSE42Enable, &tsAVXEnable, &tsAVX2Enable, &tsFMAEnable);
|
||||||
|
@ -493,7 +495,55 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosGetCpuCores(float *numOfCores) {
|
// Returns the container's CPU quota if successful, otherwise returns the physical CPU cores
|
||||||
|
static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
|
#ifdef WINDOWS
|
||||||
|
return -1;
|
||||||
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
if (!(pFile = taosOpenFile(tsCpuQuotaFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
||||||
|
goto _sys;
|
||||||
|
}
|
||||||
|
char qline[32] = {0};
|
||||||
|
if (taosGetsFile(pFile, sizeof(qline), qline) < 0) {
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
goto _sys;
|
||||||
|
}
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
float quota = taosStr2Float(qline, NULL);
|
||||||
|
if (quota < 0) {
|
||||||
|
goto _sys;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pFile = taosOpenFile(tsCpuPeriodFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
||||||
|
goto _sys;
|
||||||
|
}
|
||||||
|
char pline[32] = {0};
|
||||||
|
if (taosGetsFile(pFile, sizeof(pline), pline) < 0) {
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
goto _sys;
|
||||||
|
}
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
float period = taosStr2Float(pline, NULL);
|
||||||
|
float quotaCores = quota / period;
|
||||||
|
float sysCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if (quotaCores < sysCores && quotaCores > 0) {
|
||||||
|
*numOfCores = quotaCores;
|
||||||
|
} else {
|
||||||
|
*numOfCores = sysCores;
|
||||||
|
}
|
||||||
|
goto _end;
|
||||||
|
_sys:
|
||||||
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
_end:
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosGetCpuCores(float *numOfCores, bool physical) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SYSTEM_INFO info;
|
SYSTEM_INFO info;
|
||||||
GetSystemInfo(&info);
|
GetSystemInfo(&info);
|
||||||
|
@ -503,7 +553,11 @@ int32_t taosGetCpuCores(float *numOfCores) {
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
if (physical) {
|
||||||
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
} else {
|
||||||
|
taosCntrGetCpuCores(numOfCores);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue