ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Search Repo:
Add :spawn_thread? feature

Many applications will only want to spawn a thread for several slow 
running
requests such as POSTs which do image resizing. This commit allows Rack
applications a fine degree of tuning which requests will spawn threads.

The application need only implement the method :spawn_thread? that takes a

single Client#env object. The method should return quickly with true or
false.

For Rails applications, which have a dispatcher lock anyway, this method 
is
implemented simply as
  def spawn_thread?(env)
    false
  end
ryah (author)
Sun Apr 06 08:16:04 -0700 2008
commit  7bfe53508a2139735c8641bfe57cbc2317b7c3cd
tree    47b0cf1b1175c5135be2d83f56d590666264ab8d
parent  3a056d749c4e73b92c0ce3b7d325005a555d6a69
...
1
2
3
4
5
6
7
8
9
 
 
 
10
 
 
 
...
1
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
0
@@ -1,11 +1,12 @@
0
 .gdb_history
0
-src/ebb.o
0
-src/parser.o
0
-src/parser.c
0
-src/ebb_ruby.o
0
-src/ebb_ext.bundle
0
 benchmark/runall.sh
0
 site/index.html
0
 src/Makefile
0
+src/ebb.o
0
+src/ebb_ext.bundle
0
+src/ebb_ruby.o
0
 src/mkmf.log
0
+src/parser.c
0
+src/parser.o
0
+test/parser_test
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
 
22
 
23
 
24
 
 
25
26
27
28
29
30
31
32
33
34
35
 
36
 
 
37
38
39
...
8
9
10
 
 
 
 
 
 
 
 
 
11
 
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
25
26
27
 
 
 
28
29
30
31
32
33
34
0
@@ -8,32 +8,27 @@
0
   autoload :Runner, LIBDIR + '/ebb/runner'
0
   
0
   def self.start_server(app, options={})
0
- port = (options[:port] || 4001).to_i
0
- if options.has_key?(:threaded_processing)
0
- threaded_processing = options[:threaded_processing] ? true : false
0
- else
0
- threaded_processing = true
0
- end
0
-
0
- Client::BASE_ENV['rack.multithread'] = threaded_processing
0
-
0
     if options.has_key?(:fileno)
0
- FFI::server_listen_on_fd(options[:fileno].to_i)
0
+ fd = options[:fileno].to_i
0
+ FFI::server_listen_on_fd(fd)
0
+ log.puts "Ebb is listening on file descriptor #{fd}"
0
     else
0
+ port = (options[:port] || 4001).to_i
0
       FFI::server_listen_on_port(port)
0
+ log.puts "Ebb is listening at http://0.0.0.0:#{port}/"
0
     end
0
+ log.puts "Ebb PID #{Process.pid}"
0
+
0
     @running = true
0
     trap('INT') { stop_server }
0
     
0
- log.puts "Ebb listening at http://0.0.0.0:#{port}/ (#{threaded_processing ? 'threaded' : 'sequential'} processing, PID #{Process.pid})"
0
-
0
     while @running
0
       FFI::server_process_connections()
0
       while client = FFI::waiting_clients.shift
0
- if threaded_processing
0
- Thread.new(client) { |c| process(app, c) }
0
- else
0
+ if app.respond_to?(:spawn_thread?) and !app.spawn_thread?(client.env)
0
           process(app, client)
0
+ else
0
+ Thread.new(client) { |c| process(app, c) }
0
         end
0
       end
0
     end
...
66
67
68
 
 
 
 
 
69
70
71
...
66
67
68
69
70
71
72
73
74
75
76
0
@@ -66,6 +66,11 @@
0
           serve_rails(env)
0
         end
0
       end
0
+
0
+ # Never spawn threads for a request
0
+ def spawn_thread?(env)
0
+ false
0
+ end
0
     
0
       protected
0
         

Comments

    No one has commented yet.