Understanding CPU Allocation Logic in OceanBase 4.x and How to Modify the cpu_count Configuration
This article explains the background of tenant creation failures caused by insufficient CPU resources in OceanBase, details the calculation of usable CPU in version 4.x, shows how to query CPU usage with SQL, describes related configuration parameters, and provides step‑by‑step procedures for modifying cpu_count and testing over‑commit scenarios across different OceanBase versions.
Background
When creating a tenant in OceanBase, failures often occur due to insufficient memory or CPU resources. This article discusses the logic for calculating the usable CPU cores in OceanBase 4.x.
Test Versions
OceanBase_CE‑v4.2.1.8
Related Configuration
Before starting, understand several CPU‑related parameters:
resource_hard_limit : percentage of CPU over‑commit; the enable_rebalance switch does not affect over‑commit.
cpu_count : total number of logical CPUs on the host.
cpu_reserved (deprecated in V4): the number of CPUs reserved for the system; the remaining CPUs are available to the database.
Viewing CPU Situation
You can query the CPU usage of the two OBServer hosts with the following SQL statements.
2.2.77 version
select svr_ip, zone, cpu_total, cpu_assigned, cpu_assigned_percent,
cpu_capacity, cpu_max_assigned,
(cpu_capacity - cpu_assigned) cpu_remained,
(cpu_total - cpu_max_assigned) cpu_max_remained
from oceanbase.__all_virtual_server_stat;4.2.1.8 version
select svr_ip, zone, cpu_capacity_max, cpu_assigned,
cpu_assigned/cpu_capacity cpu_assigned_percent,
cpu_capacity, cpu_assigned_max,
(cpu_capacity - cpu_assigned) cpu_remained,
(cpu_capacity_max - cpu_assigned_max) cpu_max_remained
from oceanbase.GV$OB_SERVERS;Explanation of Query Fields
cpu_total : total CPU available to OceanBase (including over‑commit), equivalent to cpu_capacity * resource_hard_limit or (cpu_count - cpu_reserved) * resource_hard_limit .
cpu_capacity_max : equivalent to cpu_total .
cpu_assigned : sum of min_cpu of all allocated units.
cpu_max_assigned : sum of max_cpu of all allocated units.
cpu_assigned_percent : percentage of assigned CPU over the total CPU ( cpu_assigned / cpu_capacity ).
cpu_capacity : CPU available to OceanBase without over‑commit.
cpu_remained : remaining min_cpu that can still be allocated ( cpu_capacity - cpu_assigned ).
cpu_max_remained : remaining max_cpu that can be allocated ( cpu_total - cpu_max_assigned ).
Notes on Resource Unit Definition
When defining a resource unit , both min_cpu and max_cpu can be specified. The following principles must be satisfied:
The sum of min_cpu of all units on a host must be less than the cpu_capacity field in oceanbase.__all_virtual_server_stat .
The sum of max_cpu of all units on a host must be less than the cpu_total field in the same table.
When no over‑commit is allowed, the total max_cpu cannot exceed the total min_cpu .
When over‑commit is allowed, the total max_cpu cannot exceed min_cpu * resource_hard_limit .
Modifying the cpu_count Configuration
Steps to change cpu_count for both versions:
2.2.77 version
-- View current parameters
show parameters where name in ('resource_hard_limit','cpu_count','cpu_reserved') \G
-- Set cpu_count to 20 (requires observer restart)
alter system set cpu_count=20;
-- After restart, verify the new CPU limits
select svr_ip, zone, cpu_total, cpu_assigned, cpu_assigned_percent,
cpu_capacity, cpu_max_assigned,
(cpu_capacity - cpu_assigned) cpu_remained
from oceanbase.__all_virtual_server_stat;4.2.1.8 version
-- View current parameters
show parameters where name in ('resource_hard_limit','cpu_count') \G
-- Set cpu_count to 20 (no restart needed)
alter system set cpu_count=20;
-- Verify the new CPU limits
select svr_ip, zone, cpu_capacity_max, cpu_assigned,
cpu_assigned/cpu_capacity cpu_assigned_percent,
cpu_capacity, cpu_assigned_max,
(cpu_capacity - cpu_assigned) cpu_remained,
(cpu_capacity_max - cpu_assigned_max) cpu_max_remained
from oceanbase.GV$OB_SERVERS;Testing CPU Over‑Commit Scenarios
Configure the host to over‑commit CPU and observe the remaining min_cpu and max_cpu values.
2.2.77 version
-- Set resource pool memory limit
alter system set __min_full_resource_pool_memory=1073741824;
-- Show parameters
show parameters where name in ('resource_hard_limit','cpu_count','cpu_reserved') \G
-- Increase over‑commit limit and CPU count
alter system set resource_hard_limit=120;
alter system set cpu_count=40;
alter system set cpu_reserved=2;
-- After restart, query CPU limits
select svr_ip, zone, cpu_total, cpu_assigned, cpu_assigned_percent,
cpu_capacity, cpu_max_assigned,
(cpu_capacity - cpu_assigned) cpu_remained,
(cpu_total - cpu_max_assigned) cpu_max_remained
from oceanbase.__all_virtual_server_stat;Then create a resource unit with min_cpu=27.5 and max_cpu=32.6 , a resource pool, and a tenant, and attempt to alter the unit’s CPU limits beyond the allowed range, which results in errors. Clean‑up commands are provided.
4.2.1.8 version
-- Similar steps with the newer version
alter system set __min_full_resource_pool_memory=1073741824;
show parameters where name in ('resource_hard_limit','cpu_count') \G
alter system set resource_hard_limit=120;
alter system set cpu_count=40;
select svr_ip, zone, cpu_capacity_max, cpu_assigned,
cpu_assigned/cpu_capacity cpu_assigned_percent,
cpu_capacity, cpu_assigned_max,
(cpu_capacity - cpu_assigned) cpu_remained,
(cpu_capacity_max - cpu_assigned_max) cpu_max_remained
from oceanbase.GV$OB_SERVERS;Again, attempts to increase min_cpu or max_cpu beyond the calculated limits produce errors, and cleanup commands are shown.
Summary
Before OceanBase 4.x, cpu_count represented the total CPU cores of the host, while cpu_reserved indicated the portion reserved for the host itself; the remaining CPUs were available to tenants. Starting with OceanBase 4.x, cpu_count directly represents the total CPU cores available to tenants, and the cpu_reserved parameter has been removed.
The upper limit of the sum of min_cpu on a host is cpu_count - cpu_reserved for pre‑4.x versions and simply cpu_count for 4.x and later.
The upper limit of the sum of max_cpu equals min_cpu when no over‑commit is allowed, or min_cpu * resource_hard_limit when over‑commit is permitted.
The difference max_cpu - min_cpu represents the amount of CPU that can be over‑committed.
Setting cpu_count to a value larger than the physical CPU count does not raise an error; however, allocating all of it to tenants leads to CPU over‑commit, which may cause high CPU utilization and tenant interference.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.