为什么Greenplum 的CPU有大量是%ni的占用

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

在使用Greenplum的过程中,发现CPU监控有大量的%ni的占比。
ni是指低优先级的用户模式,通过setpriority可以设置进程的优先级。数字越大,优先级越低。
TOP中CPU统计的分类解释如下:

   2c. SUMMARY Area Fields
       The summary area fields describing CPU statistics are abbreviated.  They provide information about times spent in:
           us = user mode
           sy = system mode
           ni = low priority user mode (nice)
           id = idle task
           wa = I/O waiting
           hi = servicing IRQs
           si = servicing soft IRQs
           st = steal (time given to other DomU instances)

setpriority 用法如下:

NAME
       getpriority, setpriority - get/set program scheduling priority

SYNOPSIS
       #include <sys/time.h>
       #include <sys/resource.h>

       int getpriority(int which, int who);
       int setpriority(int which, int who, int prio);

查看greenplum的源码,在src/backend/tcop/postgres.c中发现了setpriority的踪迹。

/*
 * Change the priority of the current process to the specified level
 * (bigger nice_level values correspond to lower priority).
*/
static bool renice_current_process(int nice_level)
{
#ifdef WIN32
        elog(DEBUG2, "Renicing of processes on Windows currently not supported.");
        return false;
#else
        int prio_out = -1;
        elog(DEBUG2, "Current nice level of the process: %d",
                        getpriority(PRIO_PROCESS, 0));
        prio_out = setpriority(PRIO_PROCESS, 0, nice_level);
        if (prio_out == -1)
        {
                switch (errno)
                {
                case EACCES:
                        elog(DEBUG1, "Could not change priority of the query process, errno: %d (%m).", errno);
                        break;
                case ESRCH:
                        /* ignore this, the backend went away when we weren't looking */
                        break;
                default:
                        elog(DEBUG1, "Could not change priority of the query process, errno: %d (%m).", errno);
                }
                return false;
        }

        elog(DEBUG2, "Reniced process to level %d", getpriority(PRIO_PROCESS, 0));
        return true;
#endif
}

以上函数在exec_mpp_query时被调用:

/*
 * exec_mpp_query
 *
 * Called in a qExec process to read and execute a query plan sent by
 * cdbdisp_dispatchPlan().
 *
 * query_string -- optional query text (C string).
 * serializedQuerytree[len]  -- Query node or (NULL,0) if plan provided.
 * serializedPlantree[len] -- PlannedStmt node, or (NULL,0) if query provided.
 * serializedParms[len] -- optional parameters
 * serializedSliceInfo[len] -- optional SliceTable
 * localSlice -- slice table index
 *
 * Caller may supply either a Query (representing utility command) or
 * a PlannedStmt (representing a planned DML command), but not both.
 */
static void
exec_mpp_query(const char *query_string, 
                           const char * serializedQuerytree, int serializedQuerytreelen,
                           const char * serializedPlantree, int serializedPlantreelen,
                           const char * serializedParams, int serializedParamslen,
                           const char * serializedSliceInfo, int serializedSliceInfolen,
                           const char * seqServerHost, int seqServerPort,
                           int localSlice)
{
...
        /* Downgrade segworker process priority */
                if (gp_segworker_relative_priority != 0)
                {
                        renice_current_process(PostmasterPriority + gp_segworker_relative_priority);
                }

gp_segworker_relative_priority 是一个启动参数,默认是20:

        {
                {"gp_segworker_relative_priority", PGC_POSTMASTER, RESOURCES_MGM,
                        gettext_noop("Priority for the segworkers relative to the postmaster's priority."),
                        NULL,
                        GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
                },
                &gp_segworker_relative_priority,
                PRIO_MAX,
                0, PRIO_MAX, NULL, NULL
        },
...

src/include/cdb/cdbvars.h:#define PRIO_MAX 20

因此就能解释,为什么使用greenplum会发现大量的nice占比的CPU统计。

相关文章
|
安全 Linux 网络安全
查看 cpu、内存、磁盘相关指标
查看 cpu、内存、磁盘相关指标
cpu是啥
CPU是指中央处理器(Central Processing Unit),是计算机中负责读取指令,对指令译码并执行指令的核心部件。CPU主要包括两个部分,即控制器、运算器,其中还包括高速缓冲存储器及实现它们之间联系的数据、控制的总线。
213 0
cpu是啥
|
缓存
完了!CPU一味求快出事儿了!
今天我们来为大家讲讲计算机的底层技术,CPU的那些事,快跟我一起去看看它又给我们整了什么活吧。
333 0
完了!CPU一味求快出事儿了!
|
Linux
Linux下区分物理CPU、逻辑CPU和CPU核数
Linux下区分物理CPU、逻辑CPU和CPU核数㈠ 概念 ① 物理CPU 实际Server中插槽上的CPU个数 物理cpu数量,可以数不重复的 physical id 有几个 ② 逻辑CPU Linux用户对 /proc/cpuinfo 这个文件肯定不陌生. 它是用来存储cpu硬件信息的 信息内容分别列出了processor 0 – n 的规格。
3764 0
|
Linux Shell
一个限制进程 CPU 使用率的解决方案
一个限制进程 CPU 使用率的解决方案 一 背景 在最近的一个项目中,需要限制 CPU 使用率。通过查阅各种资料,发现已经有直接可以使用的软件可以使用,这个软件就是cpulimit,这个软件使用非常简单。
1425 0