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

Clean idle pooled schedulers periodically #1575

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

ryoqun
Copy link
Collaborator

@ryoqun ryoqun commented Jun 2, 2024

Problem

From #1211:

Specifically, there are following several termination conditions which it must handle respectively:

...
3. A unified scheduler can be idling in the scheduler pool for very long time. And it needs to be disposed of: #1574
...

Summary of Changes

This pr addresses (3).

@ryoqun ryoqun requested a review from apfitzge June 2, 2024 05:45
@ryoqun ryoqun force-pushed the idle-pooled-scheduler-cleaning branch from 9984a5f to b16e9fe Compare June 2, 2024 05:51
@ryoqun ryoqun changed the title Clean idle pooled scheudlers periodically Clean idle pooled schedulers periodically Jun 2, 2024
@ryoqun ryoqun force-pushed the idle-pooled-scheduler-cleaning branch 2 times, most recently from 4d47f20 to 1a7e780 Compare June 2, 2024 13:42
Comment on lines +1808 to 1814
// Block solScCleaner until we see trashed schedler...
assert_eq!(pool_raw.trashed_scheduler_inners.lock().unwrap().len(), 1);
sleepless_testing::at(TestCheckPoint::BeforeTrashedSchedulerCleaned);

// See the trashed scheduler gone only after solScCleaner did its job...
sleepless_testing::at(TestCheckPoint::AfterTrashedSchedulerCleaned);
assert_eq!(pool_raw.trashed_scheduler_inners.lock().unwrap().len(), 0);
Copy link
Collaborator Author

@ryoqun ryoqun Jun 2, 2024

Choose a reason for hiding this comment

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

it turns out this test is racy to begin with... it seems this test isn't racy unless i add new logic to solScCleaner. so, I'm piggybacking this into this pr.

@ryoqun ryoqun force-pushed the idle-pooled-scheduler-cleaning branch 2 times, most recently from 63f08ca to 05f5a25 Compare June 9, 2024 01:32
@@ -438,6 +438,7 @@ trees = "0.4.2"
tungstenite = "0.20.1"
uriparse = "0.6.4"
url = "2.5.0"
vec_extract_if_polyfill = "0.1.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

according to this page, we're the first consumer of the polyfill crate: https://crates.io/crates/vec_extract_if_polyfill/reverse_dependencies

however, i've confirmed that this crate is almost verbatim copy of what's gated behind the unstable feature flag in our present rust-nightly std source:

$ git diff -w --no-index ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/vec_extract_if_polyfill-0.1.0/src/lib.rs ~/.rustup/toolchains/nightly-2024-05-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/extract_if.rs
...
$ git diff -w --no-index ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/vec_extract_if_polyfill-0.1.0/src/lib.rs ~/.rustup/toolchains/nightly-2024-05-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs
...

Choose a reason for hiding this comment

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

I don't understand why we're adding the dependency instead of just using a nightly feature if we really need it? The docs even say this polyfill crate uses it:

This struct is created by Vec::extract_if. See its documentation for more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if we only supported building with nightly, it would work.

but, Vec::extract_if() isn't available for stable rust yet...

@ryoqun ryoqun force-pushed the idle-pooled-scheduler-cleaning branch from 05f5a25 to 645f8bc Compare June 9, 2024 01:44
@@ -438,6 +438,7 @@ trees = "0.4.2"
tungstenite = "0.20.1"
uriparse = "0.6.4"
url = "2.5.0"
vec_extract_if_polyfill = "0.1.0"

Choose a reason for hiding this comment

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

I don't understand why we're adding the dependency instead of just using a nightly feature if we really need it? The docs even say this polyfill crate uses it:

This struct is created by Vec::extract_if. See its documentation for more.

let Ok(mut scheduler_inners) = scheduler_pool.scheduler_inners.lock() else {
break;
};
// I want to use the fancy ::extract_if() no matter what....

Choose a reason for hiding this comment

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

why though? it seems like we can get something similar with retain and collecting a vec inside?

Copy link
Collaborator Author

@ryoqun ryoqun Jun 10, 2024

Choose a reason for hiding this comment

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

why though? it seems like we can get something similar with retain and collecting a vec inside?

retain only gives &mut to the predicate closure. So, we can't collect (i.e. take the ownership) in that way. After all, that's the why there's the still unstable ::extract_if().

And ::extract_if() is a perfect match and simplest & fastest way for this use case.

Copy link
Collaborator Author

@ryoqun ryoqun Jun 10, 2024

Choose a reason for hiding this comment

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

well, while waiting for lgtm, I managed to write a in-source commentary: 2b90fd1

Choose a reason for hiding this comment

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

yeah agree it's a good match, would just love if the feature were stable. Just concerned with adding dependency on an otherwise unused crate. repo has no readme either.

kind of curious how you found it.
Looking at the repo, it seems fine to me as is - but who knows with upgrades.

Copy link
Collaborator Author

@ryoqun ryoqun Jun 10, 2024

Choose a reason for hiding this comment

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

kind of curious how you found it.

well, crates.io's own search functionality didn't work... i just googled...: https://www.google.com/search?q=rust+extract_if lol

Looking at the repo, it seems fine to me as is - but who knows with upgrades.

as for upgrades, that's certainly a possibility. however, our dep is pinned to exact commit hash via Cargo.lock as usual. so, i think it's okay unless we're practicing blind dependabot merges. ;)

also as far as i screened author profile pages (https://github.com/chyyran and https://crates.io/users/chyyran). i think there's only legit activities.

Lastly, I'm planning to advertise this crate at the rust's tracking issue to increase the exposure of this crate across the ecosystem and to move this forward the stabilization.

@ryoqun ryoqun requested a review from apfitzge June 10, 2024 05:04
@ryoqun ryoqun merged commit a054e47 into anza-xyz:master Jun 10, 2024
53 checks passed
samkim-crypto pushed a commit to samkim-crypto/agave that referenced this pull request Jul 31, 2024
* Clean idle pooled schedulers periodically

* Fix race in failure_{with,without}_extra_tx

* Improve test

* Use extract_if polyfill

* Write justfication of extract_if with minor opt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants