Resource Management Preparation（1）
Tags: opengauss
Published: 2023-04-17 09:33:41

**Planning Resources**
Before configuring resource load management, plan tenant resources based on service models. After services run for a period of time, you can adjust the configurations based on resource usage.

Assume that two departments in a large enterprise use the same cluster. openGauss puts system resources used by the same department in a group to isolate resources for different departments. Table 1 describes the resource plan.

Table 1 Tenant resource plan

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49g7pqjyty7zycj9ze09.png)

**Enabling Resource Load Management**
**Background**
This section describes how to configure parameters for resource load management.

**Prerequisites**
**·** In openGauss, you can manage system resources only as a database administrator. Run the following statement to query user permissions:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiauip59ner6e0zursn3.png)

**·** Resource load management can be applied only to users with the login permission. Run the following statement to query user permissions:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/diih9daa706z4a27ur1n.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo9k44w01suunib6mz6p.png)

**Procedure**
You can perform the following steps only as a database administrator to enable load management based on the resource pool. The following uses user **omm** as an example.

1. Log in as the OS user **omm** to the primary node of openGauss.

2. Enable resource pool–based load management.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34w98ojo0914ogapl3y7.png)

3. Restart the database for the parameter settings to take effect.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v32353xushh5vbim0lwv.png)

**Setting a Cgroup**
**Background**
The core of openGauss 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 openGauss 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 under **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.

**Prerequisites**
You are familiar with “Server Tools > gs_cgroup” and “Server Tools > gs_ssh” in Tool Reference.

**Procedure**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfv8izx25rpspxbprlu4.png)

**Creating sub-Class and Workload Cgroups**

1. Log in as the OS user **omm** to the primary node of openGauss.

2. Create sub-Class Cgroups **class_a** and **class_b**, and allocate 40% and 20% of Class CPU resources to them, respectively.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qb42u4vtf0h770ctsky.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bvf102ewwmbhwzs6ueiu.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0h3hdn4oex2k09rm1s4.png)

**Adjusting resource quotas for Cgroups**

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr1mbhnfo2p2klno9pxy.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt9raalvkzmpjrsfxf5m.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omxt8jq96hrzksc1xx1j.png)

**Deleting a Cgroup**

1. Delete the Cgroup **class_a**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjltr1wmzlf4f83pojw6.png)

After the command is executed, the Cgroup **class_a** is deleted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1dlpysw21dztzrsrmvn.png)

**Viewing Cgroup Information**
1. View Cgroup information in configuration files.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pz30f7oi36igyc6eav4y.png)

Cgroup configuration

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npzh5v1ed4frq9a4vkip.png)

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

Table 1 Cgroup configuration

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dys6qh0pbo5jnv08jfaj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hmgdyg38bxtmzeepe8ai.png)

2. View the Cgroup tree in the OS.

Run the following command to query the structure of the Cgroup tree:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qsdtgcvw60s96xshzp1.png)

In the command output, **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).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9i26vi57od3gnqnogg4g.png)

3. Obtain the Cgroup configuration in a system view.

3.1 Perform the steps in Using gsql to Connect to a Database.
3.2 Obtain the configuration about all Cgroups in the system.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z5m0l9a6dm25p6vnkev.png)