public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Merge branch 'master' into keepalive

Conflicts:

  CHANGELOG
macournoyer (author)
Sun Feb 10 08:52:32 -0800 2008
commit  5d8d6a703c0d3de3256aaf74537eb01435c65914
tree    4e8322a8f510d2c29ede4951832216164d018b79
parent  3780f3f12d871d5a76b801ae579f0af5b1c829a7 parent  3f23868d488b471947ac0d751a5d5b590e97568d
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@
0
 ext/thin_parser/*.so
0
 lib/*.bundle
0
 lib/*.so
0
-log/*.log
0
+loglog
0
 spec/rails_app/log
0
 doc/rdoc/*
0
 tmp/*
...
1
2
 
3
4
5
...
1
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 == 0.7.0 Bionic Pickle release
0
  * Persistent connection (keep-alive) & HTTP pipelining support
0
+ * Fix -s option not being included in generated config file, fixes #37.
0
  * Add Swiftiply support. Use w/ the --swiftiply (-y) option in the thin script,
0
    closes #28 [Alex MacCaw]
0
 
...
5
6
7
8
9
10
 
 
 
 
11
12
13
14
15
16
17
18
19
20
 
 
 
21
22
23
...
25
26
27
 
 
28
29
30
...
39
40
41
42
 
43
44
45
...
51
52
53
54
 
55
56
57
...
89
90
91
92
93
 
 
94
95
96
97
98
...
103
104
105
106
107
 
 
108
109
 
110
111
 
112
113
114
...
5
6
7
 
 
 
8
9
10
11
12
13
 
 
 
 
 
 
 
 
14
15
16
17
18
19
...
21
22
23
24
25
26
27
28
...
37
38
39
 
40
41
42
43
...
49
50
51
 
52
53
54
55
...
87
88
89
 
 
90
91
92
93
94
95
96
...
101
102
103
 
 
104
105
106
 
107
108
 
109
110
111
112
0
@@ -5,19 +5,15 @@
0
     # * Inject the port or socket number in the pid and log filenames.
0
     # Servers are started throught the +thin+ command-line script.
0
     class Cluster < Controller
0
- # Number of servers in the cluster.
0
- attr_accessor :size
0
-
0
+ # Cluster only options that should not be passed in the command sent
0
+ # to the indiviual servers.
0
+ CLUSTER_OPTIONS = [:servers, :only]
0
+
0
       # Create a new cluster of servers launched using +options+.
0
       def initialize(options)
0
- @options = options.merge(:daemonize => true)
0
- @size = @options.delete(:servers)
0
- @only = @options.delete(:only)
0
-
0
- if socket
0
- @options.delete(:address)
0
- @options.delete(:port)
0
- end
0
+ super
0
+ # Cluster can only contain daemonized servers
0
+ @options.merge!(:daemonize => true)
0
       end
0
     
0
       def first_port; @options[:port] end
0
@@ -25,6 +21,8 @@
0
       def socket; @options[:socket] end
0
       def pid_file; @options[:pid] end
0
       def log_file; @options[:log] end
0
+ def size; @options[:servers] end
0
+ def only; @options[:only] end
0
 
0
       def swiftiply?
0
         @options.has_key?(:swiftiply)
0
@@ -39,7 +37,7 @@
0
       def start_server(number)
0
         log "Starting server on #{server_id(number)} ... "
0
       
0
- run :start, @options, number
0
+ run :start, , number
0
       end
0
   
0
       # Stop the servers
0
@@ -51,7 +49,7 @@
0
       def stop_server(number)
0
         log "Stopping server on #{server_id(number)} ... "
0
       
0
- run :stop, @options, number
0
+ run :stop, , number
0
       end
0
     
0
       # Stop and start the servers.
0
@@ -89,8 +87,8 @@
0
       
0
       private
0
         # Send the command to the +thin+ script
0
- def run(cmd, options, number)
0
- cmd_options = options.dup
0
+ def run(cmd, number)
0
+ cmd_options = @options.reject { |option, value| CLUSTER_OPTIONS.include?(option) }
0
           cmd_options.merge!(:pid => pid_file_for(number), :log => log_file_for(number))
0
           if socket
0
             cmd_options.merge!(:socket => socket_for(number))
0
0
0
@@ -103,12 +101,12 @@
0
         end
0
       
0
         def with_each_server
0
- if @only
0
- yield @only
0
+ if only
0
+ yield only
0
           elsif socket || swiftiply?
0
- @size.times { |n| yield n }
0
+ size.times { |n| yield n }
0
           else
0
- @size.times { |n| yield first_port + n }
0
+ size.times { |n| yield first_port + n }
0
           end
0
         end
0
       
...
19
20
21
 
 
 
 
 
22
23
24
...
19
20
21
22
23
24
25
26
27
28
29
0
@@ -19,6 +19,11 @@
0
     
0
       def initialize(options)
0
         @options = options
0
+
0
+ if @options[:socket]
0
+ @options.delete(:address)
0
+ @options.delete(:port)
0
+ end
0
       end
0
     
0
       def start
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@
0
       TEMPLATE = File.dirname(__FILE__) + '/service.sh.erb'
0
     
0
       def initialize(options)
0
- @options = options
0
+ super
0
       
0
         raise PlatformNotSupported, 'Running as a service only supported on Linux' unless Thin.linux?
0
       end
...
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
14
15
16
 
 
17
18
19
 
 
 
 
 
20
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
27
...
29
30
31
 
32
33
34
...
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
...
76
77
78
79
80
81
82
0
@@ -8,20 +8,67 @@
0
 # bleak log/memlog
0
 #
0
 
0
+module Kernel
0
+ def alias_method_chain(target, feature)
0
+ # Strip out punctuation on predicates or bang methods since
0
+ # e.g. target?_without_feature is not a valid method name.
0
+ aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
0
+ yield(aliased_target, punctuation) if block_given?
0
+
0
+ with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
0
+
0
+ alias_method without_method, target
0
+ alias_method target, with_method
0
+
0
+ case
0
+ when public_method_defined?(without_method)
0
+ public target
0
+ when protected_method_defined?(without_method)
0
+ protected target
0
+ when private_method_defined?(without_method)
0
+ private target
0
+ end
0
+ end
0
+end
0
+
0
 module BleakInstruments
0
   module Connection
0
     def self.included(base)
0
       base.class_eval do
0
- alias_method :process_without_instrument, :process
0
- alias_method :process, :process_with_instrument
0
+ alias_method_chain :receive_data, :instrument
0
+ alias_method_chain :process, :instrument
0
       end
0
     end
0
     
0
+ def receive_data_with_instrument(data)
0
+ receive_data_without_instrument(data)
0
+ $memlogger.snapshot($logfile, "connection/receive_data", false, 0.1)
0
+ end
0
+
0
     def process_with_instrument
0
       process_without_instrument
0
       $memlogger.snapshot($logfile, "connection/process", false, 0.1)
0
     end
0
   end
0
+
0
+ module Connector
0
+ def self.included(base)
0
+ base.class_eval do
0
+ alias_method_chain :connect, :instrument
0
+ alias_method_chain :initialize_connection, :instrument
0
+ end
0
+ end
0
+
0
+ def connect_with_instrument
0
+ connect_without_instrument
0
+ $memlogger.snapshot($logfile, "connector/connect", false, 0.1)
0
+ end
0
+
0
+ def initialize_connection_with_instrument(connection)
0
+ initialize_connection_without_instrument(connection)
0
+ $memlogger.snapshot($logfile, "connector/initialize_connection", false, 0.1)
0
+ end
0
+ end
0
 end
0
 
0
 require 'rubygems'
0
@@ -29,6 +76,7 @@
0
 require File.dirname(__FILE__) + '/../lib/thin'
0
 
0
 Thin::Connection.send :include, BleakInstruments::Connection
0
+Thin::Connectors::TcpServer.send :include, BleakInstruments::Connector
0
 
0
 $memlogger = BleakHouse::Logger.new
0
 File.delete($logfile = File.expand_path("log/memlog")) rescue nil
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -1 +1,15 @@
0
+#!/usr/bin/env ruby
0
+# Script to profile thin using ruby-prof.
0
+# Takes the same arguments as the thin script.
0
+require 'rubygems'
0
+require 'ruby-prof'
0
+
0
+# Profile the code
0
+result = RubyProf.profile do
0
+ load 'bin/thin'
0
+end
0
+
0
+# Print a graph profile to text
0
+printer = RubyProf::GraphPrinter.new(result)
0
+printer.print(STDOUT, 0)
...
 
 
...
1
2
0
@@ -1 +1,3 @@
0
+#!/usr/bin/env bash
0
+valgrind --tool=memcheck --leak-check=yes --show-reachable=no --num-callers=15 --track-fds=yes ruby bin/thin $@
...
197
198
199
 
200
201
202
...
197
198
199
200
201
202
203
0
@@ -197,6 +197,7 @@
0
       li { a "Lipomics", :href => 'http://www.lipomics.com/' }
0
       li { a "RaPlanet", :href => 'http://planet.zhekov.net/' }
0
       li { a "Ninja Hideout blog", :href => 'http://blog.ninjahideout.com/' }
0
+ li { a "blog.hoodow.de", :href => 'http://blog.hoodow.de/articles/2008/02/09/thin' }
0
     end
0
     
0
     p { "If you'd like to have your site listed here, #{a 'drop me an email', :href => 'mailto:macournoyer@gmail.com'}" }
...
19
20
21
22
23
24
25
26
27
28
...
120
121
122
123
124
125
126
127
128
129
130
...
19
20
21
 
 
 
 
22
23
24
...
116
117
118
 
 
 
 
 
119
120
121
0
@@ -19,10 +19,6 @@
0
     @cluster.send(:include_server_number, 'thin.pid', 3000).should == 'thin.3000.pid'
0
   end
0
   
0
- it "should exclude :servers option" do
0
- @cluster.options.should_not have_key(:servers)
0
- end
0
-
0
   it 'should call each server' do
0
     calls = []
0
     @cluster.send(:with_each_server) do |port|
0
@@ -120,11 +116,6 @@
0
                            :only => 3001
0
                           )
0
     @cluster.silent = true
0
- end
0
-
0
- it "should exclude :servers and :only options" do
0
- @cluster.options.should_not have_key(:servers)
0
- @cluster.options.should_not have_key(:only)
0
   end
0
   
0
   it 'should call only specified server' do

Comments

    No one has commented yet.