Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] Optimize ThresholdShedder with improved boundary checks and parameter reuse #24064

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

crossoverJie
Copy link
Member

@crossoverJie crossoverJie commented Mar 7, 2025

Motivation:

his PR aims to improve the code clarity in the ThresholdShedder class by reorganizing the flow of the tryLowerBoundaryShedding method. The primary improvement is the early detection of the hasBrokerBelowLowerBound condition before attempting to access broker data.

Modifications:

  • Reordered condition checks in tryLowerBoundaryShedding()
  • Reuses the already calculated value from the parent method

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 7, 2025
@lhotari
Copy link
Member

lhotari commented Mar 7, 2025

Early detection hasBrokerBelowLowerBound

This would be a better name for the PR. The "optimization" itself is more about code cleanup than an actual optimization that has an impact. The title should also be specific about the area where this change is made, mentioning the ThresholdShedder.

btw. For larger PRs, it's useful to use LLMs like DeepSeek to provide a draft of the PR title and description. Here's a guide of how to achieve that: https://gist.github.com/lhotari/81f533af4b9ad515e02d96e543c4408b . In this case, it wouldn't necessarily be useful, but I highly recommend using LLMs for fixing grammar and making PR titles more specific. Obviously they could make mistakes, but it usually gives a good suggestion. With DeepSeek, there's a challenge since very large PRs will hit the context size limits. With Claude AI Professional, I haven't had that problem.

This was Claude AI's suggestion for this PR using the instructions provided in https://gist.github.com/lhotari/81f533af4b9ad515e02d96e543c4408b . I didn't check the result or edit it in any way so it might not be correct. It just gives an example how powerful it is.

[improve][broker] Optimize ThresholdShedder by improving early detection of brokers below lower bound

Motivation

This PR aims to improve the code clarity in the ThresholdShedder class by reorganizing the flow of the tryLowerBoundaryShedding method. The primary improvement is the early detection of the hasBrokerBelowLowerBound condition before attempting to access broker data.

Modifications

  1. Early detection of hasBrokerBelowLowerBound: Moved the validation check before attempting to access the broker data, preventing unnecessary processing when no suitable broker is found
  2. Reuse of threshold parameter: Improved the code by passing the existing threshold parameter to the tryLowerBoundaryShedding method instead of recalculating it

@crossoverJie crossoverJie changed the title [improve][broker] Optimize method hasBrokerBelowLowerBound [improve][broker] Optimize ThresholdShedder with improved boundary checks and parameter reuse Mar 7, 2025
@crossoverJie
Copy link
Member Author

@lhotari Thanks for the recommendation, this is a great tool for writing PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs ready-to-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants