-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
diagnostic: implement cache size check #3783
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
Conversation
With an effectively empty cache: Before this PR:
After this PR:
With a cache containing 10 copies of Before this PR:
After this PR:
The everything-after-the-first-run results are presumably twisted a bit by "(run it twice to test the cold/warm IO cache)?" but doesn't show a huge slow down. |
I think you need something like
Otherwise it doesn't work for me. |
|
Oh, it's working here:
Perhaps I didn't expand the cache hard enough during testing. |
Yeah sounds like your cache never went over the 2GB mark. |
|
Library/Homebrew/diagnostic.rb
Outdated
cache = Utils.popen_read("du -sm #{HOMEBREW_CACHE}").split.first | ||
return unless cache > "2000" | ||
<<~EOS | ||
Your HOMEBREW_CACHE is using more than 2GB of disk space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be worth printing the actual value, too, given you already computed it.
So it has issues once we pass the 10000 mark apparently. Will look into that. |
Can we use |
and/or |
Yeah, we can. In initial testing it was slightly slower than simply throwing out to
But it does work: diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index 70f3e3881..c9b37d6d5 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -838,10 +838,10 @@ module Homebrew
def check_for_large_cache
return unless HOMEBREW_CACHE.exist?
return if ENV["CI"] # CI can be expected to have a large cache.
- cache = Utils.popen_read("du -sm #{HOMEBREW_CACHE}").split.first
- return unless cache > "2000"
+ cache_size = HOMEBREW_CACHE.abv.split.last
+ return unless cache_size.to_i > 2
<<~EOS
- Your HOMEBREW_CACHE is using more than 2GB of disk space.
+ Your HOMEBREW_CACHE is using #{cache_size} of disk space.
You may wish to consider running `brew cleanup`.
EOS
end |
since 2 is ambiguous depending on the units in the human readable format |
Then use |
Apparently has to be |
Not sure if that's still valid/correct. Don't see a problem with long numbers personally but there we go 🙈. |
Specifically:
|
2_147_483_648 doesn't work? |
Yeah, that's fine. Didn't know how pedantic we were getting about the whole every three digits thing. The error message isn't wildly clear. |
or just 2**31 |
Wasn't sure if shortening it made it less readable at a glance/less friendly. |
Although I guess we could just do |
2**31 is the most readable IMO |
So I guess we might as well be consistent and use |
Alright, tweaked. |
So in terms of time, on APFS with 4.1GB cache first doctor run without this PR second third After this PR, fourth fifth sixth |
Before:
After:
So a bit of a performance hit from using Ruby rather than a pure |
Great work as usual @DomT4; thanks! |
Managed a mistake so follow up in #3791. Thanks for the merge, and apologies for my "oops" 😅. |
In light of #3798 I think we may want to revert this. It will be an endless source of confusion because |
I considered that before this PR. My initial thought was to advise the ‘-s’ flag or a shorter default prune time. I think we have to do something around cache size notification given the confusion it already causes, but as I wrote in my initial post I’m open to ideas on quite what. I think this is a decent solution that’ll have teething issues around working out a good size & working out what advice to give, FWIW. |
There’s a lot we can consider in terms of tweaking the messaging or placement here or tweaking the default prune time for non-CI that reduces the confusion. Mike has said before in an ideal world cleanup could be run automatically for most users IIRC, and I’d certainly agree with that, but it remains a very slow operation which limits what we can do. I think this is something that needed better UX, and will need better UX even if this isn’t quite a perfect solution. |
I think removing it completely is an overly blunt reaction, especially considering the prior problem will remain & will be something users keep being confused about, but ultimately you two are the maintainers here. |
I disagree with the idea that there's anything wrong with a larger cache. |
Sure, but you’re not giving users a choice in that because a significant chunk of them don’t know about the cache size & don’t know the size of it. If you’re running a 250GB or 500GB MacBook & your cache is taking up 30GB that’s a huge chunk. |
https://twitter.com/pidster/status/963005893272010753 https://twitter.com/inoueh/status/961863241054892032 https://twitter.com/alexcarolc/status/960824943465418752 https://twitter.com/hannahwarmbier/status/959814433840222209 These are not users actively loving having a huge cache. These are people not knowing about how to shift it or not remembering the command exists. It is an issue. It was an issue regularly when I used to primarily operate the Twitter account. It is something that has been discussed as an issue by maintainers repeatedly. |
The man page is there. If people don't read it, OK. Doctor should warn about actual problems not imagined problems. |
I think we should alert users to |
Do you have any broad implementation ideas on that you’d be happier with so I’m not working up potential avenues of resolution that run counter to something you already have in mind? ILZ: I don’t think “RTFM” is actually helpful advice to users. We can barely get them to read caveats. |
Yep: #568. |
brew style
with your changes locally?brew tests
with your changes locally?Haven't worked up a test yet because I suspect there's going to be some discussion on this & how to implement it, if at all.
It has been a repetitive theme that people don't know about
brew cleanup
and have no idea how much spaceHOMEBREW_CACHE
is occupying, which can be a significant chunk, especially on Macs with smaller storage capacities. Seriously, do any search on Twitter forbrew cleanup
as a starting data point.This attempts to shine some light on the situation for users, whilst carving out an exemption for CI where massive caches are expected & in some way desirable. I stuck it in
diagnostic
but it could have a place inbrew config
or evenbrew --cache
somewhere. Opinions on everything welcome.