preplay_unicorn 4.3.1.2.gc450

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/.CHANGELOG.old +25 -0
  2. data/.document +29 -0
  3. data/.gitignore +24 -0
  4. data/.mailmap +26 -0
  5. data/.manifest +258 -0
  6. data/.wrongdoc.yml +10 -0
  7. data/Application_Timeouts +77 -0
  8. data/CONTRIBUTORS +35 -0
  9. data/COPYING +674 -0
  10. data/ChangeLog +3839 -0
  11. data/DESIGN +97 -0
  12. data/Documentation/.gitignore +5 -0
  13. data/Documentation/GNUmakefile +30 -0
  14. data/Documentation/unicorn.1.txt +174 -0
  15. data/Documentation/unicorn_rails.1.txt +175 -0
  16. data/FAQ +53 -0
  17. data/GIT-VERSION-FILE +1 -0
  18. data/GIT-VERSION-GEN +40 -0
  19. data/GNUmakefile +294 -0
  20. data/HACKING +134 -0
  21. data/ISSUES +36 -0
  22. data/KNOWN_ISSUES +79 -0
  23. data/LATEST +15 -0
  24. data/LICENSE +64 -0
  25. data/Links +56 -0
  26. data/NEWS +1886 -0
  27. data/PHILOSOPHY +145 -0
  28. data/README +149 -0
  29. data/Rakefile +97 -0
  30. data/SIGNALS +114 -0
  31. data/Sandbox +96 -0
  32. data/TODO +5 -0
  33. data/TUNING +98 -0
  34. data/bin/unicorn +121 -0
  35. data/bin/unicorn_rails +209 -0
  36. data/examples/big_app_gc.rb +2 -0
  37. data/examples/echo.ru +27 -0
  38. data/examples/git.ru +13 -0
  39. data/examples/init.sh +74 -0
  40. data/examples/logger_mp_safe.rb +25 -0
  41. data/examples/logrotate.conf +29 -0
  42. data/examples/nginx.conf +156 -0
  43. data/examples/unicorn.conf.minimal.rb +13 -0
  44. data/examples/unicorn.conf.rb +94 -0
  45. data/ext/unicorn_http/CFLAGS +13 -0
  46. data/ext/unicorn_http/c_util.h +124 -0
  47. data/ext/unicorn_http/common_field_optimization.h +111 -0
  48. data/ext/unicorn_http/ext_help.h +86 -0
  49. data/ext/unicorn_http/extconf.rb +10 -0
  50. data/ext/unicorn_http/global_variables.h +97 -0
  51. data/ext/unicorn_http/httpdate.c +82 -0
  52. data/ext/unicorn_http/unicorn_http.c +4031 -0
  53. data/ext/unicorn_http/unicorn_http.rl +1036 -0
  54. data/ext/unicorn_http/unicorn_http_common.rl +76 -0
  55. data/lib/unicorn/app/exec_cgi.rb +154 -0
  56. data/lib/unicorn/app/inetd.rb +109 -0
  57. data/lib/unicorn/app/old_rails/static.rb +59 -0
  58. data/lib/unicorn/app/old_rails.rb +35 -0
  59. data/lib/unicorn/cgi_wrapper.rb +147 -0
  60. data/lib/unicorn/configurator.rb +641 -0
  61. data/lib/unicorn/const.rb +40 -0
  62. data/lib/unicorn/http_request.rb +77 -0
  63. data/lib/unicorn/http_response.rb +45 -0
  64. data/lib/unicorn/http_server.rb +748 -0
  65. data/lib/unicorn/launcher.rb +62 -0
  66. data/lib/unicorn/oob_gc.rb +71 -0
  67. data/lib/unicorn/preread_input.rb +33 -0
  68. data/lib/unicorn/socket_helper.rb +208 -0
  69. data/lib/unicorn/ssl_client.rb +11 -0
  70. data/lib/unicorn/ssl_configurator.rb +104 -0
  71. data/lib/unicorn/ssl_server.rb +42 -0
  72. data/lib/unicorn/stream_input.rb +149 -0
  73. data/lib/unicorn/tee_input.rb +126 -0
  74. data/lib/unicorn/tmpio.rb +29 -0
  75. data/lib/unicorn/util.rb +68 -0
  76. data/lib/unicorn/worker.rb +88 -0
  77. data/lib/unicorn.rb +107 -0
  78. data/local.mk.sample +59 -0
  79. data/man/man1/unicorn.1 +201 -0
  80. data/man/man1/unicorn_rails.1 +208 -0
  81. data/preplay_unicorn.gemspec +44 -0
  82. data/script/isolate_for_tests +50 -0
  83. data/setup.rb +1586 -0
  84. data/t/.gitignore +5 -0
  85. data/t/GNUmakefile +82 -0
  86. data/t/README +42 -0
  87. data/t/bin/content-md5-put +36 -0
  88. data/t/bin/sha1sum.rb +17 -0
  89. data/t/bin/unused_listen +40 -0
  90. data/t/bin/utee +12 -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/heartbeat-timeout.ru +12 -0
  95. data/t/my-tap-lib.sh +201 -0
  96. data/t/oob_gc.ru +21 -0
  97. data/t/oob_gc_path.ru +21 -0
  98. data/t/pid.ru +3 -0
  99. data/t/preread_input.ru +17 -0
  100. data/t/rack-input-tests.ru +21 -0
  101. data/t/rails3-app/.gitignore +4 -0
  102. data/t/rails3-app/Gemfile +26 -0
  103. data/t/rails3-app/Rakefile +10 -0
  104. data/t/rails3-app/app/controllers/application_controller.rb +4 -0
  105. data/t/rails3-app/app/helpers/application_helper.rb +2 -0
  106. data/t/rails3-app/app/views/layouts/application.html.erb +14 -0
  107. data/t/rails3-app/config/application.rb +46 -0
  108. data/t/rails3-app/config/boot.rb +6 -0
  109. data/t/rails3-app/config/database.yml +22 -0
  110. data/t/rails3-app/config/environment.rb +5 -0
  111. data/t/rails3-app/config/environments/development.rb +19 -0
  112. data/t/rails3-app/config/environments/production.rb +42 -0
  113. data/t/rails3-app/config/environments/test.rb +32 -0
  114. data/t/rails3-app/config/initializers/backtrace_silencers.rb +7 -0
  115. data/t/rails3-app/config/initializers/inflections.rb +10 -0
  116. data/t/rails3-app/config/initializers/mime_types.rb +5 -0
  117. data/t/rails3-app/config/initializers/secret_token.rb +7 -0
  118. data/t/rails3-app/config/initializers/session_store.rb +8 -0
  119. data/t/rails3-app/config/locales/en.yml +5 -0
  120. data/t/rails3-app/config/routes.rb +58 -0
  121. data/t/rails3-app/config.ru +4 -0
  122. data/t/rails3-app/db/seeds.rb +7 -0
  123. data/t/rails3-app/doc/README_FOR_APP +2 -0
  124. data/t/rails3-app/lib/tasks/.gitkeep +0 -0
  125. data/t/rails3-app/public/404.html +1 -0
  126. data/t/rails3-app/public/500.html +1 -0
  127. data/t/rails3-app/public/x.txt +1 -0
  128. data/t/rails3-app/script/rails +9 -0
  129. data/t/rails3-app/test/performance/browsing_test.rb +9 -0
  130. data/t/rails3-app/test/test_helper.rb +13 -0
  131. data/t/rails3-app/vendor/plugins/.gitkeep +0 -0
  132. data/t/sslgen.sh +71 -0
  133. data/t/t0000-http-basic.sh +50 -0
  134. data/t/t0001-reload-bad-config.sh +53 -0
  135. data/t/t0002-config-conflict.sh +49 -0
  136. data/t/t0002-parser-error.sh +94 -0
  137. data/t/t0003-working_directory.sh +51 -0
  138. data/t/t0004-heartbeat-timeout.sh +69 -0
  139. data/t/t0004-working_directory_broken.sh +24 -0
  140. data/t/t0005-working_directory_app.rb.sh +37 -0
  141. data/t/t0006-reopen-logs.sh +83 -0
  142. data/t/t0006.ru +13 -0
  143. data/t/t0007-working_directory_no_embed_cli.sh +44 -0
  144. data/t/t0008-back_out_of_upgrade.sh +110 -0
  145. data/t/t0009-broken-app.sh +56 -0
  146. data/t/t0009-winch_ttin.sh +59 -0
  147. data/t/t0010-reap-logging.sh +55 -0
  148. data/t/t0011-active-unix-socket.sh +79 -0
  149. data/t/t0012-reload-empty-config.sh +85 -0
  150. data/t/t0013-rewindable-input-false.sh +24 -0
  151. data/t/t0013.ru +12 -0
  152. data/t/t0014-rewindable-input-true.sh +24 -0
  153. data/t/t0014.ru +12 -0
  154. data/t/t0015-configurator-internals.sh +25 -0
  155. data/t/t0016-trust-x-forwarded-false.sh +30 -0
  156. data/t/t0017-trust-x-forwarded-true.sh +30 -0
  157. data/t/t0018-write-on-close.sh +23 -0
  158. data/t/t0019-max_header_len.sh +49 -0
  159. data/t/t0020-at_exit-handler.sh +49 -0
  160. data/t/t0021-process_detach.sh +29 -0
  161. data/t/t0100-rack-input-tests.sh +124 -0
  162. data/t/t0116-client_body_buffer_size.sh +80 -0
  163. data/t/t0116.ru +16 -0
  164. data/t/t0300-rails3-basic.sh +28 -0
  165. data/t/t0301-rails3-missing-config-ru.sh +33 -0
  166. data/t/t0302-rails3-alt-working_directory.sh +32 -0
  167. data/t/t0303-rails3-alt-working_directory_config.ru.sh +56 -0
  168. data/t/t0304-rails3-alt-working_directory_no_embed_cli.sh +52 -0
  169. data/t/t0600-https-server-basic.sh +48 -0
  170. data/t/t9000-preread-input.sh +48 -0
  171. data/t/t9001-oob_gc.sh +47 -0
  172. data/t/t9002-oob_gc-path.sh +75 -0
  173. data/t/test-lib.sh +113 -0
  174. data/t/test-rails3.sh +27 -0
  175. data/t/write-on-close.ru +11 -0
  176. data/test/aggregate.rb +15 -0
  177. data/test/benchmark/README +50 -0
  178. data/test/benchmark/dd.ru +18 -0
  179. data/test/benchmark/stack.ru +8 -0
  180. data/test/exec/README +5 -0
  181. data/test/exec/test_exec.rb +1055 -0
  182. data/test/rails/app-1.2.3/.gitignore +2 -0
  183. data/test/rails/app-1.2.3/Rakefile +7 -0
  184. data/test/rails/app-1.2.3/app/controllers/application.rb +6 -0
  185. data/test/rails/app-1.2.3/app/controllers/foo_controller.rb +36 -0
  186. data/test/rails/app-1.2.3/app/helpers/application_helper.rb +4 -0
  187. data/test/rails/app-1.2.3/config/boot.rb +11 -0
  188. data/test/rails/app-1.2.3/config/database.yml +12 -0
  189. data/test/rails/app-1.2.3/config/environment.rb +13 -0
  190. data/test/rails/app-1.2.3/config/environments/development.rb +9 -0
  191. data/test/rails/app-1.2.3/config/environments/production.rb +5 -0
  192. data/test/rails/app-1.2.3/config/routes.rb +6 -0
  193. data/test/rails/app-1.2.3/db/.gitignore +0 -0
  194. data/test/rails/app-1.2.3/log/.gitignore +1 -0
  195. data/test/rails/app-1.2.3/public/404.html +1 -0
  196. data/test/rails/app-1.2.3/public/500.html +1 -0
  197. data/test/rails/app-2.0.2/.gitignore +2 -0
  198. data/test/rails/app-2.0.2/Rakefile +7 -0
  199. data/test/rails/app-2.0.2/app/controllers/application.rb +4 -0
  200. data/test/rails/app-2.0.2/app/controllers/foo_controller.rb +36 -0
  201. data/test/rails/app-2.0.2/app/helpers/application_helper.rb +4 -0
  202. data/test/rails/app-2.0.2/config/boot.rb +11 -0
  203. data/test/rails/app-2.0.2/config/database.yml +12 -0
  204. data/test/rails/app-2.0.2/config/environment.rb +17 -0
  205. data/test/rails/app-2.0.2/config/environments/development.rb +8 -0
  206. data/test/rails/app-2.0.2/config/environments/production.rb +5 -0
  207. data/test/rails/app-2.0.2/config/routes.rb +6 -0
  208. data/test/rails/app-2.0.2/db/.gitignore +0 -0
  209. data/test/rails/app-2.0.2/log/.gitignore +1 -0
  210. data/test/rails/app-2.0.2/public/404.html +1 -0
  211. data/test/rails/app-2.0.2/public/500.html +1 -0
  212. data/test/rails/app-2.1.2/.gitignore +2 -0
  213. data/test/rails/app-2.1.2/Rakefile +7 -0
  214. data/test/rails/app-2.1.2/app/controllers/application.rb +4 -0
  215. data/test/rails/app-2.1.2/app/controllers/foo_controller.rb +36 -0
  216. data/test/rails/app-2.1.2/app/helpers/application_helper.rb +4 -0
  217. data/test/rails/app-2.1.2/config/boot.rb +111 -0
  218. data/test/rails/app-2.1.2/config/database.yml +12 -0
  219. data/test/rails/app-2.1.2/config/environment.rb +17 -0
  220. data/test/rails/app-2.1.2/config/environments/development.rb +7 -0
  221. data/test/rails/app-2.1.2/config/environments/production.rb +5 -0
  222. data/test/rails/app-2.1.2/config/routes.rb +6 -0
  223. data/test/rails/app-2.1.2/db/.gitignore +0 -0
  224. data/test/rails/app-2.1.2/log/.gitignore +1 -0
  225. data/test/rails/app-2.1.2/public/404.html +1 -0
  226. data/test/rails/app-2.1.2/public/500.html +1 -0
  227. data/test/rails/app-2.2.2/.gitignore +2 -0
  228. data/test/rails/app-2.2.2/Rakefile +7 -0
  229. data/test/rails/app-2.2.2/app/controllers/application.rb +4 -0
  230. data/test/rails/app-2.2.2/app/controllers/foo_controller.rb +36 -0
  231. data/test/rails/app-2.2.2/app/helpers/application_helper.rb +4 -0
  232. data/test/rails/app-2.2.2/config/boot.rb +111 -0
  233. data/test/rails/app-2.2.2/config/database.yml +12 -0
  234. data/test/rails/app-2.2.2/config/environment.rb +17 -0
  235. data/test/rails/app-2.2.2/config/environments/development.rb +7 -0
  236. data/test/rails/app-2.2.2/config/environments/production.rb +5 -0
  237. data/test/rails/app-2.2.2/config/routes.rb +6 -0
  238. data/test/rails/app-2.2.2/db/.gitignore +0 -0
  239. data/test/rails/app-2.2.2/log/.gitignore +1 -0
  240. data/test/rails/app-2.2.2/public/404.html +1 -0
  241. data/test/rails/app-2.2.2/public/500.html +1 -0
  242. data/test/rails/test_rails.rb +287 -0
  243. data/test/test_helper.rb +300 -0
  244. data/test/unit/test_configurator.rb +158 -0
  245. data/test/unit/test_droplet.rb +28 -0
  246. data/test/unit/test_http_parser.rb +860 -0
  247. data/test/unit/test_http_parser_ng.rb +716 -0
  248. data/test/unit/test_http_parser_xftrust.rb +38 -0
  249. data/test/unit/test_request.rb +197 -0
  250. data/test/unit/test_response.rb +99 -0
  251. data/test/unit/test_server.rb +289 -0
  252. data/test/unit/test_signals.rb +207 -0
  253. data/test/unit/test_sni_hostnames.rb +47 -0
  254. data/test/unit/test_socket_helper.rb +192 -0
  255. data/test/unit/test_stream_input.rb +204 -0
  256. data/test/unit/test_tee_input.rb +296 -0
  257. data/test/unit/test_upload.rb +306 -0
  258. data/test/unit/test_util.rb +100 -0
  259. metadata +428 -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,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 1.1.5 and carries the same license.
64
+
65
+ Mongrel is copyright 2007 Zed A. Shaw and contributors. It is
66
+ tri-licensed under (your choice) of the GPLv3, GPLv2 or Ruby-specific
67
+ terms. See the included LICENSE file for 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 RubyGems.org:
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://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://bogomips.org/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,97 @@
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 RAA"
9
+ task :raa_update do
10
+ require 'net/http'
11
+ require 'net/netrc'
12
+ rc = Net::Netrc.locate('unicorn-raa') or abort "~/.netrc not found"
13
+ password = rc.password
14
+
15
+ s = Gem::Specification.load('unicorn.gemspec')
16
+ desc = [ s.description.strip ]
17
+ desc << ""
18
+ desc << "* #{s.email}"
19
+ desc << "* #{git_url}"
20
+ desc << "* #{cgit_url}"
21
+ desc = desc.join("\n")
22
+ uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
23
+ form = {
24
+ :name => s.name,
25
+ :short_description => s.summary,
26
+ :version => s.version.to_s,
27
+ :status => 'stable',
28
+ :owner => s.authors.first,
29
+ :email => s.email,
30
+ :category_major => 'Library',
31
+ :category_minor => 'Web',
32
+ :url => s.homepage,
33
+ :download => "http://rubyforge.org/frs/?group_id=1306",
34
+ :license => "Ruby's",
35
+ :description_style => 'Plain',
36
+ :description => desc,
37
+ :pass => password,
38
+ :submit => "Update",
39
+ }
40
+ res = Net::HTTP.post_form(uri, form)
41
+ p res
42
+ puts res.body
43
+ end
44
+
45
+ desc "post to FM"
46
+ task :fm_update do
47
+ require 'tempfile'
48
+ require 'net/http'
49
+ require 'net/netrc'
50
+ require 'json'
51
+ version = ENV['VERSION'] or abort "VERSION= needed"
52
+ uri = URI.parse('http://freecode.com/projects/unicorn/releases.json')
53
+ rc = Net::Netrc.locate('unicorn-fm') or abort "~/.netrc not found"
54
+ api_token = rc.password
55
+ _, subject, body = `git cat-file tag v#{version}`.split(/\n\n/, 3)
56
+ tmp = Tempfile.new('fm-changelog')
57
+ tmp.puts subject
58
+ tmp.puts
59
+ tmp.puts body
60
+ tmp.flush
61
+ system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
62
+ changelog = File.read(tmp.path).strip
63
+
64
+ req = {
65
+ "auth_code" => api_token,
66
+ "release" => {
67
+ "tag_list" => "Experimental",
68
+ "version" => version,
69
+ "changelog" => changelog,
70
+ },
71
+ }.to_json
72
+
73
+ if ! changelog.strip.empty? && version =~ %r{\A[\d\.]+\d+\z}
74
+ Net::HTTP.start(uri.host, uri.port) do |http|
75
+ p http.post(uri.path, req, {'Content-Type'=>'application/json'})
76
+ end
77
+ else
78
+ warn "not updating freshmeat for v#{version}"
79
+ end
80
+ end
81
+
82
+ # optional rake-compiler support in case somebody needs to cross compile
83
+ begin
84
+ mk = "ext/unicorn_http/Makefile"
85
+ if File.readable?(mk)
86
+ warn "run 'gmake -C ext/unicorn_http clean' and\n" \
87
+ "remove #{mk} before using rake-compiler"
88
+ elsif ENV['VERSION']
89
+ unless File.readable?("ext/unicorn_http/unicorn_http.c")
90
+ abort "run 'gmake ragel' or 'make ragel' to generate the Ragel source"
91
+ end
92
+ spec = Gem::Specification.load('unicorn.gemspec')
93
+ require 'rake/extensiontask'
94
+ Rake::ExtensionTask.new('unicorn_http', spec)
95
+ end
96
+ rescue LoadError
97
+ end
data/SIGNALS ADDED
@@ -0,0 +1,114 @@
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
+ === Master Process
11
+
12
+ * HUP - reloads config file and gracefully restart all workers.
13
+ If the "preload_app" directive is false (the default), then workers
14
+ will also pick up any application code changes when restarted. If
15
+ "preload_app" is true, then application code changes will have no
16
+ effect; USR2 + QUIT (see below) must be used to load newer code in
17
+ this case. When reloading the application, +Gem.refresh+ will
18
+ be called so updated code for your application can pick up newly
19
+ installed RubyGems. It is not recommended that you uninstall
20
+ libraries your application depends on while Unicorn is running,
21
+ as respawned workers may enter a spawn loop when they fail to
22
+ load an uninstalled dependency.
23
+
24
+ * INT/TERM - quick shutdown, kills all workers immediately
25
+
26
+ * QUIT - graceful shutdown, waits for workers to finish their
27
+ current request before finishing.
28
+
29
+ * USR1 - reopen all logs owned by the master and all workers
30
+ See Unicorn::Util.reopen_logs for what is considered a log.
31
+
32
+ * USR2 - reexecute the running binary. A separate QUIT
33
+ should be sent to the original process once the child is verified to
34
+ be up and running.
35
+
36
+ * WINCH - gracefully stops workers but keep the master running.
37
+ This will only work for daemonized processes.
38
+
39
+ * TTIN - increment the number of worker processes by one
40
+
41
+ * TTOU - decrement the number of worker processes by one
42
+
43
+ === Worker Processes
44
+
45
+ Sending signals directly to the worker processes should not normally be
46
+ needed. If the master process is running, any exited worker will be
47
+ automatically respawned.
48
+
49
+ * INT/TERM - Quick shutdown, immediately exit.
50
+ Unless WINCH has been sent to the master (or the master is killed),
51
+ the master process will respawn a worker to replace this one.
52
+
53
+ * QUIT - Gracefully exit after finishing the current request.
54
+ Unless WINCH has been sent to the master (or the master is killed),
55
+ the master process will respawn a worker to replace this one.
56
+
57
+ * USR1 - Reopen all logs owned by the worker process.
58
+ See Unicorn::Util.reopen_logs for what is considered a log.
59
+ Log files are not reopened until it is done processing
60
+ the current request, so multiple log lines for one request
61
+ (as done by Rails) will not be split across multiple logs.
62
+
63
+ It is NOT recommended to send the USR1 signal directly to workers via
64
+ "killall -USR1 unicorn" if you are using user/group-switching support
65
+ in your workers. You will encounter incorrect file permissions and
66
+ workers will need to be respawned. Sending USR1 to the master process
67
+ first will ensure logs have the correct permissions before the master
68
+ forwards the USR1 signal to workers.
69
+
70
+ === Procedure to replace a running unicorn executable
71
+
72
+ You may replace a running instance of unicorn with a new one without
73
+ losing any incoming connections. Doing so will reload all of your
74
+ application code, Unicorn config, Ruby executable, and all libraries.
75
+ The only things that will not change (due to OS limitations) are:
76
+
77
+ 1. The path to the unicorn executable script. If you want to change to
78
+ a different installation of Ruby, you can modify the shebang
79
+ line to point to your alternative interpreter.
80
+
81
+ The procedure is exactly like that of nginx:
82
+
83
+ 1. Send USR2 to the master process
84
+
85
+ 2. Check your process manager or pid files to see if a new master spawned
86
+ successfully. If you're using a pid file, the old process will have
87
+ ".oldbin" appended to its path. You should have two master instances
88
+ of unicorn running now, both of which will have workers servicing
89
+ requests. Your process tree should look something like this:
90
+
91
+ unicorn master (old)
92
+ \_ unicorn worker[0]
93
+ \_ unicorn worker[1]
94
+ \_ unicorn worker[2]
95
+ \_ unicorn worker[3]
96
+ \_ unicorn master
97
+ \_ unicorn worker[0]
98
+ \_ unicorn worker[1]
99
+ \_ unicorn worker[2]
100
+ \_ unicorn worker[3]
101
+
102
+ 3. You can now send WINCH to the old master process so only the new workers
103
+ serve requests. If your unicorn process is bound to an interactive
104
+ terminal, you can skip this step. Step 5 will be more difficult but
105
+ you can also skip it if your process is not daemonized.
106
+
107
+ 4. You should now ensure that everything is running correctly with the
108
+ new workers as the old workers die off.
109
+
110
+ 5. If everything seems ok, then send QUIT to the old master. You're done!
111
+
112
+ If something is broken, then send HUP to the old master to reload
113
+ the config and restart its workers. Then send QUIT to the new master
114
+ process.
data/Sandbox ADDED
@@ -0,0 +1,96 @@
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
+ == Isolate
64
+
65
+ === Running
66
+
67
+ Installing "unicorn" as a system-wide Rubygem and using the
68
+ isolate gem may cause issues if you're using any of the bundled
69
+ application-level libraries in unicorn/app/* (for compatibility
70
+ with CGI-based applications, Rails <= 2.2.2, or ExecCgi).
71
+ For now workarounds include doing one of the following:
72
+
73
+ 1. Isolating unicorn, setting GEM_HOME to your Isolate path,
74
+ and running the isolated version of unicorn. You *must* set
75
+ GEM_HOME before running your isolated unicorn install in this way.
76
+
77
+ 2. Installing the same version of unicorn as a system-wide Rubygem
78
+ *and* isolating unicorn as well.
79
+
80
+ 3. Explicitly setting RUBYLIB or $LOAD_PATH to include any gem path
81
+ where the unicorn gem is installed
82
+ (e.g. /usr/lib/ruby/gems/1.9.1/gems/unicorn-VERSION/lib)
83
+
84
+ === RUBYOPT pollution from SIGUSR2 upgrades
85
+
86
+ If you are using Isolate, using Isolate 2.x is strongly recommended as
87
+ environment modifications are idempotent.
88
+
89
+ If you are stuck with 1.x versions of Isolate, it is recommended that
90
+ you disable it with the <tt>before_exec</tt> hook prevent the PATH and
91
+ RUBYOPT environment variable modifications from propagating between
92
+ upgrades in your Unicorn config file:
93
+
94
+ before_exec do |server|
95
+ Isolate.disable
96
+ 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)