A resource unit is a container or VM that stores user resources on an OBServer in OceanBase Database. Resource units are important for the multi-tenant distributed database architecture of OceanBase Database. RootService manages resource units and schedules resource units across OBServers to utilize system resources in an efficient manner.
RootService performs the following operations on resource units:
Allocates resource units: When you create a resource unit, RootService determines the OBServer to which the resource unit is allocated.
Balances resource units: When the system is running, RootService re-balances resource units through scheduling based on 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 OBServers in a zone.
Multiple types of resources
The algorithm that is used to allocate and balance resource units considers the following types of resources: CPU and memory. If multiple types of resources exist at the same time, errors may occur in resource allocation and balancing. The following example describes the allocation and balancing of a single type of resource: CPU.
Balance CPUs
Background information
Assume that two OBServers are deployed: OBS0 (10 CPUs) and OBS1 (10 CPUs). OBS0 contains six resource units, and each resource unit represents one CPU. OBS1 contains four resource units, and each resource unit represents one CPU.
Goal
Migrate resource units between the OBServers 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 in CPU utilization between the two OBServers is 0.2. Therefore, one resource unit is migrated from OBS0 to OBS1. Then, CPU utilization of both OBS0 and OBS1 is(5 / 10) × 100% = 50%. Resource usage of the two OBServers is more balanced than that before the resource unit is migrated.
Calculate the usage of multiple types of resources
If you want to allocate and balance multiple types of resources in the system, the results may not be accurate or optimal if resources are allocated and balanced based on the usage of only one type of resource. To resolve the issue, OceanBase Database assigns a weight to each type of resource when OceanBase Database allocates and balances multiple types of resources such as CPU and memory. The weight of a resource indicates the percentage of the resource to all resources and is used to calculate the total resource usage of the OBServer. The more a specific type of resource is used, the greater the weight of the type of the resource.
For example, if a cluster contains 50 CPUs and resource units occupy 20 CPUs, 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, the weights of CPU and memory are 80% and 20%, respectively. The resource usage of each OBServer is calculated based on the weights. Then, the difference in resource usage between OBServers is reduced through the migration of resource units.
Allocate resource units
When you create a resource unit, you must select an OBServer as the host in the following steps: Calculate the resource usage of each OBServer based on the preceding rule for calculating the resource usage of multiple types of resources. Then, select the OBServer 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 OBServers to minimize the difference in resource usage among OBServers. You can calculate the resource usage of each OBServer 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 OBServers is smaller than that before the migration. In this way, resource units are balanced.
Control resource unit balancing
OceanBase Database controls resource unit balancing by using the following parameters:
enable_rebalanceThis parameter specifies whether to enable load balancing. If you disable load balancing, resource unit balancing and partition replica balancing are disabled. If you set the
enable_rebalanceparameter toFalse, resource unit balancing and partition replica balancing are disabled. If you set theenable_rebalanceparameter toTrue, load balancing is enabled. In this case, the value of theresource_soft_limitparameter determines whether resource unit balancing is enabled.For more information about partition replica balancing, see Automatic load balancing.
resource_soft_limitThis parameter specifies whether to enable resource unit balancing. If you set the
enable_rebalanceparameter toTrue, the value of this parameter determines whether resource unit balancing is enabled.If you set the
enable_rebalanceparameter toTrueand the value of theresource_soft_limitparameter is less than100, resource unit balancing is enabled. If you set theenable_rebalanceparameter toTrueand theresource_soft_limitparameter is greater than or equal to100, resource unit balancing is disabled.server_balance_cpu_mem_tolerance_percentThis parameter specifies the threshold for triggering resource unit balancing. If the difference between loads of resource units of specific OBServers and the average load exceeds the value of the
server_balance_cpu_mem_tolerance_percentparameter, resource units are scheduled and balanced until the difference is less than the value of theserver_balance_cpu_mem_tolerance_percentparameter.
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';
In the statement:
$
unit_id: the ID of the resource unit that you want to migrate, which can be found in theoceanbase.gv$unitview.$
server: the IP address of the OBServer to which you want to migrate the resource unit, in theIP address:port numberformat. Example:10.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;