Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Kallen
committed
Apr 16, 2009
1 parent
cf1f569
commit 28de084
Showing
8 changed files
with
232 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,19 @@ | |||
#!/usr/bin/env ruby | #!/usr/bin/env ruby | ||
|
|
||
options = { | require 'optparse' | ||
:count => 10, | |||
:base_port => 1000 | |||
} | |||
OptionParser.new do |opts| | |||
opts.on('-n', "--number COUNT", Integer) { |count| options[:count] = count } | |||
opts.on('-p', "--port PORT", Integer) { |count| options[:port] = port } | |||
end.parse! | |||
|
|
||
options[:count].times do |count| | begin | ||
port = options[:base_port] + count | $options = { | ||
System.fork("./joke_server.rb -p#{port}") | :count => 10, | ||
:base_port => 10000 | |||
} | |||
OptionParser.new do |opts| | |||
opts.on('-n', "--number COUNT", Integer) { |count| $options[:count] = count } | |||
opts.on('-p', "--port PORT", Integer) { |count| $options[:port] = port } | |||
end.parse! | |||
end | |||
|
|||
$options[:count].times do |count| | |||
port = $options[:base_port] + count + 1 | |||
fork { exec("./joke_server.rb -p#{port}") } | |||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
require 'proxy/balancers/balancer' | |||
|
|||
class Random < Balancer | |||
def forward(data) | |||
servers.rand.call(data) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require 'proxy/balancers/balancer' | |||
|
|||
class RoundRobin < Balancer | |||
def forward(data) | |||
next_server.call(data) | |||
end | |||
|
|||
private | |||
def next_server | |||
Thread.exclusive do | |||
@current ||= 0 | |||
@current = (@current + 1) % servers.size | |||
servers[@current] | |||
end | |||
end | |||
end |