Help Center > > Developer Guide> Resource Load Management> Resource Management Preparation> Setting a Cgroup

Setting a Cgroup

Updated at: Sep 17, 2021 GMT+08:00

Context

The core of GaussDB(DWS) resource load management is resource pools. The first step of configuring a resource pool is to configure Cgroups in the environment. For details about Cgroup principles, see the product manual corresponding to your OS. For details about GaussDB(DWS) Cgroups, see Viewing Cgroup Information.

The Class Cgroup is a top-layer Cgroup for database service running. DefaultClass is a sub-category of the Class Cgroup and is automatically created when a cluster is deployed. The Medium Cgroup of DefaultClass contains running jobs that are triggered by the system. Resource configurations of Medium cannot be modified, and the jobs running on it are not controlled by resource management. Therefore, you are advised to create Sub-Class and Workload Cgroups to control resource allocation.

Procedure

  • To control all the resources in GaussDB(DWS), you need to create, update, and delete Cgroups on each node. Use gs_ssh to run commands in the steps below.
  • The name of a Sub-Class or Workload Cgroup cannot contain colons (:). In addition, Cgroup names cannot be duplicate.

Creating Sub-Class and Workload Cgroups

  1. Log in to any host where the GaussDB(DWS) cluster is installed as the OS user omm.
  2. Create Sub-Class Cgroups class_a and class_b, and allocate 40% and 20% of Class CPU resources to them, respectively.

    gs_ssh -c "gs_cgroup -c -S class_a -s 40"
    gs_ssh -c "gs_cgroup -c -S class_b -s 20"

  3. Create Workload Cgroups workload_a1 and workload_a2 under class_a, and allocate 20% and 60% of class_a CPU resources to them, respectively.

    gs_ssh -c "gs_cgroup -c -S class_a -G workload_a1 -g 20 "
    gs_ssh -c "gs_cgroup -c -S class_a -G workload_a2 -g 60 "

  4. Create Workload Cgroups workload_b1 and workload_b2 under class_b, and allocate 50% and 40% of class_b CPU resources to them, respectively.

    gs_ssh -c "gs_cgroup -c -S class_b -G workload_b1 -g 50 "
    gs_ssh -c "gs_cgroup -c -S class_b -G workload_b2 -g 40 "

Adjusting resource quotas for Cgroups

  1. Change the CPU resource quota for class_a to 30%.

    gs_ssh -c "gs_cgroup -u -S class_a -s 30"

  2. Change the CPU resource quota for workload_a1 under class_a to 30% of class_a CPU resources.

    gs_ssh -c "gs_cgroup -u -S class_a -G workload_a1 -g 30"

    After adjustment, the quantity of CPU resources allocated to workload_a1 should not be greater than that allocated to class_a. The name of a Workload Cgroup cannot be a default name of the Timeshare Cgroup, such as Low, Medium, High, or Rush.

Deleting a Cgroup

  1. Delete the Cgroup class_a.

    gs_ssh -c "gs_cgroup -d  -S class_a"
    After the command is executed, the Cgroup class_a is deleted.

    User root or a user with the root permission can delete the default Cgroups that can be accessed by a common user username by specifying -d and -U username. A common user can delete existing Class Cgroups by specifying -d and -S classname.

Viewing Cgroup Information

  1. View cgroup information in configuration files.

    gs_cgroup -p 

    Cgroup configuration

    gs_cgroup -p
    
    Top Group information is listed:
    GID:   0 Type: Top    Percent(%): 1000( 50) Name: Root                  Cores: 0-47
    GID:   1 Type: Top    Percent(%):  833( 83) Name: Gaussdb:omm           Cores: 0-20
    GID:   2 Type: Top    Percent(%):  333( 40) Name: Backend               Cores: 0-20
    GID:   3 Type: Top    Percent(%):  499( 60) Name: Class                 Cores: 0-20
    
    Backend Group information is listed:
    GID:   4 Type: BAKWD  Name: DefaultBackend   TopGID:   2 Percent(%): 266(80) Cores: 0-20
    GID:   5 Type: BAKWD  Name: Vacuum           TopGID:   2 Percent(%):  66(20) Cores: 0-20
    
    Class Group information is listed:
    GID:  20 Type: CLASS  Name: DefaultClass     TopGID:   3 Percent(%): 166(20) MaxLevel: 1 RemPCT: 100 Cores: 0-20
    GID:  21 Type: CLASS  Name: class1           TopGID:   3 Percent(%): 332(40) MaxLevel: 2 RemPCT:  70 Cores: 0-20
    
    Workload Group information is listed:
    GID:  86 Type: DEFWD  Name: grp1:2           ClsGID:  21 Percent(%):  99(30) WDLevel:  2 Quota(%): 30 Cores: 0-5
    
    Timeshare Group information is listed:
    GID: 724 Type: TSWD   Name: Low              Rate: 1
    GID: 725 Type: TSWD   Name: Medium           Rate: 2
    GID: 726 Type: TSWD   Name: High             Rate: 4
    GID: 727 Type: TSWD   Name: Rush             Rate: 8
    
    Group Exception information is listed:
    GID:  20 Type: EXCEPTION Class: DefaultClass
    PENALTY: QualificationTime=1800 CPUSkewPercent=30
    
    GID:  21 Type: EXCEPTION Class: class1
    PENALTY: AllCpuTime=100 QualificationTime=2400 CPUSkewPercent=90
    
    GID:  86 Type: EXCEPTION Group: class1:grp1:2
    ABORT: BlockTime=1200 ElapsedTime=2400

    Table 1 lists the cgroup configuration shown in the above example.

    Table 1 Cgroup configuration

    GID

    Type

    Name

    Percentage (%)

    Remarks

    0

    Top cgroup

    Root

    The number 1000 indicates that the total system resources are divided into 1000 pieces.

    The number 50 in the parentheses indicates 50% of I/O resources.

    GaussDB(DWS) does not control I/O resources using cgroups. Therefore, the information of the following cgroups involves only CPU quotas.

    -

    1

    Gaussdb:omm

    Only one database runs in a cluster. The default quota of the Gaussdb:omm cgroup is 833. That is, the ratio of database programs to non-database programs is 5:1 (833:167).

    -

    2

    Backend

    The number 40 in the parentheses indicates that the Backend cgroup takes up 40% of the resources of the Gaussdb:dbuser cgroup. The number 60 in the parentheses indicates that the Class cgroup takes up 60% of the resources of the Gaussdb:dbuser cgroup.

    -

    3

    Class

    -

    4

    Backend cgroup

    DefaultBackend

    The numbers 80 and 20 in the parentheses indicate the percentages of Backend cgroup resources taken by the DefaultBackend and Vacuum groups, respectively.

    TopGID: Specifies the GID (2) of the Backend group in the Top cgroup.

    5

    Vacuum

    20

    Class cgroup

    DefaultClass

    The number 20 in the parentheses indicates that the DefaultClass cgroup takes up 20% of Class resources. The number 40 in the parentheses indicates that the class1 cgroup takes up 40% of the Class resources. There are only two Class cgroups currently. Therefore, the system resource quotas for the Class cgroups (499) are allocated in the ratio of 40:20 into 332 and 166.

    In the CPU quota mode, the DefaultClass cgroup takes up 20% resources by default, and other Class cgroups allocate the remaining 80% resources. The accumulated resource usage does not exceed 100%.

    • TopGID: Specifies the GID (3) of the Top cgroup to which the DefaultClass and class1 cgroups belong.
    • MaxLevel: Specifies the maximum number of levels for Workload cgroups in a Class cgroup. This parameter is set to 1 for DefaultClass because it has no Workload cgroups.
    • RemPCT: Specifies the percentage of remaining resources in a Class cgroup after its resources are allocated to Workload cgroups. For example, the percentage of remaining resources in the class1 cgroup is 70.

    21

    class1

    86

    Workload cgroup

    grp1:2

    (This name is composed of the name of a Workload cgroup and its level in the Class cgroup. This grp1:2 cgroup is the first Workload cgroup under the class1 cgroup, and its level is 2. Each Class cgroup contains a maximum of 10 levels of Workload cgroups.)

    In this example, this Workload cgroup takes up 30% of class1 resources (332 x 30% = 99).

    • ClsGID: Specifies the GID of the class1 cgroup to which this Workload cgroup belongs.
    • WDLevel: Specifies the level of this Workload cgroup in the corresponding Class cgroup.

    724

    Timeshare cgroup

    Low

    -

    Rate: Specifies the rate of resources allocated to a Timeshare cgroup. The Low cgroup has the minimum rate 1 and the Rush cgroup has the maximum rate 8. The resource rate for Rush:High:Medium:Low is 8:4:2:1 under a Timeshare cgroup.

    725

    Medium

    -

    726

    High

    -

    727

    Rush

    -

  2. View the cgroup tree in the OS.

    gs_cgroup -P displays a cgroup tree. In the tree, shares indicates the value of cpu.shares, which specifies the dynamic quota of CPU resources in the OS, and cpus indicates the value of cpuset.cpus, which specifies the dynamic quota of CPUSET resources in the OS (number of cores that a cgroup can use).

    gs_cgroup -P
    Mount Information:
    cpu:/dev/cgroup/cpu
    blkio:/dev/cgroup/blkio
    cpuset:/dev/cgroup/cpuset
    cpuacct:/dev/cgroup/cpuacct
    
    Group Tree Information:
    - Gaussdb:wangrui (shares: 5120, cpus: 0-20, weight: 1000)
            - Backend (shares: 4096, cpus: 0-20, weight: 400)
                    - Vacuum (shares: 2048, cpus: 0-20, weight: 200)
                    - DefaultBackend (shares: 8192, cpus: 0-20, weight: 800)
            - Class (shares: 6144, cpus: 0-20, weight: 600)
                    - class1 (shares: 4096, cpus: 0-20, weight: 400)
                            - RemainWD:1 (shares: 1000, cpus: 0-20, weight: 100)
                                    - RemainWD:2 (shares: 7000, cpus: 0-20, weight: 700)
                                            - Timeshare (shares: 1024, cpus: 0-20, weight: 500)
                                                    - Rush (shares: 8192, cpus: 0-20, weight: 800)
                                                    - High (shares: 4096, cpus: 0-20, weight: 400)
                                                    - Medium (shares: 2048, cpus: 0-20, weight: 200)
                                                    - Low (shares: 1024, cpus: 0-20, weight: 100)
                                    - grp1:2 (shares: 3000, cpus: 0-5, weight: 300)
                            - TopWD:1 (shares: 9000, cpus: 0-20, weight: 900)
                    - DefaultClass (shares: 2048, cpus: 0-20, weight: 200)
                            - RemainWD:1 (shares: 1000, cpus: 0-20, weight: 100)
                                    - Timeshare (shares: 1024, cpus: 0-20, weight: 500)
                                            - Rush (shares: 8192, cpus: 0-20, weight: 800)
                                            - High (shares: 4096, cpus: 0-20, weight: 400)
                                            - Medium (shares: 2048, cpus: 0-20, weight: 200)
                                            - Low (shares: 1024, cpus: 0-20, weight: 100)
                            - TopWD:1 (shares: 9000, cpus: 0-20, weight: 900)

  3. Obtain the Cgroup configuration in a system view.

    1. Obtain the configuration about all Cgroups in the system.
    1
    SELECT * FROM gs_all_control_group_info;
    

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel