Repository: puma/puma
File: lib/puma/configuration.rb (Ruby)

Code before:
      @conf        = nil
      @cli_options = nil
      @options     = @options.dup
    end

    def flatten
      dup.flatten!
    end

    def flatten!
      @options = @options.flatten
      self
    end

    def puma_default_options(env = ENV)
      defaults = DEFAULTS.dup
      puma_options_from_env(env).each { |k,v| defaults[k] = v if v }
      defaults
    end

    def puma_options_from_env(env = ENV)
      min = env['PUMA_MIN_THREADS'] || env['MIN_THREADS']
      max = env['PUMA_MAX_THREADS'] || env['MAX_THREADS']
      workers = env['WEB_CONCURRENCY']

      {
        min_threads: min && Integer(min),
        max_threads: max && Integer(max),
        workers: workers && Integer(workers),
        environment: env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'],
      }
    end

    def load
      config_files.each { |config_file| @file_dsl._load_from(config_file) }

      @options
    end

    def config_files
      files = @options.all_of(:config_files)

      return [] if files == ['-']
      return files if files.any?

      first_default_file = %W(config/puma/#{@options[:environment]}.rb config/puma.rb).find do |f|
        File.exist?(f)
      end

      [first_default_file]
    end

Review comment (suggestion):
Hi,

Thanks for this feature it is really handy :)

I was just wondering, is the optimal number the _available_ processors or the _physical_ processors?

I think I'm asking the same question as @MSP-Greg did in this https://github.com/puma/puma/pull/3439#issuecomment-2368500248 🤔 

I tried `WEB_CONCURRENCY=auto` on a 1x vcpu instance on AWS and noticed puma wanted to start up 2x processes.

If that is deliberate and, in your expert opinion, 2 processes per "hyper threaded" processor (or equivalent) is optimal then all good 😌 

If it isn't then maybe the above can be changed to `::Concurrent.physical_processor_count`?

I would be happy to PR that, but honestly I'm no expert on which would be optimal so thought I'd check first :) 

Here is some console output on the 1vcpu instance showing that `available_processor_count` returns `2.0` while `physical_processor_count` returns `1`.

``` 
> Concurrent.physical_processor_count
1
> ::Concurrent.available_processor_count
2.0
```

Code after:
      @conf        = nil
      @cli_options = nil
      @options     = @options.dup
    end

    def flatten
      dup.flatten!
    end

    def flatten!
      @options = @options.flatten
      self
    end

    def puma_default_options(env = ENV)
      defaults = DEFAULTS.dup
      puma_options_from_env(env).each { |k,v| defaults[k] = v if v }
      defaults
    end

    def puma_options_from_env(env = ENV)
      min = env['PUMA_MIN_THREADS'] || env['MIN_THREADS']
      max = env['PUMA_MAX_THREADS'] || env['MAX_THREADS']
      workers = if env['WEB_CONCURRENCY'] == 'auto'
        require_processor_counter
        ::Concurrent.available_processor_count
      else
        env['WEB_CONCURRENCY']
      end

      {
        min_threads: min && Integer(min),
        max_threads: max && Integer(max),
        workers: workers && Integer(workers),
        environment: env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'],
      }
    end

    def load
      config_files.each { |config_file| @file_dsl._load_from(config_file) }

      @options
    end

    def config_files
      files = @options.all_of(:config_files)

      return [] if files == ['-']
      return files if files.any?

      first_default_file = %W(config/puma/#{@options[:environment]}.rb config/puma.rb).find do |f|