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

ActionListener#notifyOnce should release delegate on completion #92452

Conversation

DaveCTurner
Copy link
Contributor

There's no need to keep hold of the delegate after completing it, and in some cases this might hold on to excessive heap. With this commit we drop the reference to the delegate when it's complete.

Closes #92451

There's no need to keep hold of the delegate after completing it, and in
some cases this might hold on to excessive heap. With this commit we
drop the reference to the delegate when it's complete.

Closes elastic#92451
@DaveCTurner DaveCTurner added >non-issue :Core/Infra/Core Core issues without another label v8.7.0 labels Dec 19, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Dec 19, 2022
Copy link
Member

@thecoop thecoop left a comment

Choose a reason for hiding this comment

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

Good find!

One thing we could have is a test that checks the delegate is unassigned after it's called, by using a weak reference. But that might be a bit too much for this. Up to you.

@DaveCTurner
Copy link
Contributor Author

Yeah that'd be nice, but I think it would mean we have to force a GC? I tried, but I didn't manage to get it to work anyway.

@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 19, 2022
@DaveCTurner
Copy link
Contributor Author

@elasticmachine please run elasticsearch-ci/part-3

@elasticsearchmachine elasticsearchmachine merged commit 661ea5f into elastic:main Dec 19, 2022
@DaveCTurner DaveCTurner deleted the 2022-12-19-notifyOnce-release-delegate branch December 19, 2022 16:41
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 21, 2022
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 22, 2022
Like elastic#92452 and elastic#92507 but for `Releasables#releaseOnce`: there's no
need to keep hold of the wrapped releasable after closing it, and in
some cases this might hold on to excessive heap. With this commit we
drop the reference to the delegate when it's complete.
elasticsearchmachine pushed a commit that referenced this pull request Dec 23, 2022
Like #92452 and #92507 but for `Releasables#releaseOnce`: there's no
need to keep hold of the wrapped releasable after closing it, and in
some cases this might hold on to excessive heap. With this commit we
drop the reference to the delegate when it's complete.
DaveCTurner added a commit that referenced this pull request Dec 23, 2022
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 24, 2022
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jan 15, 2023
We recently adjusted `RunOnce`, `Releasables#releaseOnce` and
`ActionListener#notifyOnce` so that once they have fired they drop the
now-unnecessary reference to the delegate. This commit introduces tests
to verify that this reference does genuinely become unreachable (i.e.
available for garbage collection) as expected.

It also fixes a bug in `ActionListener#notifyOnce` which caused us to
unexpectedly retain a reference to the delegate 🤦

Relates elastic#92452
Relates elastic#92507
Relates elastic#92537
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jan 16, 2023
We recently adjusted `RunOnce`, `Releasables#releaseOnce` and
`ActionListener#notifyOnce` so that once they have fired they drop the
now-unnecessary reference to the delegate. This commit introduces tests
to verify that this reference does genuinely become unreachable (i.e.
available for garbage collection) as expected.

It also fixes a bug in `ActionListener#notifyOnce` which caused us to
unexpectedly retain a reference to the delegate 🤦

Relates elastic#92452
Relates elastic#92507
Relates elastic#92537
@DaveCTurner
Copy link
Contributor Author

Yeah that'd be nice, but I think it would mean we have to force a GC? I tried, but I didn't manage to get it to work anyway.

I suspect this might be because this commit had a subtle bug 🤦 - see #92928

elasticsearchmachine pushed a commit that referenced this pull request Jan 16, 2023
We recently adjusted `RunOnce`, `Releasables#releaseOnce` and
`ActionListener#notifyOnce` so that once they have fired they drop the
now-unnecessary reference to the delegate. This commit introduces tests
to verify that this reference does genuinely become unreachable (i.e.
available for garbage collection) as expected.

It also fixes a bug in `ActionListener#notifyOnce` which caused us to
unexpectedly retain a reference to the delegate 🤦

Relates #92452 Relates #92507 Relates #92537
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jan 17, 2023
Recent improvements to the primitives for writing async code
(particularly elastic#92452 and elastic#92620) mean that we can enormously simplify
`TransportNodesAction`. In particular, we can avoid accumulating an
intermediate array of responses for later processing in favour of just
accumulating the successes and failures into their final separate lists.
We also no longer need to use a separate `NodesResponseTracker` to
discard responses on cancellation.
DaveCTurner added a commit that referenced this pull request Jan 19, 2023
Recent improvements to the primitives for writing async code
(particularly #92452 and #92620) mean that we can enormously simplify
`TransportNodesAction`. In particular, we can avoid accumulating an
intermediate array of responses for later processing in favour of just
accumulating the successes and failures into their final separate lists.
We also no longer need to use a separate `NodesResponseTracker` to
discard responses on cancellation.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Feb 2, 2023
Similarly to elastic#92987, recent improvements to the primitives for writing
async code (particularly elastic#92452 and elastic#92620) mean that we can enormously
simplify `TransportBroadcastByNodeAction`. In particular, we can avoid
accumulating an intermediate array of responses for later processing in
favour of just accumulating the successes and failures into their final
separate lists. We also no longer need to use a separate
`NodesResponseTracker` to discard responses on cancellation. Finally, we
can now discard shard-level responses more promptly on cancellation.
elasticsearchmachine pushed a commit that referenced this pull request Feb 7, 2023
Similarly to #92987, recent improvements to the primitives for writing
async code (particularly #92452 and #92620) mean that we can enormously
simplify `TransportBroadcastByNodeAction`. In particular, we can avoid
accumulating an intermediate array of responses for later processing in
favour of just accumulating the successes and failures into their final
separate lists. We also no longer need to use a separate
`NodesResponseTracker` to discard responses on cancellation. Finally, we
can now discard shard-level responses more promptly on cancellation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActionListener#notifyOnce can release its delegate listener once completed
3 participants