unicorn-fotopedia 0.99.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.CHANGELOG.old +25 -0
- data/.document +19 -0
- data/.gitignore +21 -0
- data/.mailmap +26 -0
- data/CONTRIBUTORS +32 -0
- data/COPYING +339 -0
- data/DESIGN +105 -0
- data/Documentation/.gitignore +5 -0
- data/Documentation/GNUmakefile +30 -0
- data/Documentation/unicorn.1.txt +171 -0
- data/Documentation/unicorn_rails.1.txt +172 -0
- data/FAQ +52 -0
- data/GIT-VERSION-GEN +40 -0
- data/GNUmakefile +292 -0
- data/HACKING +116 -0
- data/ISSUES +36 -0
- data/KNOWN_ISSUES +50 -0
- data/LICENSE +55 -0
- data/PHILOSOPHY +145 -0
- data/README +149 -0
- data/Rakefile +191 -0
- data/SIGNALS +109 -0
- data/Sandbox +78 -0
- data/TODO +5 -0
- data/TUNING +70 -0
- data/bin/unicorn +126 -0
- data/bin/unicorn_rails +203 -0
- data/examples/big_app_gc.rb +33 -0
- data/examples/echo.ru +27 -0
- data/examples/git.ru +13 -0
- data/examples/init.sh +58 -0
- data/examples/logger_mp_safe.rb +25 -0
- data/examples/nginx.conf +139 -0
- data/examples/unicorn.conf.rb +78 -0
- data/ext/unicorn_http/CFLAGS +13 -0
- data/ext/unicorn_http/c_util.h +124 -0
- data/ext/unicorn_http/common_field_optimization.h +111 -0
- data/ext/unicorn_http/ext_help.h +77 -0
- data/ext/unicorn_http/extconf.rb +14 -0
- data/ext/unicorn_http/global_variables.h +89 -0
- data/ext/unicorn_http/unicorn_http.rl +714 -0
- data/ext/unicorn_http/unicorn_http_common.rl +75 -0
- data/lib/unicorn.rb +847 -0
- data/lib/unicorn/app/exec_cgi.rb +150 -0
- data/lib/unicorn/app/inetd.rb +109 -0
- data/lib/unicorn/app/old_rails.rb +33 -0
- data/lib/unicorn/app/old_rails/static.rb +58 -0
- data/lib/unicorn/cgi_wrapper.rb +145 -0
- data/lib/unicorn/configurator.rb +421 -0
- data/lib/unicorn/const.rb +34 -0
- data/lib/unicorn/http_request.rb +72 -0
- data/lib/unicorn/http_response.rb +75 -0
- data/lib/unicorn/launcher.rb +65 -0
- data/lib/unicorn/oob_gc.rb +58 -0
- data/lib/unicorn/socket_helper.rb +152 -0
- data/lib/unicorn/tee_input.rb +217 -0
- data/lib/unicorn/util.rb +90 -0
- data/local.mk.sample +62 -0
- data/setup.rb +1586 -0
- data/t/.gitignore +2 -0
- data/t/GNUmakefile +67 -0
- data/t/README +42 -0
- data/t/bin/content-md5-put +36 -0
- data/t/bin/sha1sum.rb +23 -0
- data/t/bin/unused_listen +40 -0
- data/t/bin/utee +12 -0
- data/t/env.ru +3 -0
- data/t/my-tap-lib.sh +200 -0
- data/t/t0000-http-basic.sh +50 -0
- data/t/t0001-reload-bad-config.sh +52 -0
- data/t/t0002-config-conflict.sh +49 -0
- data/t/test-lib.sh +100 -0
- data/test/aggregate.rb +15 -0
- data/test/benchmark/README +50 -0
- data/test/benchmark/dd.ru +18 -0
- data/test/exec/README +5 -0
- data/test/exec/test_exec.rb +1038 -0
- data/test/rails/app-1.2.3/.gitignore +2 -0
- data/test/rails/app-1.2.3/Rakefile +7 -0
- data/test/rails/app-1.2.3/app/controllers/application.rb +6 -0
- data/test/rails/app-1.2.3/app/controllers/foo_controller.rb +36 -0
- data/test/rails/app-1.2.3/app/helpers/application_helper.rb +4 -0
- data/test/rails/app-1.2.3/config/boot.rb +11 -0
- data/test/rails/app-1.2.3/config/database.yml +12 -0
- data/test/rails/app-1.2.3/config/environment.rb +13 -0
- data/test/rails/app-1.2.3/config/environments/development.rb +9 -0
- data/test/rails/app-1.2.3/config/environments/production.rb +5 -0
- data/test/rails/app-1.2.3/config/routes.rb +6 -0
- data/test/rails/app-1.2.3/db/.gitignore +0 -0
- data/test/rails/app-1.2.3/public/404.html +1 -0
- data/test/rails/app-1.2.3/public/500.html +1 -0
- data/test/rails/app-2.0.2/.gitignore +2 -0
- data/test/rails/app-2.0.2/Rakefile +7 -0
- data/test/rails/app-2.0.2/app/controllers/application.rb +4 -0
- data/test/rails/app-2.0.2/app/controllers/foo_controller.rb +36 -0
- data/test/rails/app-2.0.2/app/helpers/application_helper.rb +4 -0
- data/test/rails/app-2.0.2/config/boot.rb +11 -0
- data/test/rails/app-2.0.2/config/database.yml +12 -0
- data/test/rails/app-2.0.2/config/environment.rb +17 -0
- data/test/rails/app-2.0.2/config/environments/development.rb +8 -0
- data/test/rails/app-2.0.2/config/environments/production.rb +5 -0
- data/test/rails/app-2.0.2/config/routes.rb +6 -0
- data/test/rails/app-2.0.2/db/.gitignore +0 -0
- data/test/rails/app-2.0.2/public/404.html +1 -0
- data/test/rails/app-2.0.2/public/500.html +1 -0
- data/test/rails/app-2.1.2/.gitignore +2 -0
- data/test/rails/app-2.1.2/Rakefile +7 -0
- data/test/rails/app-2.1.2/app/controllers/application.rb +4 -0
- data/test/rails/app-2.1.2/app/controllers/foo_controller.rb +36 -0
- data/test/rails/app-2.1.2/app/helpers/application_helper.rb +4 -0
- data/test/rails/app-2.1.2/config/boot.rb +111 -0
- data/test/rails/app-2.1.2/config/database.yml +12 -0
- data/test/rails/app-2.1.2/config/environment.rb +17 -0
- data/test/rails/app-2.1.2/config/environments/development.rb +7 -0
- data/test/rails/app-2.1.2/config/environments/production.rb +5 -0
- data/test/rails/app-2.1.2/config/routes.rb +6 -0
- data/test/rails/app-2.1.2/db/.gitignore +0 -0
- data/test/rails/app-2.1.2/public/404.html +1 -0
- data/test/rails/app-2.1.2/public/500.html +1 -0
- data/test/rails/app-2.2.2/.gitignore +2 -0
- data/test/rails/app-2.2.2/Rakefile +7 -0
- data/test/rails/app-2.2.2/app/controllers/application.rb +4 -0
- data/test/rails/app-2.2.2/app/controllers/foo_controller.rb +36 -0
- data/test/rails/app-2.2.2/app/helpers/application_helper.rb +4 -0
- data/test/rails/app-2.2.2/config/boot.rb +111 -0
- data/test/rails/app-2.2.2/config/database.yml +12 -0
- data/test/rails/app-2.2.2/config/environment.rb +17 -0
- data/test/rails/app-2.2.2/config/environments/development.rb +7 -0
- data/test/rails/app-2.2.2/config/environments/production.rb +5 -0
- data/test/rails/app-2.2.2/config/routes.rb +6 -0
- data/test/rails/app-2.2.2/db/.gitignore +0 -0
- data/test/rails/app-2.2.2/public/404.html +1 -0
- data/test/rails/app-2.2.2/public/500.html +1 -0
- data/test/rails/app-2.3.5/.gitignore +2 -0
- data/test/rails/app-2.3.5/Rakefile +7 -0
- data/test/rails/app-2.3.5/app/controllers/application_controller.rb +5 -0
- data/test/rails/app-2.3.5/app/controllers/foo_controller.rb +36 -0
- data/test/rails/app-2.3.5/app/helpers/application_helper.rb +4 -0
- data/test/rails/app-2.3.5/config/boot.rb +109 -0
- data/test/rails/app-2.3.5/config/database.yml +12 -0
- data/test/rails/app-2.3.5/config/environment.rb +17 -0
- data/test/rails/app-2.3.5/config/environments/development.rb +7 -0
- data/test/rails/app-2.3.5/config/environments/production.rb +6 -0
- data/test/rails/app-2.3.5/config/routes.rb +6 -0
- data/test/rails/app-2.3.5/db/.gitignore +0 -0
- data/test/rails/app-2.3.5/public/404.html +1 -0
- data/test/rails/app-2.3.5/public/500.html +1 -0
- data/test/rails/app-2.3.5/public/x.txt +1 -0
- data/test/rails/test_rails.rb +280 -0
- data/test/test_helper.rb +301 -0
- data/test/unit/test_configurator.rb +150 -0
- data/test/unit/test_http_parser.rb +555 -0
- data/test/unit/test_http_parser_ng.rb +443 -0
- data/test/unit/test_request.rb +184 -0
- data/test/unit/test_response.rb +110 -0
- data/test/unit/test_server.rb +291 -0
- data/test/unit/test_signals.rb +206 -0
- data/test/unit/test_socket_helper.rb +147 -0
- data/test/unit/test_tee_input.rb +257 -0
- data/test/unit/test_upload.rb +298 -0
- data/test/unit/test_util.rb +96 -0
- data/unicorn.gemspec +52 -0
- metadata +283 -0
data/ISSUES
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= Issues
|
2
|
+
|
3
|
+
The {mailing list}[mailto:mongrel-unicorn@rubyforge.org] is the best
|
4
|
+
place to report bugs, submit patches and/or obtain support after you
|
5
|
+
have searched the mailing list archives and
|
6
|
+
{documentation}[http://unicorn.bogomips.org].
|
7
|
+
|
8
|
+
* No subscription is needed to post to the mailing list,
|
9
|
+
let us know that we need to Cc: replies to you if you're unsubscribed.
|
10
|
+
* Do not {top post}[http://catb.org/jargon/html/T/top-post.html] in replies
|
11
|
+
* Quote only the relevant portions of the message you're replying to
|
12
|
+
* Do not send HTML mail
|
13
|
+
|
14
|
+
If your issue is of a sensitive nature or you're just shy in public,
|
15
|
+
then feel free to email us privately at mailto:unicorn@bogomips.org
|
16
|
+
instead and your issue will be handled discreetly.
|
17
|
+
|
18
|
+
If you don't get a response within a few days, we may have forgotten
|
19
|
+
about it so feel free to ask again.
|
20
|
+
|
21
|
+
== Submitting Patches
|
22
|
+
|
23
|
+
See the HACKING document (and additionally, the
|
24
|
+
Documentation/SubmittingPatches document distributed with git) on
|
25
|
+
guidelines for patch submission.
|
26
|
+
|
27
|
+
== Mailing List Info
|
28
|
+
|
29
|
+
* subscribe: http://rubyforge.org/mailman/listinfo/mongrel-unicorn
|
30
|
+
* post: mailto:mongrel-unicorn@rubyforge.org
|
31
|
+
* private: mailto:unicorn@bogomips.org
|
32
|
+
|
33
|
+
== Mailing List Archives
|
34
|
+
|
35
|
+
* nntp://news.gmane.org/gmane.comp.lang.ruby.unicorn.general
|
36
|
+
* http://rubyforge.org/pipermail/mongrel-unicorn
|
data/KNOWN_ISSUES
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Known Issues
|
2
|
+
|
3
|
+
Occasionally odd {issues}[link:ISSUES.html] arise without a transparent or
|
4
|
+
acceptable solution. Those issues are documented here.
|
5
|
+
|
6
|
+
* For notes on sandboxing tools such as Bundler or Isolate,
|
7
|
+
see the {Sandbox}[link:Sandbox.html] page.
|
8
|
+
|
9
|
+
* Under Ruby 1.9.1, methods like Array#shuffle and Array#sample will
|
10
|
+
segfault if called after forking. This is fixed in trunk (r26936) and
|
11
|
+
should be backported to the next 1.9.1 stable release (after p378).
|
12
|
+
Until then, it is advisable to call "Kernel.rand" in your after_fork
|
13
|
+
hook to reinitialize the random number generator.
|
14
|
+
|
15
|
+
See http://redmine.ruby-lang.org/issues/show/2962 for more details
|
16
|
+
|
17
|
+
* When using "preload_app true", with apps using background threads
|
18
|
+
need to restart them in the after_fork hook because threads are never
|
19
|
+
shared with child processes. Additionally, any synchronization
|
20
|
+
primitives (Mutexes, Monitors, ConditionVariables) should be
|
21
|
+
reinitialized in case they are held during fork time to avoid
|
22
|
+
deadlocks. The core Ruby Logger class needlessly uses a MonitorMutex
|
23
|
+
which can be disabled with a {monkey patch}[link:examples/logger_mp_safe.rb]
|
24
|
+
|
25
|
+
* Rails 2.3.2 bundles its own version of Rack. This may cause subtle
|
26
|
+
bugs when simultaneously loaded with the system-wide Rack Rubygem
|
27
|
+
which Unicorn depends on. Upgrading to Rails 2.3.4 (or later) is
|
28
|
+
strongly recommended for all Rails 2.3.x users for this (and security
|
29
|
+
reasons). Rails 2.2.x series (or before) did not bundle Rack and are
|
30
|
+
should be unnaffected. If there is any reason which forces your
|
31
|
+
application to use Rails 2.3.2 and you have no other choice, then
|
32
|
+
you may edit your Unicorn gemspec and remove the Rack dependency.
|
33
|
+
|
34
|
+
ref: http://mid.gmane.org/20091014221552.GA30624@dcvr.yhbt.net
|
35
|
+
Note: the workaround described in the article above only made
|
36
|
+
the issue more subtle and we didn't notice them immediately.
|
37
|
+
|
38
|
+
* WONTFIX: code reloading and restarts with Sinatra 0.3.x (and likely older
|
39
|
+
versions) apps is broken. The workaround is to force production
|
40
|
+
mode to disable code reloading as well as disabling "run" in your
|
41
|
+
Sinatra application:
|
42
|
+
set :env, :production
|
43
|
+
set :run, false
|
44
|
+
Since this is no longer an issue with Sinatra 0.9.x apps, this will not be
|
45
|
+
fixed on our end. Since Unicorn is itself the application launcher, the
|
46
|
+
at_exit handler used in old Sinatra always caused Mongrel to be launched
|
47
|
+
whenever a Unicorn worker was about to exit.
|
48
|
+
|
49
|
+
Also remember we're capable of replacing the running binary without dropping
|
50
|
+
any connections regardless of framework :)
|
data/LICENSE
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
Unicorn is copyrighted free software by all contributors, see logs in
|
2
|
+
revision control for names and email addresses of all of them. You can
|
3
|
+
redistribute it and/or modify it under either the terms of the
|
4
|
+
{GPL2}[http://www.gnu.org/licenses/gpl-2.0.txt] (see link:COPYING) or
|
5
|
+
the conditions below:
|
6
|
+
|
7
|
+
1. You may make and give away verbatim copies of the source form of the
|
8
|
+
software without restriction, provided that you duplicate all of the
|
9
|
+
original copyright notices and associated disclaimers.
|
10
|
+
|
11
|
+
2. You may modify your copy of the software in any way, provided that
|
12
|
+
you do at least ONE of the following:
|
13
|
+
|
14
|
+
a) place your modifications in the Public Domain or otherwise make them
|
15
|
+
Freely Available, such as by posting said modifications to Usenet or an
|
16
|
+
equivalent medium, or by allowing the author to include your
|
17
|
+
modifications in the software.
|
18
|
+
|
19
|
+
b) use the modified software only within your corporation or
|
20
|
+
organization.
|
21
|
+
|
22
|
+
c) rename any non-standard executables so the names do not conflict with
|
23
|
+
standard executables, which must also be provided.
|
24
|
+
|
25
|
+
d) make other distribution arrangements with the author.
|
26
|
+
|
27
|
+
3. You may distribute the software in object code or executable
|
28
|
+
form, provided that you do at least ONE of the following:
|
29
|
+
|
30
|
+
a) distribute the executables and library files of the software,
|
31
|
+
together with instructions (in the manual page or equivalent) on where
|
32
|
+
to get the original distribution.
|
33
|
+
|
34
|
+
b) accompany the distribution with the machine-readable source of the
|
35
|
+
software.
|
36
|
+
|
37
|
+
c) give non-standard executables non-standard names, with
|
38
|
+
instructions on where to get the original software distribution.
|
39
|
+
|
40
|
+
d) make other distribution arrangements with the author.
|
41
|
+
|
42
|
+
4. You may modify and include the part of the software into any other
|
43
|
+
software (possibly commercial). But some files in the distribution
|
44
|
+
are not written by the author, so that they are not under this terms.
|
45
|
+
|
46
|
+
5. The scripts and library files supplied as input to or produced as
|
47
|
+
output from the software do not automatically fall under the
|
48
|
+
copyright of the software, but belong to whomever generated them,
|
49
|
+
and may be sold commercially, and may be aggregated with this
|
50
|
+
software.
|
51
|
+
|
52
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
53
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
54
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
55
|
+
PURPOSE.
|
data/PHILOSOPHY
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
= The Philosophy Behind Unicorn
|
2
|
+
|
3
|
+
Being a server that only runs on Unix-like platforms, Unicorn is
|
4
|
+
strongly tied to the Unix philosophy of doing one thing and (hopefully)
|
5
|
+
doing it well. Despite using HTTP, Unicorn is strictly a _backend_
|
6
|
+
application server for running Rack-based Ruby applications.
|
7
|
+
|
8
|
+
== Avoid Complexity
|
9
|
+
|
10
|
+
Instead of attempting to be efficient at serving slow clients, Unicorn
|
11
|
+
relies on a buffering reverse proxy to efficiently deal with slow
|
12
|
+
clients.
|
13
|
+
|
14
|
+
Unicorn uses an old-fashioned preforking worker model with blocking I/O.
|
15
|
+
Our processing model is the antithesis of more modern (and theoretically
|
16
|
+
more efficient) server processing models using threads or non-blocking
|
17
|
+
I/O with events.
|
18
|
+
|
19
|
+
=== Threads and Events Are Hard
|
20
|
+
|
21
|
+
...to many developers. Reasons for this is beyond the scope of this
|
22
|
+
document. Unicorn avoids concurrency within each worker process so you
|
23
|
+
have fewer things to worry about when developing your application. Of
|
24
|
+
course Unicorn can use multiple worker processes to utilize multiple
|
25
|
+
CPUs or spindles. Applications can still use threads internally, however.
|
26
|
+
|
27
|
+
== Slow Clients Are Problematic
|
28
|
+
|
29
|
+
Most benchmarks we've seen don't tell you this, and Unicorn doesn't
|
30
|
+
care about slow clients... but <i>you</i> should.
|
31
|
+
|
32
|
+
A "slow client" can be any client outside of your datacenter. Network
|
33
|
+
traffic within a local network is always faster than traffic that
|
34
|
+
crosses outside of it. The laws of physics do not allow otherwise.
|
35
|
+
|
36
|
+
Persistent connections were introduced in HTTP/1.1 reduce latency from
|
37
|
+
connection establishment and TCP slow start. They also waste server
|
38
|
+
resources when clients are idle.
|
39
|
+
|
40
|
+
Persistent connections mean one of the Unicorn worker processes
|
41
|
+
(depending on your application, it can be very memory hungry) would
|
42
|
+
spend a significant amount of its time idle keeping the connection alive
|
43
|
+
<i>and not doing anything else</i>. Being single-threaded and using
|
44
|
+
blocking I/O, a worker cannot serve other clients while keeping a
|
45
|
+
connection alive. Thus Unicorn does not implement persistent
|
46
|
+
connections.
|
47
|
+
|
48
|
+
If your application responses are larger than the socket buffer or if
|
49
|
+
you're handling large requests (uploads), worker processes will also be
|
50
|
+
bottlenecked by the speed of the *client* connection. You should
|
51
|
+
not allow Unicorn to serve clients outside of your local network.
|
52
|
+
|
53
|
+
== Application Concurrency != Network Concurrency
|
54
|
+
|
55
|
+
Performance is asymmetric across the different subsystems of the machine
|
56
|
+
and parts of the network. CPUs and main memory can process gigabytes of
|
57
|
+
data in a second; clients on the Internet are usually only capable of a
|
58
|
+
tiny fraction of that. Unicorn deployments should avoid dealing with
|
59
|
+
slow clients directly and instead rely on a reverse proxy to shield it
|
60
|
+
from the effects of slow I/O.
|
61
|
+
|
62
|
+
== Improved Performance Through Reverse Proxying
|
63
|
+
|
64
|
+
By acting as a buffer to shield Unicorn from slow I/O, a reverse proxy
|
65
|
+
will inevitably incur overhead in the form of extra data copies.
|
66
|
+
However, as I/O within a local network is fast (and faster still
|
67
|
+
with local sockets), this overhead is neglible for the vast majority
|
68
|
+
of HTTP requests and responses.
|
69
|
+
|
70
|
+
The ideal reverse proxy complements the weaknesses of Unicorn.
|
71
|
+
A reverse proxy for Unicorn should meet the following requirements:
|
72
|
+
|
73
|
+
1. It should fully buffer all HTTP requests (and large responses).
|
74
|
+
Each request should be "corked" in the reverse proxy and sent
|
75
|
+
as fast as possible to the backend Unicorn processes. This is
|
76
|
+
the most important feature to look for when choosing a
|
77
|
+
reverse proxy for Unicorn.
|
78
|
+
|
79
|
+
2. It should spend minimal time in userspace. Network (and disk) I/O
|
80
|
+
are system-level tasks and usually managed by the kernel.
|
81
|
+
This may change if userspace TCP stacks become more popular in the
|
82
|
+
future; but the reverse proxy should not waste time with
|
83
|
+
application-level logic. These concerns should be separated
|
84
|
+
|
85
|
+
3. It should avoid context switches and CPU scheduling overhead.
|
86
|
+
In many (most?) cases, network devices and their interrupts are
|
87
|
+
only be handled by one CPU at a time. It should avoid contention
|
88
|
+
within the system by serializing all network I/O into one (or few)
|
89
|
+
userspace procceses. Network I/O is not a CPU-intensive task and
|
90
|
+
it is not helpful to use multiple CPU cores (at least not for GigE).
|
91
|
+
|
92
|
+
4. It should efficiently manage persistent connections (and
|
93
|
+
pipelining) to slow clients. If you care to serve slow clients
|
94
|
+
outside your network, then these features of HTTP/1.1 will help.
|
95
|
+
|
96
|
+
5. It should (optionally) serve static files. If you have static
|
97
|
+
files on your site (especially large ones), they are far more
|
98
|
+
efficiently served with as few data copies as possible (e.g. with
|
99
|
+
sendfile() to completely avoid copying the data to userspace).
|
100
|
+
|
101
|
+
nginx is the only (Free) solution we know of that meets the above
|
102
|
+
requirements.
|
103
|
+
|
104
|
+
Indeed, the folks behind Unicorn have deployed nginx as a reverse-proxy not
|
105
|
+
only for Ruby applications, but also for production applications running
|
106
|
+
Apache/mod_perl, Apache/mod_php and Apache Tomcat. In every single
|
107
|
+
case, performance improved because application servers were able to use
|
108
|
+
backend resources more efficiently and spend less time waiting on slow
|
109
|
+
I/O.
|
110
|
+
|
111
|
+
== Worse Is Better
|
112
|
+
|
113
|
+
Requirements and scope for applications change frequently and
|
114
|
+
drastically. Thus languages like Ruby and frameworks like Rails were
|
115
|
+
built to give developers fewer things to worry about in the face of
|
116
|
+
rapid change.
|
117
|
+
|
118
|
+
On the other hand, stable protocols which host your applications (HTTP
|
119
|
+
and TCP) only change rarely. This is why we recommend you NOT tie your
|
120
|
+
rapidly-changing application logic directly into the processes that deal
|
121
|
+
with the stable outside world. Instead, use HTTP as a common RPC
|
122
|
+
protocol to communicate between your frontend and backend.
|
123
|
+
|
124
|
+
In short: separate your concerns.
|
125
|
+
|
126
|
+
Of course a theoretical "perfect" solution would combine the pieces
|
127
|
+
and _maybe_ give you better performance at the end of the day, but
|
128
|
+
that is not the Unix way.
|
129
|
+
|
130
|
+
== Just Worse in Some Cases
|
131
|
+
|
132
|
+
Unicorn is not suited for all applications. Unicorn is optimized for
|
133
|
+
applications that are CPU/memory/disk intensive and spend little time
|
134
|
+
waiting on external resources (e.g. a database server or external API).
|
135
|
+
|
136
|
+
Unicorn is highly inefficient for Comet/reverse-HTTP/push applications
|
137
|
+
where the HTTP connection spends a large amount of time idle.
|
138
|
+
Nevertheless, the ease of troubleshooting, debugging, and management of
|
139
|
+
Unicorn may still outweigh the drawbacks for these applications.
|
140
|
+
|
141
|
+
The {Rainbows!}[http://rainbows.rubyforge.org/] aims to fill the gap for
|
142
|
+
odd corner cases where the nginx + Unicorn combination is not enough.
|
143
|
+
While Rainbows! management/administration is largely identical to
|
144
|
+
Unicorn, Rainbows! is far more ambitious and has seen little real-world
|
145
|
+
usage.
|
data/README
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
= Unicorn: Rack HTTP server for fast clients and Unix
|
2
|
+
|
3
|
+
\Unicorn is an HTTP server for Rack applications designed to only serve
|
4
|
+
fast clients on low-latency, high-bandwidth connections and take
|
5
|
+
advantage of features in Unix/Unix-like kernels. Slow clients should
|
6
|
+
only be served by placing a reverse proxy capable of fully buffering
|
7
|
+
both the the request and response in between Unicorn and slow clients.
|
8
|
+
|
9
|
+
== Features
|
10
|
+
|
11
|
+
* Designed for Rack, Unix, fast clients, and ease-of-debugging. We
|
12
|
+
cut out everything that is better supported by the operating system,
|
13
|
+
{nginx}[http://nginx.net/] or {Rack}[http://rack.rubyforge.org/].
|
14
|
+
|
15
|
+
* Compatible with both Ruby 1.8 and 1.9. Rubinius support is in-progress.
|
16
|
+
|
17
|
+
* Process management: \Unicorn will reap and restart workers that
|
18
|
+
die from broken apps. There is no need to manage multiple processes
|
19
|
+
or ports yourself. \Unicorn can spawn and manage any number of
|
20
|
+
worker processes you choose to scale to your backend.
|
21
|
+
|
22
|
+
* Load balancing is done entirely by the operating system kernel.
|
23
|
+
Requests never pile up behind a busy worker process.
|
24
|
+
|
25
|
+
* Does not care if your application is thread-safe or not, workers
|
26
|
+
all run within their own isolated address space and only serve one
|
27
|
+
client at a time for maximum robustness.
|
28
|
+
|
29
|
+
* Supports all Rack applications, along with pre-Rack versions of
|
30
|
+
Ruby on Rails via a Rack wrapper.
|
31
|
+
|
32
|
+
* Builtin reopening of all log files in your application via
|
33
|
+
USR1 signal. This allows logrotate to rotate files atomically and
|
34
|
+
quickly via rename instead of the racy and slow copytruncate method.
|
35
|
+
\Unicorn also takes steps to ensure multi-line log entries from one
|
36
|
+
request all stay within the same file.
|
37
|
+
|
38
|
+
* nginx-style binary upgrades without losing connections.
|
39
|
+
You can upgrade \Unicorn, your entire application, libraries
|
40
|
+
and even your Ruby interpreter without dropping clients.
|
41
|
+
|
42
|
+
* before_fork and after_fork hooks in case your application
|
43
|
+
has special needs when dealing with forked processes. These
|
44
|
+
should not be needed when the "preload_app" directive is
|
45
|
+
false (the default).
|
46
|
+
|
47
|
+
* Can be used with copy-on-write-friendly memory management
|
48
|
+
to save memory (by setting "preload_app" to true).
|
49
|
+
|
50
|
+
* Able to listen on multiple interfaces including UNIX sockets,
|
51
|
+
each worker process can also bind to a private port via the
|
52
|
+
after_fork hook for easy debugging.
|
53
|
+
|
54
|
+
* Simple and easy Ruby DSL for configuration.
|
55
|
+
|
56
|
+
* Decodes chunked transfers on-the-fly, thus allowing upload progress
|
57
|
+
notification to be implemented as well as being able to tunnel
|
58
|
+
arbitrary stream-based protocols over HTTP.
|
59
|
+
|
60
|
+
== License
|
61
|
+
|
62
|
+
\Unicorn is copyright 2009 by all contributors (see logs in git).
|
63
|
+
It is based on Mongrel and carries the same license.
|
64
|
+
|
65
|
+
Mongrel is copyright 2007 Zed A. Shaw and contributors. It is licensed
|
66
|
+
under the Ruby license and the GPL2. See the included LICENSE file for
|
67
|
+
details.
|
68
|
+
|
69
|
+
\Unicorn is 100% Free Software.
|
70
|
+
|
71
|
+
== Install
|
72
|
+
|
73
|
+
The library consists of a C extension so you'll need a C compiler
|
74
|
+
and Ruby development libraries/headers.
|
75
|
+
|
76
|
+
You may download the tarball from the Mongrel project page on Rubyforge
|
77
|
+
and run setup.rb after unpacking it:
|
78
|
+
|
79
|
+
http://rubyforge.org/frs/?group_id=1306
|
80
|
+
|
81
|
+
You may also install it via RubyGems on Gemcutter:
|
82
|
+
|
83
|
+
gem install unicorn
|
84
|
+
|
85
|
+
You can get the latest source via git from the following locations
|
86
|
+
(these versions may not be stable):
|
87
|
+
|
88
|
+
git://git.bogomips.org/unicorn.git
|
89
|
+
git://repo.or.cz/unicorn.git (mirror)
|
90
|
+
|
91
|
+
You may browse the code from the web and download the latest snapshot
|
92
|
+
tarballs here:
|
93
|
+
|
94
|
+
* http://git.bogomips.org/cgit/unicorn.git (cgit)
|
95
|
+
* http://repo.or.cz/w/unicorn.git (gitweb)
|
96
|
+
|
97
|
+
See the HACKING guide on how to contribute and build prerelease gems
|
98
|
+
from git.
|
99
|
+
|
100
|
+
== Usage
|
101
|
+
|
102
|
+
=== non-Rails Rack applications
|
103
|
+
|
104
|
+
In APP_ROOT, run:
|
105
|
+
|
106
|
+
unicorn
|
107
|
+
|
108
|
+
=== for Rails applications (should work for all 1.2 or later versions)
|
109
|
+
|
110
|
+
In RAILS_ROOT, run:
|
111
|
+
|
112
|
+
unicorn_rails
|
113
|
+
|
114
|
+
\Unicorn will bind to all interfaces on TCP port 8080 by default.
|
115
|
+
You may use the +--listen/-l+ switch to bind to a different
|
116
|
+
address:port or a UNIX socket.
|
117
|
+
|
118
|
+
=== Configuration File(s)
|
119
|
+
|
120
|
+
\Unicorn will look for the config.ru file used by rackup in APP_ROOT.
|
121
|
+
|
122
|
+
For deployments, it can use a config file for \Unicorn-specific options
|
123
|
+
specified by the +--config-file/-c+ command-line switch. See
|
124
|
+
Unicorn::Configurator for the syntax of the \Unicorn-specific options.
|
125
|
+
The default settings are designed for maximum out-of-the-box
|
126
|
+
compatibility with existing applications.
|
127
|
+
|
128
|
+
Most command-line options for other Rack applications (above) are also
|
129
|
+
supported. Run `unicorn -h` or `unicorn_rails -h` to see command-line
|
130
|
+
options.
|
131
|
+
|
132
|
+
== Disclaimer
|
133
|
+
|
134
|
+
There is NO WARRANTY whatsoever if anything goes wrong, but
|
135
|
+
{let us know}[link:ISSUES.html] and we'll try our best to fix it.
|
136
|
+
|
137
|
+
\Unicorn is designed to only serve fast clients either on the local host
|
138
|
+
or a fast LAN. See the PHILOSOPHY and DESIGN documents for more details
|
139
|
+
regarding this.
|
140
|
+
|
141
|
+
== Contact
|
142
|
+
|
143
|
+
All feedback (bug reports, user/development dicussion, patches, pull
|
144
|
+
requests) go to the mailing list/newsgroup. See the ISSUES document for
|
145
|
+
information on the {mailing list}[mailto:mongrel-unicorn@rubyforge.org].
|
146
|
+
|
147
|
+
For the latest on \Unicorn releases, you may also finger us at
|
148
|
+
unicorn@bogomips.org or check our NEWS page (and subscribe to our Atom
|
149
|
+
feed).
|
data/Rakefile
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
autoload :Gem, 'rubygems'
|
3
|
+
|
4
|
+
# most tasks are in the GNUmakefile which offers better parallelism
|
5
|
+
|
6
|
+
def old_summaries
|
7
|
+
@old_summaries ||= File.readlines(".CHANGELOG.old").inject({}) do |hash, line|
|
8
|
+
version, summary = line.split(/ - /, 2)
|
9
|
+
hash[version] = summary
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def tags
|
15
|
+
timefmt = '%Y-%m-%dT%H:%M:%SZ'
|
16
|
+
@tags ||= `git tag -l`.split(/\n/).map do |tag|
|
17
|
+
next if tag == "v0.0.0"
|
18
|
+
if %r{\Av[\d\.]+\z} =~ tag
|
19
|
+
header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
|
20
|
+
header = header.split(/\n/)
|
21
|
+
tagger = header.grep(/\Atagger /).first
|
22
|
+
body ||= "initial"
|
23
|
+
{
|
24
|
+
:time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
|
25
|
+
:tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
|
26
|
+
:tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
|
27
|
+
:id => `git rev-parse refs/tags/#{tag}`.chomp!,
|
28
|
+
:tag => tag,
|
29
|
+
:subject => subject,
|
30
|
+
:body => (old = old_summaries[tag]) ? "#{old}\n#{body}" : body,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end.compact.sort { |a,b| b[:time] <=> a[:time] }
|
34
|
+
end
|
35
|
+
|
36
|
+
cgit_url = "http://git.bogomips.org/cgit/unicorn.git"
|
37
|
+
git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/unicorn.git'
|
38
|
+
|
39
|
+
desc 'prints news as an Atom feed'
|
40
|
+
task :news_atom do
|
41
|
+
require 'nokogiri'
|
42
|
+
new_tags = tags[0,10]
|
43
|
+
puts(Nokogiri::XML::Builder.new do
|
44
|
+
feed :xmlns => "http://www.w3.org/2005/Atom" do
|
45
|
+
id! "http://unicorn.bogomips.org/NEWS.atom.xml"
|
46
|
+
title "Unicorn news"
|
47
|
+
subtitle "Rack HTTP server for Unix and fast clients"
|
48
|
+
link! :rel => 'alternate', :type => 'text/html',
|
49
|
+
:href => 'http://unicorn.bogomips.org/NEWS.html'
|
50
|
+
updated new_tags.first[:time]
|
51
|
+
new_tags.each do |tag|
|
52
|
+
entry do
|
53
|
+
title tag[:subject]
|
54
|
+
updated tag[:time]
|
55
|
+
published tag[:time]
|
56
|
+
author {
|
57
|
+
name tag[:tagger_name]
|
58
|
+
email tag[:tagger_email]
|
59
|
+
}
|
60
|
+
url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
|
61
|
+
link! :rel => "alternate", :type => "text/html", :href =>url
|
62
|
+
id! url
|
63
|
+
message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/s).first.strip
|
64
|
+
content({:type =>:text}, message_only)
|
65
|
+
content(:type =>:xhtml) { pre tag[:body] }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end.to_xml)
|
70
|
+
end
|
71
|
+
|
72
|
+
desc 'prints RDoc-formatted news'
|
73
|
+
task :news_rdoc do
|
74
|
+
tags.each do |tag|
|
75
|
+
time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
|
76
|
+
puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
|
77
|
+
puts ""
|
78
|
+
|
79
|
+
body = tag[:body]
|
80
|
+
puts tag[:body].gsub(/^/sm, " ").gsub(/[ \t]+$/sm, "")
|
81
|
+
puts ""
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
desc "print release changelog for Rubyforge"
|
86
|
+
task :release_changes do
|
87
|
+
version = ENV['VERSION'] or abort "VERSION= needed"
|
88
|
+
version = "v#{version}"
|
89
|
+
vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
|
90
|
+
prev = vtags[vtags.index(version) - 1]
|
91
|
+
system('git', 'diff', '--stat', prev, version) or abort $?
|
92
|
+
puts ""
|
93
|
+
system('git', 'log', "#{prev}..#{version}") or abort $?
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "print release notes for Rubyforge"
|
97
|
+
task :release_notes do
|
98
|
+
spec = Gem::Specification.load('unicorn.gemspec')
|
99
|
+
puts spec.description.strip
|
100
|
+
puts ""
|
101
|
+
puts "* #{spec.homepage}"
|
102
|
+
puts "* #{spec.email}"
|
103
|
+
puts "* #{git_url}"
|
104
|
+
|
105
|
+
_, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
|
106
|
+
print "\nChanges:\n\n"
|
107
|
+
puts body
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "post to RAA"
|
111
|
+
task :raa_update do
|
112
|
+
require 'net/http'
|
113
|
+
require 'net/netrc'
|
114
|
+
rc = Net::Netrc.locate('unicorn-raa') or abort "~/.netrc not found"
|
115
|
+
password = rc.password
|
116
|
+
|
117
|
+
s = Gem::Specification.load('unicorn.gemspec')
|
118
|
+
desc = [ s.description.strip ]
|
119
|
+
desc << ""
|
120
|
+
desc << "* #{s.email}"
|
121
|
+
desc << "* #{git_url}"
|
122
|
+
desc << "* #{cgit_url}"
|
123
|
+
desc = desc.join("\n")
|
124
|
+
uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
|
125
|
+
form = {
|
126
|
+
:name => s.name,
|
127
|
+
:short_description => s.summary,
|
128
|
+
:version => s.version.to_s,
|
129
|
+
:status => 'stable',
|
130
|
+
:owner => s.authors.first,
|
131
|
+
:email => s.email,
|
132
|
+
:category_major => 'Library',
|
133
|
+
:category_minor => 'Web',
|
134
|
+
:url => s.homepage,
|
135
|
+
:download => "http://rubyforge.org/frs/?group_id=1306",
|
136
|
+
:license => "Ruby's",
|
137
|
+
:description_style => 'Plain',
|
138
|
+
:description => desc,
|
139
|
+
:pass => password,
|
140
|
+
:submit => "Update",
|
141
|
+
}
|
142
|
+
res = Net::HTTP.post_form(uri, form)
|
143
|
+
p res
|
144
|
+
puts res.body
|
145
|
+
end
|
146
|
+
|
147
|
+
desc "post to FM"
|
148
|
+
task :fm_update do
|
149
|
+
require 'tempfile'
|
150
|
+
require 'net/http'
|
151
|
+
require 'net/netrc'
|
152
|
+
require 'json'
|
153
|
+
version = ENV['VERSION'] or abort "VERSION= needed"
|
154
|
+
uri = URI.parse('http://freshmeat.net/projects/unicorn/releases.json')
|
155
|
+
rc = Net::Netrc.locate('unicorn-fm') or abort "~/.netrc not found"
|
156
|
+
api_token = rc.password
|
157
|
+
changelog = tags.find { |t| t[:tag] == "v#{version}" }[:body]
|
158
|
+
tmp = Tempfile.new('fm-changelog')
|
159
|
+
tmp.syswrite(changelog)
|
160
|
+
system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
|
161
|
+
changelog = File.read(tmp.path).strip
|
162
|
+
|
163
|
+
req = {
|
164
|
+
"auth_code" => api_token,
|
165
|
+
"release" => {
|
166
|
+
"tag_list" => "Stable",
|
167
|
+
"version" => version,
|
168
|
+
"changelog" => changelog,
|
169
|
+
},
|
170
|
+
}.to_json
|
171
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
172
|
+
p http.post(uri.path, req, {'Content-Type'=>'application/json'})
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# optional rake-compiler support in case somebody needs to cross compile
|
177
|
+
begin
|
178
|
+
mk = "ext/unicorn_http/Makefile"
|
179
|
+
if test ?r, mk
|
180
|
+
warn "run 'gmake -C ext/unicorn_http clean' and\n" \
|
181
|
+
"remove #{mk} before using rake-compiler"
|
182
|
+
else
|
183
|
+
unless test ?r, "ext/unicorn_http/unicorn_http.c"
|
184
|
+
abort "run 'gmake ragel' or 'make ragel' to generate the Ragel source"
|
185
|
+
end
|
186
|
+
spec = Gem::Specification.load('unicorn.gemspec')
|
187
|
+
require 'rake/extensiontask'
|
188
|
+
Rake::ExtensionTask.new('unicorn_http', spec)
|
189
|
+
end
|
190
|
+
rescue LoadError
|
191
|
+
end
|