ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Added worker threads option.

Now with the command line option -w you can specify how many worker 
threads to use. This is a simple first pass at handling better 
concurrency. ebb_rails defaults to 1 worker.
Ryan Dahl (author)
2 months ago
commit  f3387b215126ee98644c5a6b8085a50b763141d0
tree    e4d50d72a7ecb7c6c985f02abf53b6873d06872d
parent  01f42b798c714044c56524421f31b4611c5134a9
...
35
36
37
38
 
39
40
41
...
35
36
37
 
38
39
40
41
0
@@ -35,7 +35,7 @@ class SimpleApp
0
       status = 200
0
     
0
     elsif commands.include?('wait')
0
- n = commands.last.to_i
0
+ n = commands.last.to_f
0
       raise "wait called with n <= 0" if n <= 0
0
       wait(n)
0
       body = "waited about #{n} seconds"
...
19
20
21
22
 
 
 
 
23
24
25
...
19
20
21
 
22
23
24
25
26
27
28
0
@@ -19,7 +19,10 @@ trials = {
0
     [i, "ab -t 3 -q -c 50 http://0.0.0.0:PORT/bytes/#{bytes}"]
0
   },
0
   'wait_fib' => [1,20,40,60,80,100].map { |c|
0
- [c, "ab -t 3 -q -c #{c} http://0.0.0.0:PORT/periodical_activity/fibonacci/20"]
0
+ [c, "ab -t 3 -q -c #{c} http://0.0.0.0:PORT/periodical_activity/fibonacci/10"]
0
+ },
0
+ 'wait' => [0.5,1,1.5,2,2.5,3,3.5].map { |t|
0
+ [t, "ab -t 6 -q -c 50 http://0.0.0.0:PORT/periodical_activity/wait/#{t}"]
0
   },
0
   'post_size' => [0.1,1,5,7,10,15,18,20,23,25,30,35,37,40,45,50].map { |l|
0
     size = (l * 1024).to_i
...
80
81
82
83
 
84
85
86
...
149
150
151
152
153
 
...
80
81
82
 
83
84
85
86
...
149
150
151
 
152
153
0
@@ -80,7 +80,7 @@ class ServerTest
0
   end
0
   
0
   def kill
0
- Process.kill('KILL', @pid)
0
+ Process.kill('KILL', @pid) if @pid
0
   end
0
   
0
   def running?
0
@@ -149,4 +149,4 @@ class ServerTest
0
       :ab_cmd => cmd
0
     }
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
9
10
11
 
12
13
14
...
18
19
20
21
22
23
24
 
 
 
 
 
 
 
 
 
 
25
 
26
 
 
27
28
29
...
9
10
11
12
13
14
15
...
19
20
21
 
 
 
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
0
@@ -9,6 +9,7 @@ module Ebb
0
   
0
   def self.start_server(app, options={})
0
     port = (options[:port] || 4001).to_i
0
+ nworkers = options[:workers] || 1
0
     # socket = options[:socket]
0
     # timeout = options[:timeout]
0
     
0
@@ -18,12 +19,21 @@ module Ebb
0
     
0
     trap('INT') { @running = false }
0
     @running = true
0
- while @running
0
- FFI::server_process_connections()
0
- if client = FFI::waiting_clients.shift
0
- process_client(app, client)
0
+
0
+ workers = ThreadGroup.new
0
+ nworkers.times do
0
+ thread = Thread.new do
0
+ while @running
0
+ FFI::server_process_connections()
0
+ if client = FFI::waiting_clients.shift
0
+ process_client(app, client)
0
+ end
0
+ end
0
       end
0
+ workers.add(thread)
0
     end
0
+ workers.list.each { |thread| thread.join }
0
+
0
     puts "Ebb unlistening"
0
     FFI::server_unlisten()
0
   end
...
22
23
24
25
 
 
26
27
28
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 
 
125
126
127
128
129
130
131
132
...
22
23
24
 
25
26
27
28
29
...
107
108
109
 
110
 
111
112
113
 
114
 
115
116
117
118
119
120
 
121
122
123
124
125
126
 
127
128
129
0
@@ -22,7 +22,8 @@ module Ebb
0
   class Runner
0
     DEFAULT_OPTIONS = {
0
       :port => 4001,
0
- :timeout => 60
0
+ :timeout => 60,
0
+ :workers => 1
0
     }
0
     
0
     # Kill the process which PID is stored in +pid_file+.
0
@@ -106,27 +107,23 @@ module Ebb
0
       options = DEFAULT_OPTIONS.dup
0
       option_parser = OptionParser.new do |parser|
0
         parser.banner = "Usage: #{@name} [options] start | stop"
0
-
0
         parser.separator ""
0
-
0
         if respond_to?(:add_extra_options)
0
           add_extra_options(parser, options)
0
         end
0
-
0
         parser.separator ""
0
-
0
         # opts.on("-s", "--socket SOCKET", "listen on socket") { |socket| options[:socket] = socket }
0
         parser.on("-p", "--port PORT", "(default: #{options[:port]})") { |options[:port]| }
0
         parser.on("-d", "--daemonize", "Daemonize") { options[:daemonize] = true }
0
         parser.on("-l", "--log-file FILE", "File to redirect output") { |options[:port]| }
0
         parser.on("-P", "--pid-file FILE", "File to store PID") { |options[:pid_file]| }
0
         parser.on("-t", "--timeout SECONDS", "(default: #{options[:timeout]})") { |options[:timeout]| }
0
-
0
+ parser.on("-w", "--workers WORKERS", "Number of worker threads (default: #{options[:workers]})") { |options[:workers]| }
0
+ parser.separator ""
0
         parser.on_tail("-h", "--help", "Show this message") do
0
           puts parser
0
           exit
0
         end
0
-
0
         parser.on_tail('-v', '--version', "Show version") do
0
           puts "Ebb #{Ebb::VERSION}"
0
           exit

Comments

    No one has commented yet.