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

[ML] AIOps: Reduces rerenders when streaming analysis results #182793

Merged

Conversation

walterra
Copy link
Contributor

@walterra walterra commented May 7, 2024

Summary

Part of #181111.

Improves the @kbn/ml-response-stream package to trigger less rerendering.

  • Updates the types in streamFactory(). Instead of an function overload to handle the different stream types (plain string or NDJSON based), a conditional type is now used to handle both types within the same function.
  • The way the state gets updated with throttling in useFetchStream() was improved. Previously useReducer could cause a lot of rerenders, even with the useThrottle we had in place. We now use a ref instead that holds intermediate state without causing rerenders and update the "real" state periodically while the the stream is running. For the Kibana Sample Logs dataset this bring down rerenders from ~16 to ~7. The pgbench dataset comes down from ~20 to ~11.
  • Part of the previous approach to reduce rerenders was to use both useThrottle and a special way to accept arrays of actions within reducers. This is a bit non-standard compared to redux reducers. Allowing arrays of actions is now no longer necessary with the improved rerendering so its support was removed.
  • For the Security AI Assistant we now export StreamResponseWithHeaders to simplify the types a bit.

Checklist

@walterra walterra marked this pull request as ready for review May 7, 2024 13:10
@walterra walterra requested review from a team as code owners May 7, 2024 13:10
@walterra walterra added :ml release_note:skip Skip the PR/issue when compiling release notes Feature:ML/AIOps ML AIOps features: Change Point Detection, Log Pattern Analysis, Log Rate Analysis v8.15.0 labels May 7, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@walterra walterra added release_note:enhancement and removed release_note:skip Skip the PR/issue when compiling release notes labels May 7, 2024
@walterra walterra requested review from alvarezmelissa87 and qn895 May 7, 2024 13:12
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiops 492 489 -3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 422.6KB 421.9KB -750.0B
dataVisualizer 671.8KB 671.8KB -12.0B
total -762.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @walterra

@qn895
Copy link
Member

qn895 commented May 13, 2024

Code LGTM 🎉

if (effectState.isActive) {
updateData();
}
}, DATA_THROTTLE_MS);
Copy link
Member

Choose a reason for hiding this comment

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

Should the consumer of this useFetchStream hook also have the ability to pass in the duration they want to throttle? Not necessary for this PR but would be nice to have in a follow up.

Copy link
Contributor

@stephmilovic stephmilovic left a comment

Choose a reason for hiding this comment

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

Thanks for the improvement!

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

LGTM ⚡

@walterra walterra merged commit 7026199 into elastic:main May 14, 2024
33 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 14, 2024
@szabosteve szabosteve changed the title [ML] AIOps: Reduce rerenders when streaming analysis results. [ML] AIOps: Reduces rerenders when streaming analysis results Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ML/AIOps ML AIOps features: Change Point Detection, Log Pattern Analysis, Log Rate Analysis :ml release_note:enhancement v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants