Skip to content

Commit

Permalink
Perform parallel reading of content directory to speed up startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisstaite-menlo committed Jul 5, 2023
1 parent 42b9ce0 commit b354b25
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cas/store/filesystem_store.rs
Expand Up @@ -319,6 +319,10 @@ pub fn digest_from_filename(file_name: &str) -> Result<DigestInfo, Error> {
DigestInfo::try_new(hash, size)
}

/// The number of files to read the metadata for at the same time when running
/// add_files_to_cache.
const SIMULTANEOUS_METADATA_READS: usize = 200;

async fn add_files_to_cache<Fe: FileEntry>(
evicting_map: &EvictingMap<Arc<Fe>, SystemTime>,
anchor_time: &SystemTime,
Expand Down Expand Up @@ -359,7 +363,7 @@ async fn add_files_to_cache<Fe: FileEntry>(

let read_dir_stream = ReadDirStream::new(dir_handle);
read_dir_stream
.then(|dir_entry| async move {
.map(|dir_entry| async move {
let dir_entry = dir_entry.unwrap();
let file_name = dir_entry.file_name().into_string().unwrap();
let metadata = dir_entry
Expand All @@ -381,6 +385,7 @@ async fn add_files_to_cache<Fe: FileEntry>(
};
Result::<(String, SystemTime, u64), Error>::Ok((file_name, atime, metadata.len()))
})
.buffer_unordered(SIMULTANEOUS_METADATA_READS)
.try_collect()
.await?
};
Expand Down

0 comments on commit b354b25

Please sign in to comment.