Skip to content

Commit a3712f8

Browse files
committed
Limit concurrency in blockdir tree walk
1 parent cef44f5 commit a3712f8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/blockdir.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::sync::{Arc, RwLock, RwLockReadGuard};
2929
use bytes::Bytes;
3030
use lru::LruCache;
3131
use serde::{Deserialize, Serialize};
32+
use tokio::sync::Semaphore;
3233
use tokio::task::JoinSet;
3334
use tracing::{debug, error, warn};
3435
use tracing::{instrument, trace};
@@ -358,9 +359,14 @@ async fn subdirs(transport: &Transport) -> Result<Vec<String>> {
358359
pub(crate) async fn list_blocks(transport: &Transport) -> Result<HashSet<BlockHash>> {
359360
let subdirs = subdirs(transport).await?;
360361
let mut subdir_tasks = JoinSet::new();
362+
let job_limit = Arc::new(Semaphore::new(30));
361363
for subdir_name in subdirs {
362364
let transport = transport.clone();
363-
subdir_tasks.spawn(async move { transport.list_dir(&subdir_name).await });
365+
let job_limit = job_limit.clone();
366+
subdir_tasks.spawn(async move {
367+
let _permit = job_limit.acquire().await.unwrap();
368+
transport.list_dir(&subdir_name).await
369+
});
364370
}
365371
let mut blocks = HashSet::new();
366372
while let Some(result) = subdir_tasks.join_next().await {

0 commit comments

Comments
 (0)