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

Perf: Limit concurrency for parallel requests #26

Open
hopeyen opened this issue Dec 6, 2023 · 1 comment
Open

Perf: Limit concurrency for parallel requests #26

hopeyen opened this issue Dec 6, 2023 · 1 comment
Labels
meta:good-first-issue Good for newcomers p1 High priority size:small Small type:refactor Changes not visible to users

Comments

@hopeyen
Copy link
Collaborator

hopeyen commented Dec 6, 2023

A file may contain a large number of chunks.

To prevent overwhelming system resources, utilize tokio::sync::Semaphores to limit concurrency. A semaphore maintains a set of permits, and a task must acquire a permit from the semaphore before proceeding.

// Declare number of permits
let semaphore = Arc::new(Semaphore::new(max_concurrent_tasks));
// Before task starts
let permit = semaphore.clone().acquire_owned().await.expect("Failed to acquire semaphore permit");
// Release the permit when task finishes
drop(permit); 
@hopeyen hopeyen added type:refactor Changes not visible to users size:small Small p1 High priority labels Dec 6, 2023
@chriswessels
Copy link
Member

Noice!

@hopeyen hopeyen added the meta:good-first-issue Good for newcomers label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta:good-first-issue Good for newcomers p1 High priority size:small Small type:refactor Changes not visible to users
Projects
None yet
Development

No branches or pull requests

2 participants