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

Fix Router performance issue #4327

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

kkondaka
Copy link
Collaborator

Description

Fix Router performance issue.
PR #3959 added removeAll to Router code. This method is very expensive in cases with ArrayLists(). Replacing it with for loop that removes individual records.

Also, added a performance optimization to avoid populating recordsUnRouted if there is at least one sink to which all records are routed.

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • [ X] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [X ] Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
graytaylor0
graytaylor0 previously approved these changes Mar 25, 2024
@@ -24,11 +24,13 @@ public class Router {
private final RouteEventEvaluator routeEventEvaluator;
private final DataFlowComponentRouter dataFlowComponentRouter;
private final Consumer<Event> noRouteHandler;
private Set<Record> recordsUnRouted;
Copy link
Member

Choose a reason for hiding this comment

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

This is not thread-safe. Is there a particular reason you moved it to the field? I say we just keep this as a local variable.

Copy link
Member

Choose a reason for hiding this comment

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

This should help make it final:

final Set<Record> recordsUnRouted;
        if (!allRecordsRouted) {
            recordsUnRouted = new HashSet<>(allRecords);
        } else {
            recordsUnRouted = null;
        }

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Thanks!

@kkondaka kkondaka merged commit 51ee0df into opensearch-project:main Mar 25, 2024
47 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 25, 2024
* Fix Router performance issue

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>

* Addressed comments

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Co-authored-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
(cherry picked from commit 51ee0df)
dlvenable pushed a commit that referenced this pull request Mar 25, 2024
* Fix Router performance issue

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>

* Addressed comments

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
Co-authored-by: Krishna Kondaka <krishkdk@dev-dsk-krishkdk-2c-bd29c437.us-west-2.amazon.com>
(cherry picked from commit 51ee0df)

Co-authored-by: Krishna Kondaka <41027584+kkondaka@users.noreply.github.com>
@dlvenable dlvenable added this to the v2.8 milestone Mar 26, 2024
@kkondaka kkondaka deleted the router-perf-fix branch May 13, 2024 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants