Skip to content

[LI-HOTFIX] Improving performance of the isReplicaOnline method#206

Merged
gitlw merged 2 commits into
linkedin:2.4-lifrom
gitlw:gitlw-improve_isReplicaOnline
Sep 9, 2021
Merged

[LI-HOTFIX] Improving performance of the isReplicaOnline method#206
gitlw merged 2 commits into
linkedin:2.4-lifrom
gitlw:gitlw-improve_isReplicaOnline

Conversation

@gitlw

@gitlw gitlw commented Sep 8, 2021

Copy link
Copy Markdown

TICKET = LIKAFKA-38536
LI_DESCRIPTION =
Profiling shows that the ControllerContext.isReplicaOnline method is taking a significant portion of the CPU during controller initialization.
https://harrier.tools.corp.linkedin.com/#/lnkd-services/profiler/event/41572?isAsyncProfiler=true&metri

The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

TICKET = LIKAFKA-38536
LI_DESCRIPTION =
The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.
Comment thread core/src/main/scala/kafka/controller/ControllerContext.scala Outdated
Comment thread core/src/main/scala/kafka/controller/ControllerContext.scala Outdated
def addUpdateMetadataRequestForBrokers(brokerIds: Seq[Int],
partitions: collection.Set[TopicPartition]): Unit = {

val controllerContextSnapshot = ControllerContextSnapshot(controllerContext)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caches the computed fields inside ControllerContextSnapshot so that they don't need to be repeatedly computed.

Comment on lines +435 to +437
val liveBrokerIds = controllerContext.liveBrokerIds
val liveOrShuttingDownBrokerIds = controllerContext.liveOrShuttingDownBrokerIds
val replicasOnOfflineDirs = controllerContext.replicasOnOfflineDirs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all these fields are computed? It's not clear because Scala is hiding method call vs field dereference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first 2 are method calls, and the last one replicasOnOfflineDirs is a field.
I'm captured all 3 here since they are needed for the isReplicaOnline call.

@gitlw
gitlw merged commit 7e7b9cb into linkedin:2.4-li Sep 9, 2021
@gitlw
gitlw deleted the gitlw-improve_isReplicaOnline branch January 28, 2022 05:27
wyuka added a commit that referenced this pull request Feb 4, 2022
#271)

TICKET = LIKAFKA-38536
LI_DESCRIPTION =

Original hotfix PR #206

The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.

Co-authored-by: Lucas Wang <luwang@linkedin.com>
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Feb 9, 2022
…edin#206) (linkedin#271)

TICKET = LIKAFKA-38536
LI_DESCRIPTION =

Original hotfix PR linkedin#206

The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.

Co-authored-by: Lucas Wang <luwang@linkedin.com>
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Mar 25, 2022
…edin#206) (linkedin#271)

TICKET = LIKAFKA-38536
LI_DESCRIPTION =

Original hotfix PR linkedin#206

The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.

Co-authored-by: Lucas Wang <luwang@linkedin.com>
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Jun 2, 2022
…in#206) (linkedin#271)

TICKET = LIKAFKA-38536
LI_DESCRIPTION =

Original hotfix PR linkedin#206

The ControllerContext.isReplicaOnline method is frequently called inside a loop,
and internally this method relies on several derived fields in the ControllerContext.
Repeatedly calculating the derived fields could be expensive, and yet these fields
do not change between iterations of the loop.

This PR creates a new class ControllerContextSnapshot that tries to cache
the derived fields in order to save the repeated computation and speed up the
controller.

EXIT_CRITERIA = When this change is proposed in upstream kafka and pulled internally.

Co-authored-by: Lucas Wang <luwang@linkedin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants