thin 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

data/README ADDED
@@ -0,0 +1,35 @@
1
+ == Thin
2
+
3
+ Tiny, fast & funny HTTP server
4
+
5
+ === Installation
6
+
7
+ sudo gem install thin --source http://code.macournoyer.com
8
+
9
+ Or get the source:
10
+
11
+ svn co http://code.macournoyer.com/svn/thin/trunk thin
12
+
13
+ === Usage
14
+ In your Rails app directory:
15
+
16
+ thin start
17
+
18
+ Get more help with the thin script at http://code.macournoyer.com/thin/doc/files/bin/thin.html
19
+ and with the thin_cluster script at http://code.macournoyer.com/thin/doc/files/bin/thin_cluster.html
20
+
21
+ === License
22
+ Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.
23
+
24
+ === Credits
25
+ Lots of the code was inspired (or stolen entirely) from Mongrel http://mongrel.rubyforge.org by Zed Shaw.
26
+ Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
27
+ <zedshaw at zedshaw dot com> You can redistribute it and/or modify it under
28
+ either the terms of the GPL.
29
+
30
+ transat/parser.rb was taken from Piston source code.
31
+ Copyright (c) 2006 Francois Beausoleil <francois@teksol.info>
32
+
33
+ Thin is copyright Marc-Andre Cournoyer <macournoyer@gmail.com>
34
+
35
+ Please report any bug using http://code.macournoyer.com/thin/trac.fcgi/newticket
@@ -0,0 +1,101 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+ require 'erb'
7
+
8
+ require File.dirname(__FILE__) + '/lib/thin'
9
+
10
+ REVISION = `svn info`.match('Revision: (\d+)')[1]
11
+ CLEAN.include %w(doc/rdoc pkg tmp log)
12
+
13
+ Rake::TestTask.new do |t|
14
+ t.pattern = 'test/*_test.rb'
15
+ end
16
+ task :default => :test
17
+
18
+ Rake::RDocTask.new do |rdoc|
19
+ rdoc.rdoc_dir = 'doc/rdoc'
20
+ rdoc.options += ['--quiet', '--title', Thin::NAME,
21
+ "--opname", "index.html",
22
+ "--line-numbers",
23
+ "--main", "README",
24
+ "--inline-source"]
25
+ rdoc.template = "site/rdoc.rb"
26
+ rdoc.main = "README"
27
+ rdoc.title = Thin::NAME
28
+ rdoc.rdoc_files.add ['README', 'lib/thin/*.rb', 'bin/*']
29
+ end
30
+
31
+ namespace :rdoc do
32
+ desc 'Upload rdoc to code.macournoyer.com'
33
+ task :upload => :rdoc do
34
+ upload "doc/rdoc", 'thin/doc', :replace => true
35
+ end
36
+ end
37
+
38
+ spec = Gem::Specification.new do |s|
39
+ s.name = Thin::NAME
40
+ s.version = Thin::VERSION::STRING
41
+ s.platform = Gem::Platform::RUBY
42
+ s.summary = "Thin and fast web server"
43
+ s.description = s.summary
44
+ s.author = "Marc-Andre Cournoyer"
45
+ s.email = 'macournoyer@gmail.com'
46
+ s.homepage = 'http://code.macournoyer.com/thin/'
47
+ s.executables = %w(thin thin_cluster)
48
+
49
+ s.required_ruby_version = '>= 1.8.6'
50
+
51
+ s.files = %w(README Rakefile) + Dir.glob("{bin,doc,lib}/**/*")
52
+
53
+ s.require_path = "lib"
54
+ s.bindir = "bin"
55
+ end
56
+
57
+ Rake::GemPackageTask.new(spec) do |p|
58
+ p.gem_spec = spec
59
+ end
60
+
61
+ namespace :gem do
62
+ desc 'Upload gem to code.macournoyer.com'
63
+ task :upload => :gem do
64
+ upload "pkg/#{spec.full_name}.gem", 'gems'
65
+ sh 'ssh macournoyer@macournoyer.com "cd code.macournoyer.com && index_gem_repository.rb"'
66
+ end
67
+ end
68
+
69
+ desc 'Show some stats about the code'
70
+ task :stats do
71
+ line_count = proc do |path|
72
+ Dir[path].collect { |f| File.open(f).readlines.reject { |l| l =~ /^\s*\#/ }.size }.inject(0){ |sum,n| sum += n }
73
+ end
74
+ puts "#{line_count['lib/**/*.rb'].to_s.rjust(6)} LOC of lib"
75
+ puts "#{line_count['lib/thin/{server,request,response,cgi,rails,handler,headers}.rb'].to_s.rjust(6)} LOC of web serving stuff"
76
+ puts "#{line_count['test/**/*.rb'].to_s.rjust(6)} LOC of test"
77
+ end
78
+
79
+ namespace :site do
80
+ task :build do
81
+ mkdir_p 'tmp/site/images'
82
+ cd 'tmp/site' do
83
+ ruby '../../site/thin.rb', '--dump'
84
+ end
85
+ cp 'site/style.css', 'tmp/site'
86
+ cp_r Dir['site/images/*'], 'tmp/site/images'
87
+ end
88
+
89
+ desc 'Upload website to code.macournoyer.com'
90
+ task :upload => 'site:build' do
91
+ upload 'tmp/site/*', 'thin'
92
+ end
93
+ end
94
+
95
+ desc 'Upload all the stuff to code.macournoyer.com'
96
+ task :upload => %w(gem:upload site:upload rdoc:upload)
97
+
98
+ def upload(file, to, options={})
99
+ sh %{ssh macournoyer@macournoyer.com "rm -rf code.macournoyer.com/#{to}"} if options[:replace]
100
+ sh %{scp -rq #{file} macournoyer@macournoyer.com:code.macournoyer.com/#{to}}
101
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # == thin
3
+ # Script to launch a Thin server for a Rails application.
4
+ #
5
+ # To start a server for your current Rails app:
6
+ # thin start
7
+ # You can specify the port using the -p option:
8
+ # thin start -p3001
9
+ # By default the server will bind to 0.0.0.0:3000
10
+ #
11
+ # You can specify which Rails environment should be loaded with the -e option:
12
+ # thin start -e production
13
+ #
14
+ # You can also start the server in daemon mode:
15
+ # thin start -d
16
+ # And later stop it
17
+ # thin stop
18
+ #
19
+ # Run <tt>thin help</tt> to get help.
20
+
21
+ require File.dirname(__FILE__) + '/../lib/thin'
22
+ require 'thin/command'
23
+
24
+ Thin.define_commands do
25
+ program_name 'thin'
26
+ version Thin::VERSION::STRING
27
+ help 'Thin is a web server that can run your Rails app in no time'
28
+
29
+ option :address, :short => :a, :default => '0.0.0.0', :message => 'Address to bind to',
30
+ :param_name => 'ADDRESS'
31
+ option :port, :short => :p, :default => 3000, :message => 'Port number to bind to',
32
+ :param_name => 'PORT', :type => :int
33
+ option :environment, :short => :e, :default => 'development', :message => 'Rails environment',
34
+ :param_name => 'ENVIRONMENT'
35
+ option :log_file, :short => :l, :default => 'log/thin.log', :message => 'File to write log output to (use with -d)',
36
+ :param_name => 'PATH'
37
+ option :pid_file, :short => :P, :default => 'tmp/pids/thin.pid', :message => 'File to write the PID (use with -d)',
38
+ :param_name => 'PATH'
39
+ option :daemonize, :short => :d, :message => 'Run in the background'
40
+ option :user, :short => :u, :param_name => 'USER', :message => 'User to run the process as'
41
+ option :group, :short => :g, :param_name => 'GROUP', :message => 'Group to run the process as'
42
+ option :timeout, :short => :T, :param_name => 'SEC', :message => 'Server timeout before giving up',
43
+ :default => 60
44
+ option :trace, :short => :t, :message => 'Turn trace on'
45
+
46
+ command :start, Thin::Commands::Server::Start, :valid_options => [:address, :port, :environment, :log_file, :daemonize, :pid_file, :user, :group, :trace, :timeout]
47
+ command :stop, Thin::Commands::Server::Stop, :valid_options => [:pid_file, :timeout]
48
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ # == this_cluster
3
+ # Script used to launch multiple server instances.
4
+ # It takes most of the same argument as the +thin+ script
5
+ # plus the -n option to specify the number of servers to run.
6
+ #
7
+ # Also, you can store your options into a config file, create it like this:
8
+ # thin_cluster config -C /var/www/my_app/current config
9
+ # Then a config file will be created in /var/www/my_app/current/config/thin.yml
10
+ # with the default options.
11
+ # You can launch your 3 servers with:
12
+ # thin_cluster start
13
+ # And stop them with:
14
+ # thin_cluster stop
15
+ #
16
+ # Run <tt>thin_cluster help</tt> to get help.
17
+
18
+ require File.dirname(__FILE__) + '/../lib/thin'
19
+ require 'thin/command'
20
+
21
+ Thin.define_commands do
22
+ program_name 'thin_cluster'
23
+ version Thin::VERSION::STRING
24
+ help 'Thin cluster monitoring tool for managing multiple Thin web servers'
25
+
26
+ option :address, :short => :a, :default => '127.0.0.1', :message => 'Address to bind to',
27
+ :param_name => 'ADDRESS'
28
+ option :port, :short => :p, :default => 5000, :message => 'Port number to bind to',
29
+ :param_name => 'PORT', :type => :int
30
+ option :servers, :short => :n, :default => 3, :message => 'Number of servers to launch',
31
+ :param_name => 'NUM', :type => :int
32
+ option :environment, :short => :e, :default => 'production', :message => 'Rails environment',
33
+ :param_name => 'ENVIRONMENT'
34
+ option :log_file, :short => :l, :default => 'log/thin.log', :message => 'File to write log output to',
35
+ :param_name => 'PATH'
36
+ option :pid_file, :short => :P, :default => 'tmp/pids/thin.pid', :message => 'File to write the PID (use with -d)',
37
+ :param_name => 'PATH'
38
+ option :cwd, :short => :c, :param_name => 'PATH', :message => 'Change to dir before starting'
39
+ option :user, :short => :u, :param_name => 'USER', :message => 'User to run the process as'
40
+ option :group, :short => :g, :param_name => 'GROUP', :message => 'Group to run the process as'
41
+ option :config, :short => :C, :default => 'config/thin.yml', :message => 'Config file',
42
+ :param_name => 'PATH'
43
+ option :timeout, :short => :T, :param_name => 'SEC', :message => 'Server and command timeout',
44
+ :default => 60
45
+ option :trace, :short => :t, :message => 'Turn trace on'
46
+
47
+ valid_options = [:address, :port, :environment, :log_file, :pid_file, :cwd, :servers, :config, :user, :group, :trace]
48
+
49
+ command :start, Thin::Commands::Cluster::Start, :valid_options => valid_options
50
+ command :stop, Thin::Commands::Cluster::Stop, :valid_options => valid_options
51
+ command :restart, Thin::Commands::Cluster::Restart, :valid_options => valid_options
52
+ command :config, Thin::Commands::Cluster::Config, :valid_options => valid_options
53
+ end
@@ -0,0 +1,271 @@
1
+ = Benchmark Thin vs Mongrel
2
+
3
+ == Single instance
4
+ On server instance. Running Rails in development environment.
5
+ App is http://refactormycode.com with no caching.
6
+
7
+ === Thin
8
+ marc:~ marc$ ab -n10 -c3 localhost:3000/
9
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
10
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
11
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
12
+
13
+ Benchmarking localhost (be patient).....done
14
+ Server Software: thin
15
+ Server Hostname: localhost
16
+ Server Port: 3000
17
+
18
+ Document Path: /
19
+ Document Length: 11195 bytes
20
+
21
+ Concurrency Level: 3
22
+ Time taken for tests: 15.429 seconds
23
+ Complete requests: 10
24
+ Failed requests: 0
25
+ Broken pipe errors: 0
26
+ Total transferred: 114510 bytes
27
+ HTML transferred: 111950 bytes
28
+ Requests per second: 0.65 [#/sec] (mean)
29
+ Time per request: 4628.70 [ms] (mean)
30
+ Time per request: 1542.90 [ms] (mean, across all concurrent requests)
31
+ Transfer rate: 7.42 [Kbytes/sec] received
32
+
33
+ Connnection Times (ms)
34
+ min mean[+/-sd] median max
35
+ Connect: 0 0 0.0 0 0
36
+ Processing: 1935 4175 874.1 4458 4903
37
+ Waiting: 1935 4175 874.1 4458 4903
38
+ Total: 1935 4175 874.1 4458 4903
39
+
40
+ Percentage of the requests served within a certain time (ms)
41
+ 50% 4458
42
+ 66% 4525
43
+ 75% 4562
44
+ 80% 4597
45
+ 90% 4903
46
+ 95% 4903
47
+ 98% 4903
48
+ 99% 4903
49
+ 100% 4903 (last request)
50
+
51
+ === Mongrel
52
+ marc:~ marc$ ab -n10 -c3 localhost:3001/
53
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
54
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
55
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
56
+
57
+ Benchmarking localhost (be patient).....done
58
+ Server Software: Mongrel
59
+ Server Hostname: localhost
60
+ Server Port: 3001
61
+
62
+ Document Path: /
63
+ Document Length: 11195 bytes
64
+
65
+ Concurrency Level: 3
66
+ Time taken for tests: 16.522 seconds
67
+ Complete requests: 10
68
+ Failed requests: 0
69
+ Broken pipe errors: 0
70
+ Total transferred: 114930 bytes
71
+ HTML transferred: 111950 bytes
72
+ Requests per second: 0.61 [#/sec] (mean)
73
+ Time per request: 4956.60 [ms] (mean)
74
+ Time per request: 1652.20 [ms] (mean, across all concurrent requests)
75
+ Transfer rate: 6.96 [Kbytes/sec] received
76
+
77
+ Connnection Times (ms)
78
+ min mean[+/-sd] median max
79
+ Connect: 0 0 0.0 0 0
80
+ Processing: 2629 4496 746.2 4662 5602
81
+ Waiting: 2629 4496 746.2 4662 5602
82
+ Total: 2629 4496 746.2 4662 5602
83
+
84
+ Percentage of the requests served within a certain time (ms)
85
+ 50% 4662
86
+ 66% 4681
87
+ 75% 4691
88
+ 80% 4715
89
+ 90% 5602
90
+ 95% 5602
91
+ 98% 5602
92
+ 99% 5602
93
+ 100% 5602 (last request)
94
+
95
+ == Cluster
96
+ Using Nginx as the load balancer with 3 app instance.
97
+ App is http://refactormycode.com with no caching.
98
+
99
+ === Thin
100
+ marc:~ marc$ ab -n10 -c5 localhost/
101
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
102
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
103
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
104
+
105
+ Benchmarking localhost (be patient).....done
106
+ Server Software: nginx/0.5.33
107
+ Server Hostname: localhost
108
+ Server Port: 80
109
+
110
+ Document Path: /
111
+ Document Length: 45456 bytes
112
+
113
+ Concurrency Level: 5
114
+ Time taken for tests: 4.444 seconds
115
+ Complete requests: 10
116
+ Failed requests: 0
117
+ Broken pipe errors: 0
118
+ Total transferred: 458270 bytes
119
+ HTML transferred: 454560 bytes
120
+ Requests per second: 2.25 [#/sec] (mean)
121
+ Time per request: 2222.00 [ms] (mean)
122
+ Time per request: 444.40 [ms] (mean, across all concurrent requests)
123
+ Transfer rate: 103.12 [Kbytes/sec] received
124
+
125
+ Connnection Times (ms)
126
+ min mean[+/-sd] median max
127
+ Connect: 0 0 0.0 0 0
128
+ Processing: 1031 1703 1064.3 1185 4119
129
+ Waiting: 1031 1703 1064.3 1185 4119
130
+ Total: 1031 1703 1064.3 1185 4119
131
+
132
+ Percentage of the requests served within a certain time (ms)
133
+ 50% 1185
134
+ 66% 1207
135
+ 75% 2178
136
+ 80% 2978
137
+ 90% 4119
138
+ 95% 4119
139
+ 98% 4119
140
+ 99% 4119
141
+ 100% 4119 (last request)
142
+ marc:~ marc$ ab -n100 -c10 localhost/
143
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
144
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
145
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
146
+
147
+ Benchmarking localhost (be patient).....done
148
+ Server Software: nginx/0.5.33
149
+ Server Hostname: localhost
150
+ Server Port: 80
151
+
152
+ Document Path: /
153
+ Document Length: 45456 bytes
154
+
155
+ Concurrency Level: 10
156
+ Time taken for tests: 36.949 seconds
157
+ Complete requests: 100
158
+ Failed requests: 0
159
+ Broken pipe errors: 0
160
+ Total transferred: 4582700 bytes
161
+ HTML transferred: 4545600 bytes
162
+ Requests per second: 2.71 [#/sec] (mean)
163
+ Time per request: 3694.90 [ms] (mean)
164
+ Time per request: 369.49 [ms] (mean, across all concurrent requests)
165
+ Transfer rate: 124.03 [Kbytes/sec] received
166
+
167
+ Connnection Times (ms)
168
+ min mean[+/-sd] median max
169
+ Connect: 0 0 0.0 0 0
170
+ Processing: 996 3502 762.1 3539 4841
171
+ Waiting: 996 3502 762.3 3539 4841
172
+ Total: 996 3502 762.1 3539 4841
173
+
174
+ Percentage of the requests served within a certain time (ms)
175
+ 50% 3539
176
+ 66% 3947
177
+ 75% 4167
178
+ 80% 4229
179
+ 90% 4417
180
+ 95% 4563
181
+ 98% 4742
182
+ 99% 4841
183
+ 100% 4841 (last request)
184
+
185
+
186
+ === Mongrel
187
+
188
+ marc:~ marc$ ab -n10 -c5 localhost/
189
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
190
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
191
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
192
+
193
+ Benchmarking localhost (be patient).....done
194
+ Server Software: nginx/0.5.33
195
+ Server Hostname: localhost
196
+ Server Port: 80
197
+
198
+ Document Path: /
199
+ Document Length: 45455 bytes
200
+
201
+ Concurrency Level: 5
202
+ Time taken for tests: 5.995 seconds
203
+ Complete requests: 10
204
+ Failed requests: 0
205
+ Broken pipe errors: 0
206
+ Total transferred: 458600 bytes
207
+ HTML transferred: 454550 bytes
208
+ Requests per second: 1.67 [#/sec] (mean)
209
+ Time per request: 2997.50 [ms] (mean)
210
+ Time per request: 599.50 [ms] (mean, across all concurrent requests)
211
+ Transfer rate: 76.50 [Kbytes/sec] received
212
+
213
+ Connnection Times (ms)
214
+ min mean[+/-sd] median max
215
+ Connect: 0 0 0.0 0 0
216
+ Processing: 1248 2500 1138.1 2743 4245
217
+ Waiting: 1248 2500 1138.0 2743 4245
218
+ Total: 1248 2500 1138.1 2743 4245
219
+
220
+ Percentage of the requests served within a certain time (ms)
221
+ 50% 2743
222
+ 66% 3040
223
+ 75% 3148
224
+ 80% 4131
225
+ 90% 4245
226
+ 95% 4245
227
+ 98% 4245
228
+ 99% 4245
229
+ 100% 4245 (last request)
230
+ marc:~ marc$ ab -n100 -c10 localhost/
231
+ This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
232
+ Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
233
+ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
234
+
235
+ Benchmarking localhost (be patient).....done
236
+ Server Software: nginx/0.5.33
237
+ Server Hostname: localhost
238
+ Server Port: 80
239
+
240
+ Document Path: /
241
+ Document Length: 45455 bytes
242
+
243
+ Concurrency Level: 10
244
+ Time taken for tests: 41.135 seconds
245
+ Complete requests: 100
246
+ Failed requests: 0
247
+ Broken pipe errors: 0
248
+ Total transferred: 4586000 bytes
249
+ HTML transferred: 4545500 bytes
250
+ Requests per second: 2.43 [#/sec] (mean)
251
+ Time per request: 4113.50 [ms] (mean)
252
+ Time per request: 411.35 [ms] (mean, across all concurrent requests)
253
+ Transfer rate: 111.49 [Kbytes/sec] received
254
+
255
+ Connnection Times (ms)
256
+ min mean[+/-sd] median max
257
+ Connect: 0 0 0.0 0 0
258
+ Processing: 1600 3921 640.4 3877 5694
259
+ Waiting: 1600 3921 640.4 3877 5694
260
+ Total: 1600 3921 640.4 3877 5694
261
+
262
+ Percentage of the requests served within a certain time (ms)
263
+ 50% 3877
264
+ 66% 4187
265
+ 75% 4353
266
+ 80% 4402
267
+ 90% 4585
268
+ 95% 4919
269
+ 98% 5351
270
+ 99% 5694
271
+ 100% 5694 (last request)