Help Center/ TaurusDB/ Kernel/ Multi-tenancy/ Using Multi-Tenancy for Resource Management
Updated on 2026-08-04 GMT+08:00

Using Multi-Tenancy for Resource Management

Scenarios

This section describes how to manage database resources.

Test Environment

  • The ECS and the TaurusDB cluster are in the same region and AZ.
  • The TaurusDB cluster nodes are configured with 8 vCPUs and 32 GB of memory, with a total of two nodes (one primary node and one read replica).
  • The default parameter template is used and multi-tenancy is enabled.
  • The ECS is configured with 32 vCPUs. Its specifications must be higher than the cluster specifications to prevent ECS performance bottlenecks during stress testing, which could affect multi-tenant resource isolation.

Creating Resource Configurations

Log in to the DB instance using the privileged root account and create a resource configuration to restrict tenant resources.

create resource_config cfg_1 max_cpu 1;

Creating Tenants

Log in to the DB instance using a privileged account. Create tenant_1 and associate it with the specific resource configuration.

create tenant tenant_1 resource_config cfg_1;

Creating Users and Databases

After the tenant is created, create a user and database under tenant_1.

Create user user_1 under tenant_1 and grant user_1 all execution privileges within tenant_1. Here, user_1@tenant_1 can be treated as a privileged account within tenant_1.

  1. Create user_1@tenant_1 using a privileged account.
    CREATE user 'user_1@tenant_1' IDENTIFIED WITH mysql_native_password BY {password}; 
  2. Grant user_1@tenant_1 all execution privileges of tenant_1 using a privileged account.
    GRANT all privileges ON `%@tenant_1`.* to 'user_1@tenant_1'@'%' with grant option;
  3. Create a database using a privileged account.
    CREATE DATABASE `sbtest@tenant_1`;

Testing

After resource configurations, tenants, users, and databases are created, verify multi-tenant resource management in the following scenarios.

Scenario 1: Testing Tenant-level Resource Management

Run stress tests on the sbtest database using the user_1@tenant_1 account:

sysbench --db-driver=mysql --mysql-host=host --mysql-port=3306 --mysql-user=user_1@tenant_1 --mysql-password=password --mysql-db=sbtest --table_size=25000 --tables=250 --threads=64 --time=180 --percentile=95 --report-interval=1 oltp_read_only run

Run the following SQL statements to adjust cfg_1:

alter resource_config cfg_1 max_cpu 1 min_cpu 1;
-- Execute the next change after 5 minutes.
alter resource_config cfg_1 max_cpu 2 min_cpu 1;
-- Execute the next change after 5 minutes.
alter resource_config cfg_1 max_cpu 4 min_cpu 1;

Scenario 2: Testing User-level Resource Management

Connect to the DB instance as tenant_1, create resource consumer groups group1 and group2, and associate group1 with user_1. Create resource plan plan1 and configure resource plan directive plan_directive_for_user1. This directive associates plan1 with group1 and sets mgmt_p1 to 10 and utilization_limit to 40.

mysql --host=host -u user_1@tenant_1 -p password
CALL dbms_resource_manager.create_consumer_group('group1', 'comment');
CALL dbms_resource_manager.set_consumer_group_mapping('USER', 'user_1', 'group1');
CALL dbms_resource_manager.create_plan('plan1', 'comment');
CALL dbms_resource_manager.create_plan_directive('plan1', 'group1', 'plan_directive_for_user1', 20, 20);

Connect to the DB instance as tenant_1 and enable the resource plan.