Skip to content

CHK controller reconciles all ClickHouseKeeperInstallation resources serially with no configurable concurrency #2032

Closed

Description

@miguel-signoz

Description

The CHK controller currently uses controller-runtime's default MaxConcurrentReconciles=1, meaning all ClickHouseKeeperInstallation resources are reconciled serially, one at a time. There is no configuration knob to increase this value.

By contrast, the CHI controller uses a custom worker pool with a configurable reconcileCHIsThreadsNumber setting (default 10), allowing parallel reconciliation of ClickHouseInstallation resources.

This asymmetry becomes a significant bottleneck at scale.

Problem

When a spec change is applied to a large number of CHK resources (e.g., adding Prometheus metrics settings to the base spec), the single-threaded CHK controller must reconcile every resource sequentially. Each reconciliation includes:

  • A hardcoded time.Sleep() in reconcileCRAuxObjectsPreliminaryDomain (10s for same-size, 30s for upscale, 120s for downscale)
  • A force restart cycle when config changes are detected (scale to 0, wait, scale back up)

At ~30-40 seconds per CHK, a cluster with 1,000+ CHK resources takes 9-12 hours to complete the full reconciliation backlog. During this time, any newly created CHK resources are added to the back of a FIFO queue behind the re-reconciliation of existing resources, with no priority mechanism. This means new ClickHouseKeeperInstallation resources can wait hours before the operator even begins to reconcile them.

Observed metrics from a production environment

Metric Value
Total CHK resources 1,000+
CHK controller concurrency 1 (hardcoded)
CHI controller concurrency 100 (configurable via reconcileCHIsThreadsNumber)
Time per CHK reconciliation (force restart) ~30-40 seconds
Estimated full backlog processing time 9-12 hours

Proposed Solution

Add a reconcileCHKsThreadsNumber configuration option (analogous to reconcileCHIsThreadsNumber) that maps to controller-runtime's MaxConcurrentReconciles for the CHK controller.

Code change

In cmd/operator/app/thread_keeper.go, add .WithOptions() to the builder chain:

err = ctrlRuntime.
    NewControllerManagedBy(manager).
    For(
        &api.ClickHouseKeeperInstallation{},
        builder.WithPredicates(keeperPredicate()),
    ).
    Owns(&apps.StatefulSet{}).
    WithOptions(controller.Options{
        MaxConcurrentReconciles: chop.Config().Reconcile.Runtime.ReconcileCHKsThreadsNumber,
    }).
    Complete(
        &controller.Controller{...},
    )

And add ReconcileCHKsThreadsNumber to the OperatorConfigReconcileRuntime struct in pkg/apis/clickhouse.altinity.com/v1/type_configuration_chop.go, with a sensible default (e.g., 10).

Config YAML

reconcile:
  runtime:
    reconcileCHIsThreadsNumber: 10
    reconcileCHKsThreadsNumber: 10  # <-- new
    reconcileShardsThreadsNumber: 5
    reconcileShardsMaxConcurrencyPercent: 50

Environment

  • Operator version: 0.26.3 (also verified against 0.27.0, 0.27.1, and current master — none have this setting)
  • Kubernetes: GKE v1.34
  • CHK resources: 1,000+

We are happy to submit a PR for this change if the approach looks good.

Activity

  1. miguel-signoz commented on Jul 6, 2026

    @miguel-signoz
    ContributorAuthor

    Submitted a PR for this: #2033

  2. added a commit that references this issue on Jul 7, 2026
    09d6b17
  3. added a commit that references this issue on Jul 17, 2026
    9248d7e
  4. alex-zaitsev commented on Jul 20, 2026

    @alex-zaitsev
    Member

    0.27.2:

    reconcile:
      runtime:
        reconcileCHKsThreadsNumber: 1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions