Databases 12 min read

Unlocking OceanBase Thread Limits: How min_worker_cnt and max_worker_cnt Are Calculated

This article explains why OceanBase enforces minimum values for min_worker_cnt and max_worker_cnt, shows the source‑code formulas used to compute them, demonstrates how to verify and adjust these parameters, and clarifies the impact of tenant memory and Meta‑tenant reservations on the final values.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Unlocking OceanBase Thread Limits: How min_worker_cnt and max_worker_cnt Are Calculated

1. Background

Reference to the article “Multiple‑scenario OceanBase concurrency parameter adjustment scheme” raises the question of why the values of unit_min_cpu and unit_max_cpu are both 8 for tenant mysql_ob (tenant_id 1008).

min_worker_cnt:34 // minimum worker threads
max_worker_cnt:150 // maximum worker threads

See “Tenant Resource Management” for details.

2. Related parameters

2.1 Tenant configuration

+-------------+-------------------+---------------+---------+---------+
| tenant_name | unit_server       | unit_info     | min_cpu | max_cpu |
+-------------+-------------------+---------------+---------+---------+
| mysql_ob    | 10.186.64.10:2882 | 1 unit: 8C/6G | 8       | 8       |
| mysql_ob    | 10.186.64.61:2882 | 1 unit: 8C/6G | 8       | 8       |
| mysql_ob    | 10.186.64.62:2882 | 1 unit: 8C/6G | 8       | 8       |
+-------------+-------------------+---------------+---------+---------+

2.2 Relevant variables

workers_per_cpu_quota = 10
px_workers_per_cpu_quota = 10
cpu_quota_concurrency = 4
parallel_servers_target = 80

3. Source‑code analysis

We decompile the OceanBase Enterprise edition and compare it with the open‑source Community edition.

3.1 min_worker_cnt calculation

In the Community code:

int64_t ObTenant::min_worker_cnt() const
{
    ObTenantConfigGuard tenant_config(TENANT_CONF(id_));
    return 2 + std::max(1L,
        static_cast<int64_t>(unit_min_cpu() *
            (tenant_config.is_valid() ? tenant_config->cpu_quota_concurrency : 4)));
}

cpu_quota_concurrency : uses the configured value, otherwise defaults to 4.

min_worker_cnt = 2 + max(1, unit_min_cpu * cpu_quota_concurrency)

If unit_min_cpu * cpu_quota_concurrency > 1, the result is increased by 2; otherwise it equals 3.

Enterprise disassembly confirms the same logic.

... (assembly excerpt) ...
add $0x2 // add 2 to ensure redundancy

Applying the formula:

min_worker_cnt = 2 + max(1, 8 * 4) = 34

3.2 max_worker_cnt calculation

Community code:

int64_t ObTenant::max_worker_cnt() const
{
    return std::max(tenant_meta_.unit_.config_.memory_size() / 20 /
        (GCONF.stack_size + (3 << 20) + (512 << 10)), 150L);
}

Single‑thread memory cost = stack_size + 3MB + 512KB.

Result = max(memory_size / 20 / single_thread_cost, 150).

Enterprise disassembly shows the same comparison with the constant 0x95 (149) and a fallback to 150.

max_worker_cnt = max(memory_size / 20 / (stack_size + 3MB + 512KB), 150)
               = max(6*1024/20/4, 150) = 150

4. Parameter verification

4.1 min_worker_cnt

Setting cpu_quota_concurrency = 1 and unit_min_cpu = 1 yields the expected min_worker_cnt = 3, which is confirmed in observer.log:

min_worker_cnt:3

4.2 max_worker_cnt

When tenant memory is increased to 12 GB, the formula predicts max_worker_cnt = 153, but the log shows 150 because the actual memory size is 10.8 GB (Meta tenant reserves part of the quota).

memory_size:"10.8GB"

Meta‑tenant allocation rules are explained (10 % of total, minimum 512 MB, etc.).

After increasing the tenant memory to 14 GB, the observed max_worker_cnt becomes 161, matching the calculation:

max_worker_cnt:161

5. Conclusion

OceanBase V4 enforces lower bounds for min_worker_cnt (minimum 3) and max_worker_cnt (minimum 150) to guarantee sufficient resources for each tenant.

References

租户资源管理: https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000002013998

OceanBase 社区版源码: https://github.com/oceanbase/oceanbase/tree/develop

PerformanceParameter TuningOceanBaseDatabase ConfigurationWorker Threads
Aikesheng Open Source Community
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.