A resource unit, or unit, is a container or virtual machine of user resources on an OBServer node in OceanBase Database. It is a key concept in the multi-tenant distributed database architecture of OceanBase Database. The RootService module manages resource units and effectively utilizes system resources by allocating resource units among different OBServer nodes.
RootService performs the following operations on resource units:
Resource unit allocation: When a resource unit is created, RootService determines which OBServer node this unit is allocated to.
Resource unit balancing: When the system is running, RootService re-balances resource units through scheduling based on the specifications of the resource units.
Resource units are allocated and balanced to achieve the following goals:
Allocation and balanced scheduling of multiple types of resources such as CPU and memory.
Balanced allocation of resources among OBServer nodes in a zone.
Allocation and balancing of different types of resources
The resource unit allocation and balancing algorithm involves resource allocation and the balancing of CPU and memory resources. If different types of resources exist, issues may arise from resource allocation and balancing. The following example describes the allocation and balancing of a single type of resource: CPU.
Balance CPU resources
Background information
Assume that two OBServer nodes are deployed: OBS0 (with 10 CPU cores) and OBS1 (with 10 CPU cores). OBS0 contains six resource units, and each resource unit represents one CPU core. OBS1 contains four resource units, and each resource unit represents one CPU core.
Goal
Migrate resource units among the OBServer nodes to make their CPU utilization as close as possible.
Procedure
In this example, CPU utilization of OBS0 is
(6 / 10) × 100% = 60%, and CPU utilization of OBS1 is(4 / 10) × 100% = 40%. The difference between the CPU utilization of OBS0 and that of OBS1 is 20%. After you migrate a resource unit from OBS0 to OBS1, the CPU utilization of OBS0 is(5/10) × 100% = 50%, and that of OBS1 is also(5/10) × 100% = 50%. Resource usage of the two OBServer nodes is more balanced than that before the resource unit migration.
Calculate the usage of multiple types of resources
If you have different types of resources to be allocated and balanced in the system, it may be inaccurate to implement resource allocation and balancing based on only the usage of one type of resource. This approach does not provide satisfactory resource allocation and balancing results. OceanBase Database uses the following approach to implement allocation and balancing of different resources such as CPU and memory: A weight is assigned to each type of resource and is used to calculate the percentage of this type of resource in the total resources of the OBServer node. The more a specific type of resource is used, the greater the weight of this type of resource.
For example, if a cluster contains 50 CPU cores and resource units occupy 20 CPU cores, the total CPU utilization is 40%. If the cluster contains 1,000 GB of memory and resource units occupy 100 GB of memory, the total memory usage is 10%. The usage is calculated by assuming that no other resources in the cluster need to be balanced. After normalization, weights assigned to the CPU and memory resources are respectively 80% and 20%. The resource usage of each OBServer node is calculated based on the weights. Then, the difference in resource usage among OBServer nodes can be reduced through the migration of resource units.
Allocate resource units
When you create a resource unit, you must select an OBServer node as the host in the following steps: Calculate the resource usage of each OBServer node based on the preceding rule for calculating the resource usage of multiple types of resources. Then, select the OBServer node with the lowest resource usage as the host for the new resource unit.
Balance resource units
Resource unit balancing is the process of migrating resource units among OBServer nodes to minimize the difference in resource usage among OBServer nodes. You can calculate the resource usage of each OBServer node by using the preceding method that is used to calculate the resource usage of multiple types of resources. Based on the calculation results, you can migrate resource units until the difference in resource usage among OBServer nodes is smaller than that before the migration. This way, resource units are balanced.
Control resource unit balancing
OceanBase Database provides two parameters for you to manage load balancing for resource units:
enable_rebalanceThis parameter specifies whether to enable load balancing.
server_balance_cpu_mem_tolerance_percentThis parameter specifies the threshold that triggers unit load balancing. When the difference between the resource unit load of one or more OBServer nodes and the average resource load of all OBServer nodes in a cluster exceeds the value of
server_balance_cpu_mem_tolerance_percent, resource units are scheduled and balanced until the difference is less than the value ofserver_balance_cpu_mem_tolerance_percent.
Manually migrate a resource unit
In addition to automatic resource unit balancing, OceanBase Database supports manual resource unit migration. You can execute the following SQL statement as a database administrator to manually migrate a resource unit:
obclient> ALTER SYSTEM MIGRATE UNIT $unit_id DESTINATION '$server';
where
$unit_idspecifies the ID of the resource unit that you want to migrate, which can be found in theoceanbase.GV$OB_UNITSview.$serverspecifies the IP address of the OBServer node to which you want to migrate the resource unit, in theIP address:port numberformat, such as10.10.10.1:2882.
When a resource unit is under migration, you can execute the following SQL statement to cancel the migration:
obclient> ALTER SYSTEM CANCEL MIGRATE UNIT $unit_id;