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

Troy/fix dataloader #223

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ scuffle-signal = { path = "crates/signal", version = "0.0.2" }
scuffle-http = { path = "crates/http", version = "0.0.4" }
scuffle-metrics = { path = "crates/metrics", version = "0.0.4" }
scuffle-pprof = { path = "crates/pprof", version = "0.0.2" }
scuffle-batching = { path = "crates/batching", version = "0.0.3" }
scuffle-batching = { path = "crates/batching", version = "0.0.4" }
scuffle-postcompile = { path = "crates/postcompile", version = "0.0.5" }
scuffle-ffmpeg = { path = "crates/ffmpeg", version = "0.0.2" }
scuffle-h3-webtransport = { path = "crates/h3-webtransport", version = "0.0.2" }
Expand Down
2 changes: 1 addition & 1 deletion crates/batching/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scuffle-batching"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
repository = "https://github.com/scufflecloud/scuffle"
authors = ["Scuffle <[email protected]>"]
Expand Down
23 changes: 22 additions & 1 deletion crates/batching/src/dataloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ where
let mut count = 0;

{
let mut new_batch = false;
let mut new_batch = true;
let mut batch = self.current_batch.lock().await;

for item in items {
Expand Down Expand Up @@ -555,4 +555,25 @@ mod tests {
assert!(start.elapsed() >= std::time::Duration::from_millis(5));
assert!(start.elapsed() < std::time::Duration::from_millis(20));
}

#[tokio::test]
async fn already_batch() {
let requests = Arc::new(AtomicUsize::new(0));

let fetcher = TestFetcher {
values: HashMap::from_iter(vec![("a", 1), ("b", 2), ("c", 3)]),
delay: std::time::Duration::from_millis(5),
requests: requests.clone(),
capacity: 2,
};

let loader = DataLoader::builder().batch_size(10).concurrency(1).build(fetcher);

let start = std::time::Instant::now();
let (a, b) = tokio::join!(loader.load("a"), loader.load("b"));
assert_eq!(a, Ok(Some(1)));
assert_eq!(b, Ok(Some(2)));
assert!(start.elapsed() < std::time::Duration::from_millis(15));
assert_eq!(requests.load(std::sync::atomic::Ordering::Relaxed), 1);
}
}
Loading