Updated on 2022-08-16 GMT+08:00

CPU

Priority scheduling can be based on CPU or I/O usage. The former puts new tasks in a resource pool based on the priority of associated Cgroups, and the latter suspends I/O requests in the database. This section mainly describes CPU priority scheduling.

Prerequisites

Resource load management has been enabled.

Context

After the number of concurrent tasks of a resource pool reaches the upper limit, new tasks enter the waiting queue of the resource pool.

Figure 1 shows the queue mechanism in resource load management.

Figure 1 Queue mechanism for load management

Users' tasks enter queues of CNs, queues of resource pools, and then resource pools for execution. The process is described as follows:

  1. Users' tasks are distributed by the Linux Virtual Server (LVS) to queues of CNs. Alternatively, tasks are directly distributed by users to the queues. On any CN, tasks are processed in the first-in-first-out (FIFO) principle, which means that a task entering the queue of a CN earlier than another task enters the following step before the other task.
  2. In the queue of any CN, a task is distributed to the queue of the resource pool corresponding to the task according to the following rules: based on the following rules:
    • The tasks in the queue of a CN are distributed in the FIFO principle.
    • A task is distributed to the queue of the resource pool bound with the user who initiates the task. If no resource pool is bound with the user, the task is distributed to the queue of the default resource pool default_pool.
  3. The tasks in the queue of a resource pool are executed in the FIFO principle. If the idle resources in a resource pool meet the requirement of the first task (counted from bottom to top) in the queue of the resource pool, the task enters the resource pool for execution.

Procedure

  • Adjust resource pool priorities.

    If the resource proportion of a resource pool changes, change the priority of the resource pool accordingly. You can change the priority by modifying attributes in the resource pool.

    1
    ALTER RESOURCE POOL respool2 WITH(CONTROL_GROUP = "Rush");
    

    The preceding statement changes the attribute of the Cgroup associated with a resource pool to Rush.

  • Adjust the priority of the current user. You can change the priority of a user by changing the resource pool it binds to. For example:
    1
    ALTER USER user1 WITH RESOURCE POOL 'respool2';
    

    Where user1 is the user whose priority is to be changed, and respool2 is the resource pool it is to be bound to. You need the sysadmin permission to adjust priorities.

  • Adjust the priority of the current session.

    You can change the Cgroup bound with the current session to adjust the priorities of the tasks in the session. For example:

    1
    SET CGROUP_NAME="Rush";
    

    Query for the Cgroup associated with the current session.

    1
    SHOW CGROUP_NAME;
    
  • Manually changing the positions of tasks in queues.

    If the priority of a task must be increased or a task must be executed at an earlier time, an administrator can change the position of the task in the queue.

    1. Query for the PID of the task in the queue of a CN.
      1
      SELECT * FROM pg_session_wlmstat where status = 'pending';
      
    2. Move the task to the first position of the queue.
      1
      SELECT pg_wlm_jump_queue(threadid);
      
    3. Change the priority of the task to High during the task execution. You can query the pg_session_wlmstat view for the thread ID of the task.
      1
      SELECT gs_wlm_switch_cgroup(threadid, 'High');
      

    Only the administrator can adjust the priorities of tasks being executed.