Repository navigation
feat(sort): per-phase --sort-threads / --merge-threads control for sort and runall #465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b7a3201
feat(sort): per-phase worker-thread control in RawExternalSorter
nh13 3c74508
feat(sort): cap streaming Phase-2 decompress concurrency via admissio…
nh13 7470adb
feat(sort-cli): --sort-threads / --merge-threads per-phase flags on S…
nh13 7d219fc
feat(runall): honor per-phase sort threads in sole-stage and streamin…
nh13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 60 additions & 1 deletion
61
crates/fgumi-pipeline-io/src/sort/spill_decompress/tests.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,60 @@ | ||
| // No unit tests for spill_decompress directly; integration tests live in sort/tests.rs. | ||
| use super::*; | ||
| use std::sync::Arc; | ||
| use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
|
||
| #[test] | ||
| fn admission_counter_caps_concurrency() { | ||
| let active = Arc::new(AtomicUsize::new(0)); | ||
| let max = Some(2usize); | ||
| // Acquire up to the cap; hold the permits so the count accumulates. | ||
| let p1 = try_acquire(&active, max); | ||
| assert!(p1.is_some()); | ||
| let p2 = try_acquire(&active, max); | ||
| assert!(p2.is_some()); | ||
| assert!(try_acquire(&active, max).is_none()); // at cap | ||
| drop(p1); // releasing one permit frees a slot | ||
| assert!(try_acquire(&active, max).is_some()); // freed one slot | ||
| drop(p2); | ||
| } | ||
|
|
||
| #[test] | ||
| fn admission_counter_unbounded_when_none() { | ||
| let active = Arc::new(AtomicUsize::new(0)); | ||
| for _ in 0..1000 { | ||
| assert!(try_acquire(&active, None).is_some()); | ||
| } | ||
| } | ||
|
|
||
| /// Under real thread contention, the shared counter never exceeds the cap and | ||
| /// every acquired permit is released via `DecompressPermit::drop` (the counter | ||
| /// returns to zero). Mirrors how `new_worker_copy` clones share one `active`. | ||
| #[test] | ||
| fn admission_counter_concurrent_never_exceeds_cap() { | ||
| use std::thread; | ||
|
|
||
| let active = Arc::new(AtomicUsize::new(0)); | ||
| let cap = 3usize; | ||
| let handles: Vec<_> = (0..16) | ||
| .map(|_| { | ||
| let active = Arc::clone(&active); | ||
| thread::spawn(move || { | ||
| for _ in 0..5000 { | ||
| // The returned permit IS the ownership token; its Drop at the | ||
| // end of the block exercises the decrement. | ||
| if let Some(_permit) = try_acquire(&active, Some(cap)) { | ||
| // Occupancy observed while holding a permit can never | ||
| // exceed the cap: `try_acquire` only increments past a | ||
| // CAS that checks `cur < cap`, and the count only drops | ||
| // otherwise. | ||
| let occupancy = active.load(Ordering::Acquire); | ||
| assert!(occupancy <= cap, "occupancy {occupancy} exceeded cap {cap}"); | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
| .collect(); | ||
| for h in handles { | ||
| h.join().expect("worker thread panicked"); | ||
| } | ||
| assert_eq!(active.load(Ordering::Acquire), 0, "every permit must be released on drop"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.