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

feat: limit thread number to 1 when HDD is detected #269

Merged
merged 27 commits into from
Dec 1, 2024

Conversation

Integral-Tech
Copy link
Contributor

@Integral-Tech Integral-Tech commented Nov 24, 2024

On HDD, multi-threaded du won't provide any performance benefit over the single-threaded one. Therefore, when HDD is detected on one of the files, limit the thread number to 1.

Fixes #257

@Integral-Tech Integral-Tech force-pushed the detect-hdd branch 2 times, most recently from 8fa1c14 to 80857ed Compare November 24, 2024 10:10
On HDD, multi-threaded du won't provide any performance benefit over
the single-threaded one. Therefore, when HDD is detected on one of
the files, limit the thread number to 1.

This PR fixes issue #257.
Copy link
Owner

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I have some requests and questions.

src/app/sub.rs Outdated Show resolved Hide resolved
src/mount_point.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/app/sub.rs Outdated Show resolved Hide resolved
src/app/sub.rs Outdated Show resolved Hide resolved
@KSXGitHub KSXGitHub marked this pull request as draft November 25, 2024 11:01
Copy link
Owner

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to my request at #269 (comment), I also have more suggestions for improvement.

src/app/sub/mount_point.rs Outdated Show resolved Hide resolved
src/app/sub/mount_point.rs Outdated Show resolved Hide resolved
src/app/sub/mount_point.rs Outdated Show resolved Hide resolved
src/app/sub/hdd.rs Outdated Show resolved Hide resolved
src/app/sub/hdd.rs Outdated Show resolved Hide resolved
src/app/sub/hdd.rs Outdated Show resolved Hide resolved
Copy link
Owner

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this, I need to try rewriting the dependency injections in the tests from passing functions to using a trait, like so:

pub trait Api {
    type Disk: ?Sized;
    fn get_disk_kind(&self, disk: &Self::Disk) -> DiskKind;
    fn get_mount_point(&self, disk: &Self::Disk) -> &Path;
    fn canonicalize(&self, path: &Path) -> io::Result<PathBuf>;
}

pub struct RealApi; // would implement real APIs

#[cfg(test)]
pub struct TestApi { /* ... */ } // would implement mocked APIs

Whilst I do not request you to implement this for me, you're welcomed to try if you are feeling generous enough. If you do not do it, then I will do this when I have free time.

@Integral-Tech
Copy link
Contributor Author

Before merging this, I need to try rewriting the dependency injections in the tests from passing functions to using a trait, like so:

pub trait Api {
    type Disk: ?Sized;
    fn get_disk_kind(&self, disk: &Self::Disk) -> DiskKind;
    fn get_mount_point(&self, disk: &Self::Disk) -> &Path;
    fn canonicalize(&self, path: &Path) -> io::Result<PathBuf>;
}

pub struct RealApi; // would implement real APIs

#[cfg(test)]
pub struct TestApi { /* ... */ } // would implement mocked APIs

Whilst I do not request you to implement this for me, you're welcomed to try if you are feeling generous enough. If you do not do it, then I will do this when I have free time.

However, while any_path_is_in_hdd() needs all three closures, path_is_in_hdd() only needs two of them

@KSXGitHub
Copy link
Owner

However, while any_path_is_in_hdd() needs all three closures, path_is_in_hdd() only needs two of them

It's just an internal trait, not a user-facing public trait, so we don't need to make it modular. As for code simplicity, we are not passing any closures, we are passing a single instance of TestApi or RealApi.

I feel that the names I chose are somewhat horrible though. If you have better names, feel free to use them.

@KSXGitHub KSXGitHub marked this pull request as ready for review December 1, 2024 09:25
@KSXGitHub KSXGitHub merged commit 18f5f2a into KSXGitHub:master Dec 1, 2024
7 checks passed
@KSXGitHub
Copy link
Owner

v0.11.0 has been released.

@Integral-Tech Integral-Tech deleted the detect-hdd branch December 1, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HDD performance is poor
2 participants