Class: Adelnor::ClusteredServer

Inherits:
BaseServer show all
Defined in:
lib/adelnor/clustered_server.rb

Instance Method Summary collapse

Methods inherited from BaseServer

#handle, #rack_data, #read_request_message, run, #welcome_message

Constructor Details

#initialize(rack_app, port, options = {}) ⇒ ClusteredServer

Returns a new instance of ClusteredServer.



7
8
9
10
11
# File 'lib/adelnor/clustered_server.rb', line 7

def initialize(rack_app, port, options = {})
  super(rack_app, port, options)

  @workers = options[:workers]
end

Instance Method Details

#handle_workerObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/adelnor/clustered_server.rb', line 21

def handle_worker
  pid = Process.pid
  puts "[#{pid}] Worker started"

  loop do
    client, = @socket.accept

    handle(client)
    client.close
  end
end

#runObject



13
14
15
16
17
18
19
# File 'lib/adelnor/clustered_server.rb', line 13

def run
  @workers.times do
    fork { handle_worker }
  end

  Process.waitall
end