Elastic scaling is a key capability for OceanBase to evolve from a small-scale experience environment to a larger business capacity. As the business grows or declines, and due to peak differences at different times, the database needs to provide elastic service capabilities. OceanBase Database supports elastic service capabilities through its tenant scaling feature: scaling up can increase computing power and storage capacity, which can be achieved either by enhancing the service capability of a single node or by adding service nodes; scaling down is the reverse operation of scaling up. All adjustments take effect online and are transparent to the business.
This topic covers the following experiences:
- Understand the scaling framework: Learn about the three scaling levels: tenant vertical scaling (adjusting resource specifications), tenant horizontal scaling (adjusting the unit number), and cluster scaling (adding nodes).
- Experience tenant vertical scaling: Increase the resource specification of a tenant online and observe how quickly the change takes effect.
- Compare business capacity before and after scaling: Run stress tests with the same parameters on the same tenant before and after scaling, and observe the changes in QPS and latency.
- Learn how to verify scaling: Confirm resource specifications, unit distribution, and task status through system views.
Note
This topic is based on OceanBase Database V5.0.1 (Community Edition). The related commands and feature descriptions in this topic apply to V5.0.1. This topic uses a single-node environment deployed with the All-in-One package in Deploy OceanBase as an example. A single-node cluster allows you to fully experience tenant vertical scaling (adjusting resource specifications) and its impact on business capacity; tenant horizontal scaling (adjusting the unit number) and cluster scaling (adding nodes) require a multi-node cluster, so this topic describes only their operation methods and expected behavior.
Prerequisites
Before you start this procedure, ensure that the following conditions are met:
Item |
Description |
|---|---|
| OceanBase Database | The deployment has been completed with the All-in-One package and started successfully (the deployment name is demo). For more information, see Deploy OceanBase. |
| Server resources | We recommend that you have at least four CPU cores and 16 GB of memory, and reserve sufficient resources for later scaling. |
| Access to the sys tenant | You can log in to the sys tenant of the cluster as the root user to perform management operations. The password for the root user of the sys tenant is randomly generated during deployment and is printed in the deployment output; you can also run obd cluster display demo to view it. |
| obclient | obclient is installed and can connect to OceanBase Database normally. It is installed automatically when you deploy with the All-in-One package. |
| ob-sysbench | You have installed ob-sysbench as described in Experience high-concurrency OLTP scenarios, which is required to verify the business capacity before and after scaling. |
| Multi-tenancy basics | This topic creates a tenant for the experience. For information about tenants and resource pools, see Experience multi-tenancy and resource isolation. |
Introduction to the scaling system
Tenant scaling, whether up or down, essentially increases or decreases the tenant's service capabilities, including computing power and storage capacity. OceanBase Database provides two methods for tenant scaling, which, together with node expansion at the cluster level, constitute a complete elastic scaling system:
Scaling level |
Implementation method |
Key statement |
Use cases |
|---|---|---|---|
| Tenant vertical scaling | Increase or decrease the unit config to improve the service capability of a single node. | ALTER RESOURCE UNIT |
The single node has spare resources, and you want to improve its computing power and memory. |
| Tenant horizontal scaling | Increase the unit number to add service nodes. | ALTER RESOURCE TENANT ... UNIT_NUM |
The specification of a single node has reached its upper limit, and adding nodes improves the overall service capability of the tenant. |
| Cluster scaling | Add an OBServer node to the cluster. | ALTER SYSTEM ADD SERVER |
The overall resources of the cluster are insufficient, and storage capacity and computing power need to be expanded. |
Tenant vertical scaling can be performed in two ways:
- Modify the resource configuration: Directly adjust the CPU or memory values of the unit config, which affects all resource units that use this specification.
- Switch the resource configuration: Point the resource pool to another unit config (
ALTER RESOURCE POOL pool1 UNIT='uc2';). This is useful when multiple tenants share the same unit config and you want to adjust only one of them.
Note
Resource specification adjustments take effect immediately online: OceanBase Database uses kernel-level virtualization technology to make tenant CPU and memory resources effective immediately after the configuration change, without requiring data migration or switching, and is imperceptible to the business. For more information, see Introduction to tenant scaling and Achieve tenant scaling by adjusting resource specifications.
Experience tenant vertical scaling
This section creates a small tenant scale_tenant (1C2G) and runs a round of point query stress tests as the baseline. It then scales the specification online to 2C4G and runs the same stress test again, so that you can compare the business capacity before and after scaling.
Procedure
Log in to the sys tenant of the cluster as the root user (the password is randomly generated during deployment; obtain it as described in the prerequisites above), and create the experience tenant:
obclient [oceanbase]> CREATE RESOURCE UNIT scale_unit MAX_CPU=1, MIN_CPU=1, MEMORY_SIZE='2G'; obclient [oceanbase]> CREATE RESOURCE POOL scale_pool UNIT='scale_unit', UNIT_NUM=1, ZONE_LIST=('zone1'); obclient [oceanbase]> CREATE TENANT IF NOT EXISTS scale_tenant CHARSET='utf8mb4', PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('scale_pool') SET ob_tcp_invited_nodes='%';The
CREATE TENANToperation is synchronous. The command returns after about 10 seconds, so be patient while it runs.Run the baseline stress test before scaling. Use the point query script to run a stress test against
scale_tenant, and note down the QPS and the 95th percentile latency from the results:obd test sysbench demo --tenant=scale_tenant --script-name=oltp_point_select.lua --table-size=100000 --threads=16 --rand-type=uniformPoint queries are a typical CPU-intensive workload. If CPU resources in the cluster are tight, the 1C CPU quota becomes the throughput bottleneck. If CPU resources are abundant, the tenant may actually use more CPU than its quota, and the QPS difference between the two rounds may not be significant (see Interpretation below for details).
Check the current resource specification to confirm the pre-scaling baseline:
obclient [oceanbase]> SELECT UNIT_CONFIG_ID, NAME, MAX_CPU, MIN_CPU, MEMORY_SIZE, LOG_DISK_SIZE FROM oceanbase.DBA_OB_UNIT_CONFIGS WHERE NAME='scale_unit';A sample return result is as follows (
UNIT_CONFIG_IDis assigned by the system and varies by environment):+----------------+------------+---------+---------+-------------+---------------+ | UNIT_CONFIG_ID | NAME | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | +----------------+------------+---------+---------+-------------+---------------+ | 1009 | scale_unit | 1 | 1 | 2147483648 | 6442450944 | +----------------+------------+---------+---------+-------------+---------------+ 1 row in setThe result shows that the
scale_unitresource unit provides 1C of CPU and 2G of memory, and that its log disk space is 6G (three times the memory size by default).Scale the tenant specification up to 2C4G online:
obclient [oceanbase]> ALTER RESOURCE UNIT scale_unit MAX_CPU=2, MIN_CPU=2, MEMORY_SIZE='4G'; Query OK, 0 rows affectedIf the statement returns within seconds, the scale-out is complete. The tenant's CPU and memory take effect immediately, without data migration or switchover, and the sessions used by stress testing or business operations are not affected. (In this example, this statement and the subsequent scale-down statement were both executed during the stress test, without any errors or interruptions.) The
ALTERstatement adjusts only the options that you explicitly specify, soLOG_DISK_SIZEremains unchanged. If you also need to adjust the log disk specification, specify it in the statement.Confirm that the resource specifications have changed:
obclient [oceanbase]> SELECT UNIT_CONFIG_ID, NAME, MAX_CPU, MIN_CPU, MEMORY_SIZE, LOG_DISK_SIZE FROM oceanbase.DBA_OB_UNIT_CONFIGS WHERE NAME='scale_unit';In the result,
MAX_CPUandMIN_CPUhave changed to2, andMEMORY_SIZEhas changed to4294967296(that is, 4G):+----------------+------------+---------+---------+-------------+---------------+ | UNIT_CONFIG_ID | NAME | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | +----------------+------------+---------+---------+-------------+---------------+ | 1009 | scale_unit | 2 | 2 | 4294967296 | 6442450944 | +----------------+------------+---------+---------+-------------+---------------+ 1 row in setYou can also view the actual effective values of resource units on a node through the
GV$OB_UNITSview:obclient [oceanbase]> SELECT TENANT_ID, SVR_IP, ZONE, MAX_CPU, MIN_CPU, MEMORY_SIZE/1024/1024/1024 AS MEMORY_SIZE_G FROM oceanbase.GV$OB_UNITS WHERE TENANT_ID=(SELECT TENANT_ID FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME='scale_tenant');+-----------+--------------+-------+---------+---------+----------------+ | TENANT_ID | SVR_IP | ZONE | MAX_CPU | MIN_CPU | MEMORY_SIZE_G | +-----------+--------------+-------+---------+---------+----------------+ | 1020 | 127.0.0.1 | zone1 | 2 | 2 | 3.000000000000 | +-----------+--------------+-------+---------+---------+----------------+ 1 row in set
Note
In the example, the TENANT_ID and SVR_IP should be based on the actual query results. The MEMORY_SIZE displayed in GV$OB_UNITS shows the actual available memory for the unit after deducting system reserves (about 3G for a 4G configuration), which is different from the configured value in DBA_OB_UNIT_CONFIGS and is normal. The specification refresh of resource units on a node is completed asynchronously and typically takes effect within 40 seconds.
Run the same parameter stress test again and compare with the baseline result:
obd test sysbench demo --tenant=scale_tenant --script-name=oltp_point_select.lua --table-size=100000 --threads=16 --rand-type=uniformCompare the results of the two rounds and focus on the following:
- Both rounds end normally without errors: This shows that the tenant can handle business traffic after scaling, and that the specification change is imperceptible to the business.
- The QPS difference may not be significant:
MAX_CPUis an upper limit rather than a guaranteed value. When the cluster has spare CPU resources, a tenant may actually use more CPU than its quota, so it is normal for the measured QPS to be similar before and after scaling up. The benefit of a higher specification mainly shows when cluster resources are tight and tenants compete for CPU. - The 95th percentile latency shows only slight fluctuations within the same order of magnitude: When CPU resources are abundant, the request queue time is already very short, and it remains in the sub-millisecond range before and after scaling up.
Interpretation
Observation |
Expected behavior |
Description |
|---|---|---|
| Resource specification | The new values (2 CPU cores and 4 GB of memory) are visible in the views immediately. | The specification change takes effect online and requires no migration. |
| QPS comparison between the two rounds | The difference may not be significant. | MAX_CPU is an upper limit rather than a guaranteed value. When CPU resources are abundant, a tenant may actually use more CPU than its quota, so similar QPS results are normal. The benefit of a higher specification mainly shows when resources are tight and tenants compete for CPU. |
| 95th percentile latency | Slight fluctuations within the same order of magnitude. | When CPU resources are abundant, the queue time is already very short, typically in the sub-millisecond range. |
| Business continuity | Business reads and writes remain normal during scaling. | Kernel-level virtualization makes the change transparent to the business. In the performance tests for this topic, the change caused no errors and no reconnections. |
Notice
- When increasing the resource specification, the total adjusted resources must satisfy:
Sum(min_cpu) <= CPU_CAPACITY,Sum(max_cpu) <= CPU_CAPACITY * resource_hard_limit,Sum(memory_size) <= MEM_CAPACITY, andSum(log_disk_size) <= LOG_DISK_CAPACITY. Otherwise, the system reports an error indicating scale-out failure. Here,resource_hard_limitdefaults to100, meaning overprovisioning is not allowed. If other tenants exist in the cluster and resources are insufficient, you can first reduce or delete unused tenants to free up resources. - The
obd test sysbenchcommand regenerates and loads test data each time it runs. Use identical parameters for both rounds, and focus on comparing QPS and latency during the steady-state phase of the stress test. - The example specifications in this document are relatively small. The test results are primarily used to verify the scaling mechanism and its impact on business capacity, and do not represent the production-level performance of OceanBase Database. For the official performance test report, see OceanBase Sysbench Performance Test Report, which covers test results for OceanBase Database V4.2.1.
Experience tenant scale-down
Downsizing is the reverse of upsizing: it reduces the resource specification back to its original value to release resources:
obclient [oceanbase]> ALTER RESOURCE UNIT scale_unit MAX_CPU=1, MIN_CPU=1, MEMORY_SIZE='2G';
The statement also returns within seconds. In this example, the specification was scaled down from 2C4G to 1C2G during the stress test. The change completed instantly, with no errors and no reconnections during the whole stress test, and the business was not affected.
When you reduce the specification, MEMORY_SIZE is subject to one limitation: on every physical server that hosts a unit of the tenant, the configured MEMORY_SIZE must be greater than or equal to the tenant's current actual memory usage (MEM_USED) on that server. If the new MEMORY_SIZE is less than MEM_USED, the adjustment fails, and you must trigger a minor compaction to release memory before you try again. Therefore, we recommend that you trigger a minor compaction manually before you scale down a tenant.
Note
For operations related to manually triggering a minor compaction, see Manually trigger a minor compaction. For detailed limitations on reducing resource specifications, see Scale tenants by adjusting their resource specifications.
Experience tenant horizontal scaling
When the resource specification of a single node reaches its upper limit, you can increase the total service capacity of a tenant by adding service nodes and increasing the unit number. The total service capacity of a tenant is roughly equal to the specification of a single unit multiplied by the unit number.
Starting from V4.0.0, OceanBase Database requires that the number of units in each zone of a tenant be the same. To manage the units in each zone in a unified way, the system introduces the unit group mechanism: units with the same ID (UNIT_GROUP_ID) in different zones belong to the same unit group. Increasing or decreasing the unit number essentially means creating or deleting units.
Note
Because at most one unit under the same resource pool can be placed on a single physical server, the unit number of a single-zone cluster on a single node can only be 1, and you cannot experience the operations described in this section. The following method applies to multi-node clusters (for example, a three-node cluster with one OBServer node in each zone).
Procedure (multi-node cluster)
The following example shows how to adjust the unit number of tenant mysql001 from 1 to 2:
Check the current unit number of the tenant:
obclient [oceanbase]> SELECT TENANT_ID, TENANT_NAME, UNIT_NUM FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME='mysql001';In the returned result, if the value of
UNIT_NUMis1, it means the tenant has1unit.Adjust the unit number to 2:
obclient [oceanbase]> ALTER RESOURCE TENANT mysql001 UNIT_NUM = 2;After the statement is executed, the system adds a new unit to each zone. This new unit forms a new unit group with the original unit, and data is redistributed to the new units through load balancing.
Check the execution status of the task:
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_TENANT_JOBS WHERE JOB_TYPE='ALTER_RESOURCE_TENANT_UNIT_NUM' AND TENANT_ID=1006;When the
JOB_STATUSof the corresponding record in the returned result isSUCCESS, the adjustment is successful. You can locate this change record based on the fieldsSTART_TIME(the time when the task was initiated),SQL_TEXT(the SQL statement corresponding to the task), andEXTRA_INFO(the number of units before and after the change). In the example, the values ofTENANT_IDandUNIT_GROUP_IDshould be based on the query results in your actual environment.Check the unit distribution of the tenant to confirm that the number of units in each zone has become 2:
obclient [oceanbase]> SELECT UNIT_ID, ZONE, SVR_IP, UNIT_GROUP_ID, STATUS FROM oceanbase.DBA_OB_UNITS WHERE TENANT_ID=1006;
To decrease the unit number, use the ALTER RESOURCE TENANT statement as well. The system randomly selects a unit group, redistributes its data to the other unit groups, and then deletes it. You can also specify the unit group to delete with DELETE UNIT_GROUP:
-- Randomly delete one unit group and adjust the unit number to 1.
obclient [oceanbase]> ALTER RESOURCE TENANT mysql001 UNIT_NUM = 1;
-- Specify to delete the unit group with UNIT_GROUP_ID 1006.
obclient [oceanbase]> ALTER RESOURCE TENANT mysql001 UNIT_NUM = 1 DELETE UNIT_GROUP =(1006);
Note
- Data balancing during scaling is jointly controlled by tenant-level parameters
enable_rebalanceandenable_transfer. Their default values are bothtrue. After setting, they take effect immediately without restarting the OBServer node. When both values aretrue, the system automatically adjusts partition distribution during scaling to achieve load balancing. - After the unit number is changed, the service capacity of a tenant scales linearly with the number of units. Meanwhile, log streams are distributed across more nodes, reducing the load on individual nodes.
Cluster expansion
When the overall storage space or computing capability of a cluster is insufficient, you can add an OBServer node to the cluster. For example, to add a node in zone1, execute the following command in the sys tenant:
obclient [oceanbase]> ALTER SYSTEM ADD SERVER 'server_ip:port_num' ZONE 'zone1';
Here, server_ip is the IP address of the node to be added, and port_num is the RPC port of the node (default is 2882). After the new node is added, Root Service gradually balances the existing data to it, which horizontally scales storage space and computing power. The whole process is transparent to business operations.
For clusters managed by OBD, you can also use the obd cluster scale_out command to scale out: create a configuration file that contains only the information of the new node and run this command. OBD then deploys and registers the new node automatically.
Note
- For detailed steps on manually adding nodes to a cluster, see Add a node.
- For operations on expanding clusters managed by OBD using the
obd cluster scale_outcommand, see Expansion and component changes.
Summary of scaling verification methods
Regardless of the scaling method used, you can verify the change results through the following system views:
Verification target |
View or method |
Description |
|---|---|---|
| Whether the resource specification has changed | oceanbase.DBA_OB_UNIT_CONFIGS |
View the values of the unit config, such as MAX_CPU, MIN_CPU, MEMORY_SIZE, and LOG_DISK_SIZE. |
| Unit distribution and actual usage | oceanbase.GV$OB_UNITS |
View the node and specification of each tenant's resource units, as well as actual usage such as LOG_DISK_IN_USE and DATA_DISK_IN_USE. |
| Node resource capacity and allocated capacity | oceanbase.GV$OB_SERVERS |
Compare CPU_CAPACITY/CPU_ASSIGNED, MEM_CAPACITY/MEM_ASSIGNED, and LOG_DISK_CAPACITY/LOG_DISK_ASSIGNED to confirm the node resource allocation after scaling. |
| Tenant unit number | oceanbase.DBA_OB_TENANTS |
View the UNIT_NUM field of the tenant. |
| Status of the unit number change task | oceanbase.DBA_OB_TENANT_JOBS |
View the task whose JOB_TYPE is ALTER_RESOURCE_TENANT_UNIT_NUM; a JOB_STATUS of SUCCESS means that the task was executed successfully. |
| Whether the business capacity has improved | obd test sysbench |
Run stress tests with the same parameters before and after scaling, and compare QPS and latency. |
Next steps
After you complete the experiences in this topic, you can explore the following:
- Experience parallel import and high compression: Use the parallel import capability to complete large-scale data ingestion, and compare storage usage before and after compression. For more information, see Experience parallel import and high compression.
- Experience data protection and recovery: Experience data recovery capabilities for misoperations through flashback queries. For more information, see Experience data protection and recovery.
- Deepen understanding of multi-tenancy and resource isolation: Understand the resource management and isolation mechanisms under the multi-tenant architecture. For more information, see Experience multi-tenancy and resource isolation.
References
- For an introduction to the two approaches to tenant scaling, see Introduction to tenant scaling.
- For the complete procedure to achieve tenant scaling by adjusting resource specifications, see Achieve tenant scaling by adjusting resource specifications.
- For the complete procedure to achieve tenant scaling by adjusting the unit number, see Achieve tenant scaling by adjusting the unit number.
- For conceptual explanations of unit config and resource pool, see Tenant resource management.
- For the method to manually add nodes to a cluster, see Add a node.
- For the operation to expand a cluster using OBD (
obd cluster scale_out), see Expansion and component changes. - For detailed column descriptions of the views, see GV$OB_UNITS, GV$OB_SERVERS and DBA_OB_TENANT_JOBS.
- For detailed parameters of OBD test commands, see Test commands.