class Puma::Server

The HTTP Server itself. Serves out a single Rack app.

This class is used by the `Puma::Single` and `Puma::Cluster` classes to generate one or more `Puma::Server` instances capable of handling requests. Each Puma process will contain one `Puma::Server` instance.

The `Puma::Server` instance pulls requests from the socket, adds them to a `Puma::Reactor` where they get eventually passed to a `Puma::ThreadPool`.

Each `Puma::Server` will have one reactor and one thread pool.

Constants

ThreadLocalKey

Attributes

app[RW]
auto_trim_time[RW]

@todo the following may be deprecated in the future

binder[RW]
early_hints[RW]

@todo the following may be deprecated in the future

events[R]
first_data_timeout[RW]

@todo the following may be deprecated in the future

leak_stack_on_error[RW]

@todo the following may be deprecated in the future

max_threads[RW]
min_threads[RW]
persistent_timeout[RW]

@todo the following may be deprecated in the future

reaping_time[RW]

@todo the following may be deprecated in the future

requests_count[R]
thread[R]

Public Class Methods

current() click to toggle source

@!attribute [r] current

# File lib/puma/server.rb, line 117
def current
  Thread.current[ThreadLocalKey]
end
new(app, events=Events.stdio, options={}) click to toggle source

Create a server for the rack app app.

events is an object which will be called when certain error events occur to be handled. See Puma::Events for the list of current methods to implement.

Server#run returns a thread that you can join on to wait for the server to do its work.

@note Several instance variables exist so they are available for testing,

and have default values set via +fetch+.  Normally the values are set via
`::Puma::Configuration.puma_default_options`.
# File lib/puma/server.rb, line 73
def initialize(app, events=Events.stdio, options={})
  @app = app
  @events = events

  @check, @notify = nil
  @status = :stop

  @auto_trim_time = 30
  @reaping_time = 1

  @thread = nil
  @thread_pool = nil

  @options = options

  @early_hints         = options.fetch :early_hints, nil
  @first_data_timeout  = options.fetch :first_data_timeout, FIRST_DATA_TIMEOUT
  @min_threads         = options.fetch :min_threads, 0
  @max_threads         = options.fetch :max_threads , (Puma.mri? ? 5 : 16)
  @persistent_timeout  = options.fetch :persistent_timeout, PERSISTENT_TIMEOUT
  @queue_requests      = options.fetch :queue_requests, true
  @max_fast_inline     = options.fetch :max_fast_inline, MAX_FAST_INLINE
  @io_selector_backend = options.fetch :io_selector_backend, :auto

  temp = !!(@options[:environment] =~ /\A(development|test)\z/)
  @leak_stack_on_error = @options[:environment] ? temp : true

  @binder = Binder.new(events)

  ENV['RACK_ENV'] ||= "development"

  @mode = :http

  @precheck_closing = true

  @requests_count = 0
end

Public Instance Methods

inherit_binder(bind) click to toggle source
# File lib/puma/server.rb, line 111
def inherit_binder(bind)
  @binder = bind
end