Skip to content

Commit d15a0cd

Browse files
committed
env_config: add auto option for download_concurrency
This will allow the user to set `HOMEBREW_DOWNLOAD_CONCURRENCY` to `auto` to have Homebrew use the number of cores on the machine * 2.
1 parent d90a421 commit d15a0cd

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Library/Homebrew/env_config.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,16 @@ def devcmdrun?
634634
sig { returns(Integer) }
635635
def download_concurrency
636636
# TODO: document this variable when ready to publicly announce it.
637-
concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1).to_i
638-
concurrency = 1 if concurrency <= 1
639-
concurrency
637+
concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1)
638+
concurrency = if concurrency == "auto"
639+
require "os"
640+
require "hardware"
641+
Hardware::CPU.cores * 2
642+
else
643+
concurrency.to_i
644+
end
645+
646+
[concurrency, 1].max
640647
end
641648
end
642649
end

Library/Homebrew/env_config.rbi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module Homebrew
5+
module EnvConfig
6+
include Kernel
7+
end
8+
end

0 commit comments

Comments
 (0)