[LI-HOTFIX] Improving performance of the isReplicaOnline method#206
Merged
Conversation
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.
lmr3796
suggested changes
Sep 9, 2021
smccauliff
reviewed
Sep 9, 2021
| def addUpdateMetadataRequestForBrokers(brokerIds: Seq[Int], | ||
| partitions: collection.Set[TopicPartition]): Unit = { | ||
|
|
||
| val controllerContextSnapshot = ControllerContextSnapshot(controllerContext) |
Author
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
So all these fields are computed? It's not clear because Scala is hiding method call vs field dereference.
Author
There was a problem hiding this comment.
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.
lmr3796
approved these changes
Sep 9, 2021
3 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)