// Module included in the following assemblies:
//
// assembly-cruise-control-concepts.adoc

[id='con-rebalance-{context}']
= Tuning options for rebalances

[role="_abstract"]
Configuration options allow you to fine-tune cluster rebalance performance. 
These settings control the movement of partition replicas and leadership, as well as the bandwidth allocated for rebalances.

== Selecting replica movement strategies

Cluster rebalance performance is also influenced by the _replica movement strategy_ that is applied to the batches of partition reassignment commands.
By default, Cruise Control uses the `BaseReplicaMovementStrategy`, which applies the reassignments in the order they were generated.
However, this strategy could lead to the delay of other partition reassignments if large partition reassignments are generated then ordered first. 

Cruise Control provides four alternative replica movement strategies that can be applied to optimization proposals:

* `PrioritizeSmallReplicaMovementStrategy`: Reassign smaller partitions first.
* `PrioritizeLargeReplicaMovementStrategy`: Reassign larger partitions first.
* `PostponeUrpReplicaMovementStrategy`: Prioritize partitions without out-of-sync replicas.
* `PrioritizeMinIsrWithOfflineReplicasStrategy`: Prioritize reassignments for partitions at or below their minimum in-sync replicas (MinISR) with offline replicas. +
Set `cruiseControl.config.concurrency.adjuster.min.isr.check.enabled` to `true` in the `Kafka` resource to enable this strategy.

These strategies can be configured as a sequence.
The first strategy attempts to compare two partition reassignments using its internal logic.
If the reassignments are equivalent, then it passes them to the next strategy in the sequence to decide the order, and so on.

== Intra-broker disk balancing

Intra-broker balancing shifts data between disks on the same broker, useful for deployments with JBOD storage and multiple disks. 
This type of balancing incurs less network overhead than inter-broker balancing.

NOTE: If you are using JBOD storage with a single disk, intra-broker disk balancing will result in a proposal with 0 partition movements since there are no disks to balance.

To enable intra-broker balancing, set `rebalanceDisk` to `true` in `KafkaRebalance.spec`. 
When this is enabled, do not specify a `goals` field, as Cruise Control will automatically configure intra-broker goals and disregard inter-broker goals.
Cruise Control does not perform inter-broker and intra-broker balancing at the same time.

== Rebalance tuning

You can set the following rebalance tuning options when configuring Cruise Control or individual rebalances:

* Set Cruise Control server configurations in `Kafka.spec.cruiseControl.config` in the `Kafka` resource.
* Set proposal-specific configurations in `KafkaRebalance.spec` in the `KafkaRebalance` resource.

.Rebalance configuration tuning properties
[cols="4m,4m,1,2",options="header"]
|===
| Cruise Control properties
| KafkaRebalance properties
| Default
| Description

| `num.concurrent.partition.movements.per.broker`
| `concurrentPartitionMovementsPerBroker`
| 5
| The maximum number of inter-broker partition movements in each partition reassignment batch

| `num.concurrent.intra.broker.partition.movements`
| `concurrentIntraBrokerPartitionMovements`
| 2
| The maximum number of intra-broker partition movements in each partition reassignment batch

| `num.concurrent.leader.movements`
| `concurrentLeaderMovements`
| 1000
| The maximum number of partition leadership changes in each partition reassignment batch

| `default.replication.throttle`
| `replicationThrottle`
| Null (no limit)
| The bandwidth (in bytes per second) to assign to partition reassignment


| `default.replica.movement.strategies`
| `replicaMovementStrategies`
| `BaseReplicaMovementStrategy`
| The list of strategies (in priority order) used to determine the order in which partition reassignment commands are executed for generated proposals.
  For the server setting, use a comma separated string with the fully qualified names of the strategy class (add `com.linkedin.kafka.cruisecontrol.executor.strategy.` to the start of each class name).
  For the `KafkaRebalance` resource setting use a YAML array of strategy class names.

d| -
| `rebalanceDisk`
| false
| Enables intra-broker disk balancing, which balances disk space utilization between disks on the same broker. Only applies to Kafka deployments that use JBOD storage with multiple disks.
|===

Changing the default settings affects the length of time that the rebalance takes to complete, as well as the load placed on the Kafka cluster during the rebalance.
Using lower values reduces the load but increases the amount of time taken, and vice versa.

[role="_additional-resources"]
.Additional resources

* link:{BookURLConfiguring}#type-CruiseControlSpec-reference[`CruiseControlSpec` schema reference^]
* link:{BookURLConfiguring}#type-KafkaRebalanceSpec-reference[`KafkaRebalanceSpec` schema reference^]
