unicorn-heroku-wait 4.8.0.1.g0ed2.dirty

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +7 -0
  2. data/.CHANGELOG.old +25 -0
  3. data/.document +29 -0
  4. data/.gitignore +25 -0
  5. data/.mailmap +26 -0
  6. data/.manifest +166 -0
  7. data/.wrongdoc.yml +10 -0
  8. data/Application_Timeouts +77 -0
  9. data/CONTRIBUTORS +35 -0
  10. data/COPYING +674 -0
  11. data/ChangeLog +4861 -0
  12. data/DESIGN +97 -0
  13. data/Documentation/.gitignore +5 -0
  14. data/Documentation/GNUmakefile +30 -0
  15. data/Documentation/unicorn.1.txt +178 -0
  16. data/Documentation/unicorn_rails.1.txt +175 -0
  17. data/FAQ +53 -0
  18. data/GIT-VERSION-FILE +1 -0
  19. data/GIT-VERSION-GEN +39 -0
  20. data/GNUmakefile +267 -0
  21. data/HACKING +134 -0
  22. data/ISSUES +36 -0
  23. data/KNOWN_ISSUES +79 -0
  24. data/LATEST +28 -0
  25. data/LICENSE +67 -0
  26. data/Links +56 -0
  27. data/NEWS +2067 -0
  28. data/PHILOSOPHY +145 -0
  29. data/README +150 -0
  30. data/Rakefile +60 -0
  31. data/SIGNALS +123 -0
  32. data/Sandbox +103 -0
  33. data/TODO +5 -0
  34. data/TUNING +98 -0
  35. data/bin/unicorn +126 -0
  36. data/bin/unicorn_rails +209 -0
  37. data/examples/big_app_gc.rb +2 -0
  38. data/examples/echo.ru +27 -0
  39. data/examples/git.ru +13 -0
  40. data/examples/init.sh +74 -0
  41. data/examples/logger_mp_safe.rb +25 -0
  42. data/examples/logrotate.conf +29 -0
  43. data/examples/nginx.conf +156 -0
  44. data/examples/unicorn.conf.minimal.rb +13 -0
  45. data/examples/unicorn.conf.rb +102 -0
  46. data/ext/unicorn_http/CFLAGS +13 -0
  47. data/ext/unicorn_http/c_util.h +124 -0
  48. data/ext/unicorn_http/common_field_optimization.h +111 -0
  49. data/ext/unicorn_http/ext_help.h +82 -0
  50. data/ext/unicorn_http/extconf.rb +10 -0
  51. data/ext/unicorn_http/global_variables.h +97 -0
  52. data/ext/unicorn_http/httpdate.c +78 -0
  53. data/ext/unicorn_http/unicorn_http.c +4031 -0
  54. data/ext/unicorn_http/unicorn_http.rl +1036 -0
  55. data/ext/unicorn_http/unicorn_http_common.rl +76 -0
  56. data/lib/unicorn/app/exec_cgi.rb +154 -0
  57. data/lib/unicorn/app/inetd.rb +109 -0
  58. data/lib/unicorn/app/old_rails/static.rb +59 -0
  59. data/lib/unicorn/app/old_rails.rb +35 -0
  60. data/lib/unicorn/cgi_wrapper.rb +147 -0
  61. data/lib/unicorn/configurator.rb +679 -0
  62. data/lib/unicorn/const.rb +44 -0
  63. data/lib/unicorn/http_request.rb +122 -0
  64. data/lib/unicorn/http_response.rb +75 -0
  65. data/lib/unicorn/http_server.rb +803 -0
  66. data/lib/unicorn/launcher.rb +62 -0
  67. data/lib/unicorn/oob_gc.rb +71 -0
  68. data/lib/unicorn/preread_input.rb +33 -0
  69. data/lib/unicorn/socket_helper.rb +231 -0
  70. data/lib/unicorn/ssl_client.rb +11 -0
  71. data/lib/unicorn/ssl_configurator.rb +104 -0
  72. data/lib/unicorn/ssl_server.rb +42 -0
  73. data/lib/unicorn/stream_input.rb +146 -0
  74. data/lib/unicorn/tee_input.rb +126 -0
  75. data/lib/unicorn/tmpio.rb +29 -0
  76. data/lib/unicorn/util.rb +89 -0
  77. data/lib/unicorn/version.rb +1 -0
  78. data/lib/unicorn/worker.rb +152 -0
  79. data/lib/unicorn.rb +118 -0
  80. data/local.mk.sample +59 -0
  81. data/man/man1/unicorn.1 +211 -0
  82. data/man/man1/unicorn_rails.1 +210 -0
  83. data/script/isolate_for_tests +32 -0
  84. data/setup.rb +1586 -0
  85. data/t/.gitignore +5 -0
  86. data/t/GNUmakefile +82 -0
  87. data/t/README +42 -0
  88. data/t/bin/content-md5-put +36 -0
  89. data/t/bin/sha1sum.rb +17 -0
  90. data/t/bin/unused_listen +40 -0
  91. data/t/broken-app.ru +12 -0
  92. data/t/detach.ru +11 -0
  93. data/t/env.ru +3 -0
  94. data/t/fails-rack-lint.ru +5 -0
  95. data/t/heartbeat-timeout.ru +12 -0
  96. data/t/hijack.ru +42 -0
  97. data/t/listener_names.ru +4 -0
  98. data/t/my-tap-lib.sh +201 -0
  99. data/t/oob_gc.ru +20 -0
  100. data/t/oob_gc_path.ru +20 -0
  101. data/t/pid.ru +3 -0
  102. data/t/preread_input.ru +17 -0
  103. data/t/rack-input-tests.ru +21 -0
  104. data/t/sslgen.sh +71 -0
  105. data/t/t0000-http-basic.sh +50 -0
  106. data/t/t0001-reload-bad-config.sh +53 -0
  107. data/t/t0002-config-conflict.sh +49 -0
  108. data/t/t0002-parser-error.sh +94 -0
  109. data/t/t0003-working_directory.sh +51 -0
  110. data/t/t0004-heartbeat-timeout.sh +69 -0
  111. data/t/t0004-working_directory_broken.sh +24 -0
  112. data/t/t0005-working_directory_app.rb.sh +40 -0
  113. data/t/t0006-reopen-logs.sh +83 -0
  114. data/t/t0006.ru +13 -0
  115. data/t/t0007-working_directory_no_embed_cli.sh +44 -0
  116. data/t/t0008-back_out_of_upgrade.sh +110 -0
  117. data/t/t0009-broken-app.sh +56 -0
  118. data/t/t0009-winch_ttin.sh +59 -0
  119. data/t/t0010-reap-logging.sh +55 -0
  120. data/t/t0011-active-unix-socket.sh +79 -0
  121. data/t/t0012-reload-empty-config.sh +85 -0
  122. data/t/t0013-rewindable-input-false.sh +24 -0
  123. data/t/t0013.ru +12 -0
  124. data/t/t0014-rewindable-input-true.sh +24 -0
  125. data/t/t0014.ru +12 -0
  126. data/t/t0015-configurator-internals.sh +25 -0
  127. data/t/t0016-trust-x-forwarded-false.sh +30 -0
  128. data/t/t0017-trust-x-forwarded-true.sh +30 -0
  129. data/t/t0018-write-on-close.sh +23 -0
  130. data/t/t0019-max_header_len.sh +49 -0
  131. data/t/t0020-at_exit-handler.sh +49 -0
  132. data/t/t0021-process_detach.sh +29 -0
  133. data/t/t0022-listener_names-preload_app.sh +32 -0
  134. data/t/t0100-rack-input-tests.sh +124 -0
  135. data/t/t0116-client_body_buffer_size.sh +80 -0
  136. data/t/t0116.ru +16 -0
  137. data/t/t0200-rack-hijack.sh +27 -0
  138. data/t/t0300-no-default-middleware.sh +20 -0
  139. data/t/t0600-https-server-basic.sh +48 -0
  140. data/t/t9000-preread-input.sh +48 -0
  141. data/t/t9001-oob_gc.sh +47 -0
  142. data/t/t9002-oob_gc-path.sh +75 -0
  143. data/t/test-lib.sh +128 -0
  144. data/t/write-on-close.ru +11 -0
  145. data/test/aggregate.rb +15 -0
  146. data/test/benchmark/README +50 -0
  147. data/test/benchmark/dd.ru +18 -0
  148. data/test/benchmark/stack.ru +8 -0
  149. data/test/exec/README +5 -0
  150. data/test/exec/test_exec.rb +1047 -0
  151. data/test/test_helper.rb +297 -0
  152. data/test/unit/test_configurator.rb +175 -0
  153. data/test/unit/test_droplet.rb +28 -0
  154. data/test/unit/test_http_parser.rb +854 -0
  155. data/test/unit/test_http_parser_ng.rb +731 -0
  156. data/test/unit/test_http_parser_xftrust.rb +38 -0
  157. data/test/unit/test_request.rb +182 -0
  158. data/test/unit/test_response.rb +99 -0
  159. data/test/unit/test_server.rb +268 -0
  160. data/test/unit/test_signals.rb +188 -0
  161. data/test/unit/test_sni_hostnames.rb +47 -0
  162. data/test/unit/test_socket_helper.rb +197 -0
  163. data/test/unit/test_stream_input.rb +203 -0
  164. data/test/unit/test_tee_input.rb +294 -0
  165. data/test/unit/test_upload.rb +306 -0
  166. data/test/unit/test_util.rb +105 -0
  167. data/unicorn.gemspec +44 -0
  168. metadata +328 -0
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 negligible 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 processes. 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,150 @@
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 1.1.5.
64
+ Mongrel is copyright 2007 Zed A. Shaw and contributors.
65
+
66
+ \Unicorn is licensed under (your choice) of the GPLv2 or later
67
+ (GPLv3+ preferred), or Ruby (1.8)-specific terms.
68
+ See the included LICENSE file for details.
69
+
70
+ \Unicorn is 100% Free Software.
71
+
72
+ == Install
73
+
74
+ The library consists of a C extension so you'll need a C compiler
75
+ and Ruby development libraries/headers.
76
+
77
+ You may download the tarball from the Mongrel project page on Rubyforge
78
+ and run setup.rb after unpacking it:
79
+
80
+ http://rubyforge.org/frs/?group_id=1306
81
+
82
+ You may also install it via RubyGems on RubyGems.org:
83
+
84
+ gem install unicorn
85
+
86
+ You can get the latest source via git from the following locations
87
+ (these versions may not be stable):
88
+
89
+ git://bogomips.org/unicorn.git
90
+ git://repo.or.cz/unicorn.git (mirror)
91
+
92
+ You may browse the code from the web and download the latest snapshot
93
+ tarballs here:
94
+
95
+ * http://bogomips.org/unicorn.git (cgit)
96
+ * http://repo.or.cz/w/unicorn.git (gitweb)
97
+
98
+ See the HACKING guide on how to contribute and build prerelease gems
99
+ from git.
100
+
101
+ == Usage
102
+
103
+ === non-Rails Rack applications
104
+
105
+ In APP_ROOT, run:
106
+
107
+ unicorn
108
+
109
+ === for Rails applications (should work for all 1.2 or later versions)
110
+
111
+ In RAILS_ROOT, run:
112
+
113
+ unicorn_rails
114
+
115
+ \Unicorn will bind to all interfaces on TCP port 8080 by default.
116
+ You may use the +--listen/-l+ switch to bind to a different
117
+ address:port or a UNIX socket.
118
+
119
+ === Configuration File(s)
120
+
121
+ \Unicorn will look for the config.ru file used by rackup in APP_ROOT.
122
+
123
+ For deployments, it can use a config file for \Unicorn-specific options
124
+ specified by the +--config-file/-c+ command-line switch. See
125
+ Unicorn::Configurator for the syntax of the \Unicorn-specific options.
126
+ The default settings are designed for maximum out-of-the-box
127
+ compatibility with existing applications.
128
+
129
+ Most command-line options for other Rack applications (above) are also
130
+ supported. Run `unicorn -h` or `unicorn_rails -h` to see command-line
131
+ options.
132
+
133
+ == Disclaimer
134
+
135
+ There is NO WARRANTY whatsoever if anything goes wrong, but
136
+ {let us know}[link:ISSUES.html] and we'll try our best to fix it.
137
+
138
+ \Unicorn is designed to only serve fast clients either on the local host
139
+ or a fast LAN. See the PHILOSOPHY and DESIGN documents for more details
140
+ regarding this.
141
+
142
+ == Contact
143
+
144
+ All feedback (bug reports, user/development dicussion, patches, pull
145
+ requests) go to the mailing list/newsgroup. See the ISSUES document for
146
+ information on the {mailing list}[mailto:mongrel-unicorn@rubyforge.org].
147
+
148
+ For the latest on \Unicorn releases, you may also finger us at
149
+ unicorn@bogomips.org or check our NEWS page (and subscribe to our Atom
150
+ feed).
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ # -*- encoding: binary -*-
2
+ autoload :Gem, 'rubygems'
3
+ require 'wrongdoc'
4
+
5
+ cgit_url = Wrongdoc.config[:cgit_url]
6
+ git_url = Wrongdoc.config[:git_url]
7
+
8
+ desc "post to FM"
9
+ task :fm_update do
10
+ require 'tempfile'
11
+ require 'net/http'
12
+ require 'net/netrc'
13
+ require 'json'
14
+ version = ENV['VERSION'] or abort "VERSION= needed"
15
+ uri = URI.parse('https://freecode.com/projects/unicorn/releases.json')
16
+ rc = Net::Netrc.locate('unicorn-fm') or abort "~/.netrc not found"
17
+ api_token = rc.password
18
+ _, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
19
+ tmp = Tempfile.new('fm-changelog')
20
+ tmp.puts subject
21
+ tmp.puts
22
+ tmp.puts body
23
+ tmp.flush
24
+ system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
25
+ changelog = File.read(tmp.path).strip
26
+
27
+ req = {
28
+ "auth_code" => api_token,
29
+ "release" => {
30
+ "tag_list" => "Experimental",
31
+ "version" => version,
32
+ "changelog" => changelog,
33
+ },
34
+ }.to_json
35
+
36
+ if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
37
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
38
+ p http.post(uri.path, req, {'Content-Type'=>'application/json'})
39
+ end
40
+ else
41
+ warn "not updating freshmeat for v#{version}"
42
+ end
43
+ end
44
+
45
+ # optional rake-compiler support in case somebody needs to cross compile
46
+ begin
47
+ mk = "ext/unicorn_http/Makefile"
48
+ if File.readable?(mk)
49
+ warn "run 'gmake -C ext/unicorn_http clean' and\n" \
50
+ "remove #{mk} before using rake-compiler"
51
+ elsif ENV['VERSION']
52
+ unless File.readable?("ext/unicorn_http/unicorn_http.c")
53
+ abort "run 'gmake ragel' or 'make ragel' to generate the Ragel source"
54
+ end
55
+ spec = Gem::Specification.load('unicorn.gemspec')
56
+ require 'rake/extensiontask'
57
+ Rake::ExtensionTask.new('unicorn_http', spec)
58
+ end
59
+ rescue LoadError
60
+ end
data/SIGNALS ADDED
@@ -0,0 +1,123 @@
1
+ == Signal handling
2
+
3
+ In general, signals need only be sent to the master process. However,
4
+ the signals Unicorn uses internally to communicate with the worker
5
+ processes are documented here as well. With the exception of TTIN/TTOU,
6
+ signal handling matches the behavior of {nginx}[http://nginx.net/] so it
7
+ should be possible to easily share process management scripts between
8
+ Unicorn and nginx.
9
+
10
+ One example init script is distributed with unicorn:
11
+ http://unicorn.bogomips.org/examples/init.sh
12
+
13
+ === Master Process
14
+
15
+ * HUP - reloads config file and gracefully restart all workers.
16
+ If the "preload_app" directive is false (the default), then workers
17
+ will also pick up any application code changes when restarted. If
18
+ "preload_app" is true, then application code changes will have no
19
+ effect; USR2 + QUIT (see below) must be used to load newer code in
20
+ this case. When reloading the application, +Gem.refresh+ will
21
+ be called so updated code for your application can pick up newly
22
+ installed RubyGems. It is not recommended that you uninstall
23
+ libraries your application depends on while Unicorn is running,
24
+ as respawned workers may enter a spawn loop when they fail to
25
+ load an uninstalled dependency.
26
+
27
+ * INT/TERM - quick shutdown, kills all workers immediately
28
+
29
+ * QUIT - graceful shutdown, waits for workers to finish their
30
+ current request before finishing.
31
+
32
+ * USR1 - reopen all logs owned by the master and all workers
33
+ See Unicorn::Util.reopen_logs for what is considered a log.
34
+
35
+ * USR2 - reexecute the running binary. A separate QUIT
36
+ should be sent to the original process once the child is verified to
37
+ be up and running.
38
+
39
+ * WINCH - gracefully stops workers but keep the master running.
40
+ This will only work for daemonized processes.
41
+
42
+ * TTIN - increment the number of worker processes by one
43
+
44
+ * TTOU - decrement the number of worker processes by one
45
+
46
+ === Worker Processes
47
+
48
+ Note: as of unicorn 4.8, the master uses a pipe to signal workers
49
+ instead of kill(2) for most cases. Using signals still (and works and
50
+ remains supported for external tools/libraries), however.
51
+
52
+ Sending signals directly to the worker processes should not normally be
53
+ needed. If the master process is running, any exited worker will be
54
+ automatically respawned.
55
+
56
+ * INT/TERM - Quick shutdown, immediately exit.
57
+ Unless WINCH has been sent to the master (or the master is killed),
58
+ the master process will respawn a worker to replace this one.
59
+ Immediate shutdown is still triggered using kill(2) and not the
60
+ internal pipe as of unicorn 4.8
61
+
62
+ * QUIT - Gracefully exit after finishing the current request.
63
+ Unless WINCH has been sent to the master (or the master is killed),
64
+ the master process will respawn a worker to replace this one.
65
+
66
+ * USR1 - Reopen all logs owned by the worker process.
67
+ See Unicorn::Util.reopen_logs for what is considered a log.
68
+ Log files are not reopened until it is done processing
69
+ the current request, so multiple log lines for one request
70
+ (as done by Rails) will not be split across multiple logs.
71
+
72
+ It is NOT recommended to send the USR1 signal directly to workers via
73
+ "killall -USR1 unicorn" if you are using user/group-switching support
74
+ in your workers. You will encounter incorrect file permissions and
75
+ workers will need to be respawned. Sending USR1 to the master process
76
+ first will ensure logs have the correct permissions before the master
77
+ forwards the USR1 signal to workers.
78
+
79
+ === Procedure to replace a running unicorn executable
80
+
81
+ You may replace a running instance of unicorn with a new one without
82
+ losing any incoming connections. Doing so will reload all of your
83
+ application code, Unicorn config, Ruby executable, and all libraries.
84
+ The only things that will not change (due to OS limitations) are:
85
+
86
+ 1. The path to the unicorn executable script. If you want to change to
87
+ a different installation of Ruby, you can modify the shebang
88
+ line to point to your alternative interpreter.
89
+
90
+ The procedure is exactly like that of nginx:
91
+
92
+ 1. Send USR2 to the master process
93
+
94
+ 2. Check your process manager or pid files to see if a new master spawned
95
+ successfully. If you're using a pid file, the old process will have
96
+ ".oldbin" appended to its path. You should have two master instances
97
+ of unicorn running now, both of which will have workers servicing
98
+ requests. Your process tree should look something like this:
99
+
100
+ unicorn master (old)
101
+ \_ unicorn worker[0]
102
+ \_ unicorn worker[1]
103
+ \_ unicorn worker[2]
104
+ \_ unicorn worker[3]
105
+ \_ unicorn master
106
+ \_ unicorn worker[0]
107
+ \_ unicorn worker[1]
108
+ \_ unicorn worker[2]
109
+ \_ unicorn worker[3]
110
+
111
+ 3. You can now send WINCH to the old master process so only the new workers
112
+ serve requests. If your unicorn process is bound to an interactive
113
+ terminal (not daemonized), you can skip this step. Step 5 will be more
114
+ difficult but you can also skip it if your process is not daemonized.
115
+
116
+ 4. You should now ensure that everything is running correctly with the
117
+ new workers as the old workers die off.
118
+
119
+ 5. If everything seems ok, then send QUIT to the old master. You're done!
120
+
121
+ If something is broken, then send HUP to the old master to reload
122
+ the config and restart its workers. Then send QUIT to the new master
123
+ process.
data/Sandbox ADDED
@@ -0,0 +1,103 @@
1
+ = Tips for using \Unicorn with Sandbox installation tools
2
+
3
+ Since unicorn includes executables and is usually used to start a Ruby
4
+ process, there are certain caveats to using it with tools that sandbox
5
+ RubyGems installations such as
6
+ {Bundler}[http://gembundler.com/] or
7
+ {Isolate}[http://github.com/jbarnette/isolate].
8
+
9
+ == General deployment
10
+
11
+ If you're sandboxing your unicorn installation and using Capistrano (or
12
+ similar), it's required that you sandbox your RubyGems in a per-application
13
+ shared directory that can be used between different revisions.
14
+
15
+ unicorn will stash its original command-line at startup for the USR2
16
+ upgrades, and cleaning up old revisions will cause revision-specific
17
+ installations of unicorn to go missing and upgrades to fail. If you
18
+ find yourself in this situation and can't afford downtime, you can
19
+ override the existing unicorn executable path in the config file like
20
+ this:
21
+
22
+ Unicorn::HttpServer::START_CTX[0] = "/some/path/to/bin/unicorn"
23
+
24
+ Then use HUP to reload, and then continue with the USR2+QUIT upgrade
25
+ sequence.
26
+
27
+ Environment variable pollution when exec-ing a new process (with USR2)
28
+ is the primary issue with sandboxing tools such as Bundler and Isolate.
29
+
30
+ == Bundler
31
+
32
+ === Running
33
+
34
+ If you're bundling unicorn, use "bundle exec unicorn" (or "bundle exec
35
+ unicorn_rails") to start unicorn with the correct environment variables
36
+
37
+ ref: http://mid.gmane.org/9ECF07C4-5216-47BE-961D-AFC0F0C82060@internetfamo.us
38
+
39
+ Otherwise (if you choose to not sandbox your unicorn installation), we
40
+ expect the tips for Isolate (below) apply, too.
41
+
42
+ === RUBYOPT pollution from SIGUSR2 upgrades
43
+
44
+ This is no longer be an issue as of bundler 0.9.17
45
+
46
+ ref: http://mid.gmane.org/8FC34B23-5994-41CC-B5AF-7198EF06909E@tramchase.com
47
+
48
+ === BUNDLE_GEMFILE for Capistrano users
49
+
50
+ You may need to set or reset the BUNDLE_GEMFILE environment variable in
51
+ the before_exec hook:
52
+
53
+ before_exec do |server|
54
+ ENV["BUNDLE_GEMFILE"] = "/path/to/app/current/Gemfile"
55
+ end
56
+
57
+ === Other ENV pollution issues
58
+
59
+ If you're using an older Bundler version (0.9.x), you may need to set or
60
+ reset GEM_HOME, GEM_PATH and PATH environment variables in the
61
+ before_exec hook as illustrated by http://gist.github.com/534668
62
+
63
+ === Ruby 2.0.0 close-on-exec and SIGUSR2 incompatibility
64
+
65
+ Ruby 2.0.0 enforces FD_CLOEXEC on file descriptors by default. unicorn
66
+ has been prepared for this behavior since unicorn 4.1.0, but we forgot
67
+ to remind the Bundler developers. This issue is being tracked here:
68
+ https://github.com/bundler/bundler/issues/2628
69
+
70
+ == Isolate
71
+
72
+ === Running
73
+
74
+ Installing "unicorn" as a system-wide Rubygem and using the
75
+ isolate gem may cause issues if you're using any of the bundled
76
+ application-level libraries in unicorn/app/* (for compatibility
77
+ with CGI-based applications, Rails <= 2.2.2, or ExecCgi).
78
+ For now workarounds include doing one of the following:
79
+
80
+ 1. Isolating unicorn, setting GEM_HOME to your Isolate path,
81
+ and running the isolated version of unicorn. You *must* set
82
+ GEM_HOME before running your isolated unicorn install in this way.
83
+
84
+ 2. Installing the same version of unicorn as a system-wide Rubygem
85
+ *and* isolating unicorn as well.
86
+
87
+ 3. Explicitly setting RUBYLIB or $LOAD_PATH to include any gem path
88
+ where the unicorn gem is installed
89
+ (e.g. /usr/lib/ruby/gems/1.9.1/gems/unicorn-VERSION/lib)
90
+
91
+ === RUBYOPT pollution from SIGUSR2 upgrades
92
+
93
+ If you are using Isolate, using Isolate 2.x is strongly recommended as
94
+ environment modifications are idempotent.
95
+
96
+ If you are stuck with 1.x versions of Isolate, it is recommended that
97
+ you disable it with the <tt>before_exec</tt> hook prevent the PATH and
98
+ RUBYOPT environment variable modifications from propagating between
99
+ upgrades in your Unicorn config file:
100
+
101
+ before_exec do |server|
102
+ Isolate.disable
103
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ * Documentation improvements
2
+
3
+ * improve test suite
4
+
5
+ * Rack 2.x support (when Rack 2.x exists)
data/TUNING ADDED
@@ -0,0 +1,98 @@
1
+ = Tuning \Unicorn
2
+
3
+ \Unicorn performance is generally as good as a (mostly) Ruby web server
4
+ can provide. Most often the performance bottleneck is in the web
5
+ application running on Unicorn rather than Unicorn itself.
6
+
7
+ == \Unicorn Configuration
8
+
9
+ See Unicorn::Configurator for details on the config file format.
10
+ +worker_processes+ is the most-commonly needed tuning parameter.
11
+
12
+ === Unicorn::Configurator#worker_processes
13
+
14
+ * worker_processes should be scaled to the number of processes your
15
+ backend system(s) can support. DO NOT scale it to the number of
16
+ external network clients your application expects to be serving.
17
+ \Unicorn is NOT for serving slow clients, that is the job of nginx.
18
+
19
+ * worker_processes should be *at* *least* the number of CPU cores on
20
+ a dedicated server. If your application has occasionally slow
21
+ responses that are /not/ CPU-intensive, you may increase this to
22
+ workaround those inefficiencies.
23
+
24
+ * worker_processes may be increased for Unicorn::OobGC users to provide
25
+ more consistent response times.
26
+
27
+ * Never, ever, increase worker_processes to the point where the system
28
+ runs out of physical memory and hits swap. Production servers should
29
+ never see heavy swap activity.
30
+
31
+ === Unicorn::Configurator#listen Options
32
+
33
+ * Setting a very low value for the :backlog parameter in "listen"
34
+ directives can allow failover to happen more quickly if your
35
+ cluster is configured for it.
36
+
37
+ * If you're doing extremely simple benchmarks and getting connection
38
+ errors under high request rates, increasing your :backlog parameter
39
+ above the already-generous default of 1024 can help avoid connection
40
+ errors. Keep in mind this is not recommended for real traffic if
41
+ you have another machine to failover to (see above).
42
+
43
+ * :rcvbuf and :sndbuf parameters generally do not need to be set for TCP
44
+ listeners under Linux 2.6 because auto-tuning is enabled. UNIX domain
45
+ sockets do not have auto-tuning buffer sizes; so increasing those will
46
+ allow syscalls and task switches to be saved for larger requests
47
+ and responses. If your app only generates small responses or expects
48
+ small requests, you may shrink the buffer sizes to save memory, too.
49
+
50
+ * Having socket buffers too large can also be detrimental or have
51
+ little effect. Huge buffers can put more pressure on the allocator
52
+ and may also thrash CPU caches, cancelling out performance gains
53
+ one would normally expect.
54
+
55
+ * UNIX domain sockets are slightly faster than TCP sockets, but only
56
+ work if nginx is on the same machine.
57
+
58
+ == Other \Unicorn settings
59
+
60
+ * Setting "preload_app true" can allow copy-on-write-friendly GC to
61
+ be used to save memory. It will probably not work out of the box with
62
+ applications that open sockets or perform random I/O on files.
63
+ Databases like TokyoCabinet use concurrency-safe pread()/pwrite()
64
+ functions for safe sharing of database file descriptors across
65
+ processes.
66
+
67
+ * On POSIX-compliant filesystems, it is safe for multiple threads or
68
+ processes to append to one log file as long as all the processes are
69
+ have them unbuffered (File#sync = true) or they are
70
+ record(line)-buffered in userspace before any writes.
71
+
72
+ == Kernel Parameters (Linux sysctl)
73
+
74
+ WARNING: Do not change system parameters unless you know what you're doing!
75
+
76
+ * net.core.rmem_max and net.core.wmem_max can increase the allowed
77
+ size of :rcvbuf and :sndbuf respectively. This is mostly only useful
78
+ for UNIX domain sockets which do not have auto-tuning buffer sizes.
79
+
80
+ * For load testing/benchmarking with UNIX domain sockets, you should
81
+ consider increasing net.core.somaxconn or else nginx will start
82
+ failing to connect under heavy load. You may also consider setting
83
+ a higher :backlog to listen on as noted earlier.
84
+
85
+ * If you're running out of local ports, consider lowering
86
+ net.ipv4.tcp_fin_timeout to 20-30 (default: 60 seconds). Also
87
+ consider widening the usable port range by changing
88
+ net.ipv4.ip_local_port_range.
89
+
90
+ * Setting net.ipv4.tcp_timestamps=1 will also allow setting
91
+ net.ipv4.tcp_tw_reuse=1 and net.ipv4.tcp_tw_recycle=1, which along
92
+ with the above settings can slow down port exhaustion. Not all
93
+ networks are compatible with these settings, check with your friendly
94
+ network administrator before changing these.
95
+
96
+ * Increasing the MTU size can reduce framing overhead for larger
97
+ transfers. One often-overlooked detail is that the loopback
98
+ device (usually "lo") can have its MTU increased, too.