unicorn-shopify 4.8.2.5.23

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.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/.CHANGELOG.old +25 -0
  3. data/.document +28 -0
  4. data/.gitignore +25 -0
  5. data/.mailmap +26 -0
  6. data/.olddoc.yml +15 -0
  7. data/Application_Timeouts +77 -0
  8. data/CONTRIBUTORS +35 -0
  9. data/COPYING +674 -0
  10. data/DESIGN +97 -0
  11. data/Documentation/.gitignore +5 -0
  12. data/Documentation/GNUmakefile +30 -0
  13. data/Documentation/unicorn.1.txt +185 -0
  14. data/Documentation/unicorn_rails.1.txt +175 -0
  15. data/FAQ +61 -0
  16. data/GIT-VERSION-GEN +39 -0
  17. data/GNUmakefile +252 -0
  18. data/HACKING +120 -0
  19. data/ISSUES +100 -0
  20. data/KNOWN_ISSUES +79 -0
  21. data/LICENSE +67 -0
  22. data/Links +59 -0
  23. data/PHILOSOPHY +145 -0
  24. data/README +145 -0
  25. data/Rakefile +16 -0
  26. data/SIGNALS +123 -0
  27. data/Sandbox +103 -0
  28. data/TODO +5 -0
  29. data/TUNING +101 -0
  30. data/archive/.gitignore +3 -0
  31. data/archive/slrnpull.conf +4 -0
  32. data/bin/unicorn +126 -0
  33. data/bin/unicorn_rails +209 -0
  34. data/examples/big_app_gc.rb +2 -0
  35. data/examples/echo.ru +27 -0
  36. data/examples/init.sh +74 -0
  37. data/examples/logger_mp_safe.rb +25 -0
  38. data/examples/logrotate.conf +29 -0
  39. data/examples/nginx.conf +156 -0
  40. data/examples/unicorn.conf.minimal.rb +13 -0
  41. data/examples/unicorn.conf.rb +113 -0
  42. data/ext/unicorn_http/CFLAGS +13 -0
  43. data/ext/unicorn_http/c_util.h +124 -0
  44. data/ext/unicorn_http/common_field_optimization.h +111 -0
  45. data/ext/unicorn_http/ext_help.h +82 -0
  46. data/ext/unicorn_http/extconf.rb +10 -0
  47. data/ext/unicorn_http/global_variables.h +97 -0
  48. data/ext/unicorn_http/httpdate.c +78 -0
  49. data/ext/unicorn_http/unicorn_http.rl +934 -0
  50. data/ext/unicorn_http/unicorn_http_common.rl +76 -0
  51. data/lib/unicorn.rb +112 -0
  52. data/lib/unicorn/app/old_rails.rb +35 -0
  53. data/lib/unicorn/app/old_rails/static.rb +59 -0
  54. data/lib/unicorn/cgi_wrapper.rb +147 -0
  55. data/lib/unicorn/configurator.rb +686 -0
  56. data/lib/unicorn/const.rb +21 -0
  57. data/lib/unicorn/http_request.rb +125 -0
  58. data/lib/unicorn/http_response.rb +73 -0
  59. data/lib/unicorn/http_server.rb +816 -0
  60. data/lib/unicorn/launcher.rb +62 -0
  61. data/lib/unicorn/oob_gc.rb +81 -0
  62. data/lib/unicorn/preread_input.rb +33 -0
  63. data/lib/unicorn/socket_helper.rb +197 -0
  64. data/lib/unicorn/stream_input.rb +146 -0
  65. data/lib/unicorn/tee_input.rb +133 -0
  66. data/lib/unicorn/tmpio.rb +27 -0
  67. data/lib/unicorn/util.rb +90 -0
  68. data/lib/unicorn/worker.rb +140 -0
  69. data/setup.rb +1586 -0
  70. data/t/.gitignore +4 -0
  71. data/t/GNUmakefile +74 -0
  72. data/t/README +42 -0
  73. data/t/before_murder.ru +7 -0
  74. data/t/bin/content-md5-put +36 -0
  75. data/t/bin/sha1sum.rb +17 -0
  76. data/t/bin/unused_listen +40 -0
  77. data/t/broken-app.ru +12 -0
  78. data/t/detach.ru +11 -0
  79. data/t/env.ru +3 -0
  80. data/t/fails-rack-lint.ru +5 -0
  81. data/t/heartbeat-timeout.ru +12 -0
  82. data/t/hijack.ru +42 -0
  83. data/t/listener_names.ru +4 -0
  84. data/t/my-tap-lib.sh +201 -0
  85. data/t/oob_gc.ru +20 -0
  86. data/t/oob_gc_path.ru +20 -0
  87. data/t/pid.ru +3 -0
  88. data/t/preread_input.ru +17 -0
  89. data/t/rack-input-tests.ru +21 -0
  90. data/t/t0000-http-basic.sh +50 -0
  91. data/t/t0001-reload-bad-config.sh +53 -0
  92. data/t/t0002-config-conflict.sh +49 -0
  93. data/t/t0002-parser-error.sh +94 -0
  94. data/t/t0003-working_directory.sh +51 -0
  95. data/t/t0004-heartbeat-timeout.sh +69 -0
  96. data/t/t0004-working_directory_broken.sh +24 -0
  97. data/t/t0005-working_directory_app.rb.sh +40 -0
  98. data/t/t0006-reopen-logs.sh +83 -0
  99. data/t/t0006.ru +13 -0
  100. data/t/t0007-working_directory_no_embed_cli.sh +44 -0
  101. data/t/t0008-back_out_of_upgrade.sh +110 -0
  102. data/t/t0009-broken-app.sh +56 -0
  103. data/t/t0009-winch_ttin.sh +59 -0
  104. data/t/t0010-reap-logging.sh +55 -0
  105. data/t/t0011-active-unix-socket.sh +79 -0
  106. data/t/t0012-reload-empty-config.sh +85 -0
  107. data/t/t0013-rewindable-input-false.sh +24 -0
  108. data/t/t0013.ru +12 -0
  109. data/t/t0014-rewindable-input-true.sh +24 -0
  110. data/t/t0014.ru +12 -0
  111. data/t/t0015-configurator-internals.sh +25 -0
  112. data/t/t0018-write-on-close.sh +23 -0
  113. data/t/t0019-max_header_len.sh +49 -0
  114. data/t/t0020-at_exit-handler.sh +49 -0
  115. data/t/t0021-process_detach.sh +29 -0
  116. data/t/t0022-listener_names-preload_app.sh +32 -0
  117. data/t/t0023-before-murder.sh +40 -0
  118. data/t/t0024-before-murder_once.sh +52 -0
  119. data/t/t0100-rack-input-tests.sh +124 -0
  120. data/t/t0116-client_body_buffer_size.sh +80 -0
  121. data/t/t0116.ru +16 -0
  122. data/t/t0200-rack-hijack.sh +27 -0
  123. data/t/t0300-no-default-middleware.sh +20 -0
  124. data/t/t9000-preread-input.sh +48 -0
  125. data/t/t9001-oob_gc.sh +47 -0
  126. data/t/t9002-oob_gc-path.sh +75 -0
  127. data/t/test-lib.sh +128 -0
  128. data/t/write-on-close.ru +11 -0
  129. data/test/aggregate.rb +15 -0
  130. data/test/benchmark/README +50 -0
  131. data/test/benchmark/dd.ru +18 -0
  132. data/test/benchmark/stack.ru +8 -0
  133. data/test/exec/README +5 -0
  134. data/test/exec/test_exec.rb +1047 -0
  135. data/test/test_helper.rb +297 -0
  136. data/test/unit/test_configurator.rb +175 -0
  137. data/test/unit/test_droplet.rb +28 -0
  138. data/test/unit/test_http_parser.rb +854 -0
  139. data/test/unit/test_http_parser_ng.rb +622 -0
  140. data/test/unit/test_request.rb +182 -0
  141. data/test/unit/test_response.rb +93 -0
  142. data/test/unit/test_server.rb +268 -0
  143. data/test/unit/test_signals.rb +188 -0
  144. data/test/unit/test_socket_helper.rb +197 -0
  145. data/test/unit/test_stream_input.rb +203 -0
  146. data/test/unit/test_tee_input.rb +304 -0
  147. data/test/unit/test_upload.rb +306 -0
  148. data/test/unit/test_util.rb +105 -0
  149. data/unicorn.gemspec +41 -0
  150. metadata +311 -0
data/README ADDED
@@ -0,0 +1,145 @@
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.github.io/].
14
+
15
+ * Compatible with Ruby 1.9.3 and later.
16
+ unicorn 4.8.x will remain supported for Ruby 1.8 users.
17
+
18
+ * Process management: \Unicorn will reap and restart workers that
19
+ die from broken apps. There is no need to manage multiple processes
20
+ or ports yourself. \Unicorn can spawn and manage any number of
21
+ worker processes you choose to scale to your backend.
22
+
23
+ * Load balancing is done entirely by the operating system kernel.
24
+ Requests never pile up behind a busy worker process.
25
+
26
+ * Does not care if your application is thread-safe or not, workers
27
+ all run within their own isolated address space and only serve one
28
+ client at a time for maximum robustness.
29
+
30
+ * Supports all Rack applications, along with pre-Rack versions of
31
+ Ruby on Rails via a Rack wrapper.
32
+
33
+ * Builtin reopening of all log files in your application via
34
+ USR1 signal. This allows logrotate to rotate files atomically and
35
+ quickly via rename instead of the racy and slow copytruncate method.
36
+ \Unicorn also takes steps to ensure multi-line log entries from one
37
+ request all stay within the same file.
38
+
39
+ * nginx-style binary upgrades without losing connections.
40
+ You can upgrade \Unicorn, your entire application, libraries
41
+ and even your Ruby interpreter without dropping clients.
42
+
43
+ * before_fork and after_fork hooks in case your application
44
+ has special needs when dealing with forked processes. These
45
+ should not be needed when the "preload_app" directive is
46
+ false (the default).
47
+
48
+ * Can be used with copy-on-write-friendly memory management
49
+ to save memory (by setting "preload_app" to true).
50
+
51
+ * Able to listen on multiple interfaces including UNIX sockets,
52
+ each worker process can also bind to a private port via the
53
+ after_fork hook for easy debugging.
54
+
55
+ * Simple and easy Ruby DSL for configuration.
56
+
57
+ * Decodes chunked transfers on-the-fly, thus allowing upload progress
58
+ notification to be implemented as well as being able to tunnel
59
+ arbitrary stream-based protocols over HTTP.
60
+
61
+ == License
62
+
63
+ \Unicorn is copyright 2009 by all contributors (see logs in git).
64
+ It is based on Mongrel 1.1.5.
65
+ Mongrel is copyright 2007 Zed A. Shaw and contributors.
66
+
67
+ \Unicorn is licensed under (your choice) of the GPLv2 or later
68
+ (GPLv3+ preferred), or Ruby (1.8)-specific terms.
69
+ See the included LICENSE file for details.
70
+
71
+ \Unicorn is 100% Free Software.
72
+
73
+ == Install
74
+
75
+ The library consists of a C extension so you'll need a C compiler
76
+ and Ruby development libraries/headers.
77
+
78
+ You may install it via RubyGems on RubyGems.org:
79
+
80
+ gem install unicorn
81
+
82
+ You can get the latest source via git from the following locations
83
+ (these versions may not be stable):
84
+
85
+ git://bogomips.org/unicorn.git
86
+ git://repo.or.cz/unicorn.git (mirror)
87
+
88
+ You may browse the code from the web and download the latest snapshot
89
+ tarballs here:
90
+
91
+ * http://bogomips.org/unicorn.git (cgit)
92
+ * http://repo.or.cz/w/unicorn.git (gitweb)
93
+
94
+ See the HACKING guide on how to contribute and build prerelease gems
95
+ from git.
96
+
97
+ == Usage
98
+
99
+ === Rack (including Rails 3+) applications
100
+
101
+ In APP_ROOT, run:
102
+
103
+ unicorn
104
+
105
+ === Ancient Rails 1.2 - 2.x versions
106
+
107
+ In RAILS_ROOT, run:
108
+
109
+ unicorn_rails
110
+
111
+ \Unicorn will bind to all interfaces on TCP port 8080 by default.
112
+ You may use the +--listen/-l+ switch to bind to a different
113
+ address:port or a UNIX socket.
114
+
115
+ === Configuration File(s)
116
+
117
+ \Unicorn will look for the config.ru file used by rackup in APP_ROOT.
118
+
119
+ For deployments, it can use a config file for \Unicorn-specific options
120
+ specified by the +--config-file/-c+ command-line switch. See
121
+ Unicorn::Configurator for the syntax of the \Unicorn-specific options.
122
+ The default settings are designed for maximum out-of-the-box
123
+ compatibility with existing applications.
124
+
125
+ Most command-line options for other Rack applications (above) are also
126
+ supported. Run `unicorn -h` to see command-line options.
127
+
128
+ == Disclaimer
129
+
130
+ There is NO WARRANTY whatsoever if anything goes wrong, but
131
+ {let us know}[link:ISSUES.html] and we'll try our best to fix it.
132
+
133
+ \Unicorn is designed to only serve fast clients either on the local host
134
+ or a fast LAN. See the PHILOSOPHY and DESIGN documents for more details
135
+ regarding this.
136
+
137
+ == Contact
138
+
139
+ All feedback (bug reports, user/development dicussion, patches, pull
140
+ requests) go to the mailing list/newsgroup. See the ISSUES document for
141
+ information on the {mailing list}[mailto:unicorn-public@bogomips.org].
142
+
143
+ For the latest on \Unicorn releases, you may also finger us at
144
+ unicorn@bogomips.org or check our NEWS page (and subscribe to our Atom
145
+ feed).
@@ -0,0 +1,16 @@
1
+ # optional rake-compiler support in case somebody needs to cross compile
2
+ begin
3
+ mk = "ext/unicorn_http/Makefile"
4
+ if File.readable?(mk)
5
+ warn "run 'gmake -C ext/unicorn_http clean' and\n" \
6
+ "remove #{mk} before using rake-compiler"
7
+ elsif ENV['VERSION']
8
+ unless File.readable?("ext/unicorn_http/unicorn_http.c")
9
+ abort "run 'gmake ragel' or 'make ragel' to generate the Ragel source"
10
+ end
11
+ spec = Gem::Specification.load('unicorn.gemspec')
12
+ require 'rake/extensiontask'
13
+ Rake::ExtensionTask.new('unicorn_http', spec)
14
+ end
15
+ rescue LoadError
16
+ 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.3/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,101 @@
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 (unless you do not have enough memory).
21
+ If your application has occasionally slow responses that are /not/
22
+ CPU-intensive, you may increase this to workaround those inefficiencies.
23
+
24
+ * Under Ruby 2.2 or later, Etc.nprocessors may be used to determine
25
+ the number of CPU cores present.
26
+
27
+ * worker_processes may be increased for Unicorn::OobGC users to provide
28
+ more consistent response times.
29
+
30
+ * Never, ever, increase worker_processes to the point where the system
31
+ runs out of physical memory and hits swap. Production servers should
32
+ never see heavy swap activity.
33
+
34
+ === Unicorn::Configurator#listen Options
35
+
36
+ * Setting a very low value for the :backlog parameter in "listen"
37
+ directives can allow failover to happen more quickly if your
38
+ cluster is configured for it.
39
+
40
+ * If you're doing extremely simple benchmarks and getting connection
41
+ errors under high request rates, increasing your :backlog parameter
42
+ above the already-generous default of 1024 can help avoid connection
43
+ errors. Keep in mind this is not recommended for real traffic if
44
+ you have another machine to failover to (see above).
45
+
46
+ * :rcvbuf and :sndbuf parameters generally do not need to be set for TCP
47
+ listeners under Linux 2.6 because auto-tuning is enabled. UNIX domain
48
+ sockets do not have auto-tuning buffer sizes; so increasing those will
49
+ allow syscalls and task switches to be saved for larger requests
50
+ and responses. If your app only generates small responses or expects
51
+ small requests, you may shrink the buffer sizes to save memory, too.
52
+
53
+ * Having socket buffers too large can also be detrimental or have
54
+ little effect. Huge buffers can put more pressure on the allocator
55
+ and may also thrash CPU caches, cancelling out performance gains
56
+ one would normally expect.
57
+
58
+ * UNIX domain sockets are slightly faster than TCP sockets, but only
59
+ work if nginx is on the same machine.
60
+
61
+ == Other \Unicorn settings
62
+
63
+ * Setting "preload_app true" can allow copy-on-write-friendly GC to
64
+ be used to save memory. It will probably not work out of the box with
65
+ applications that open sockets or perform random I/O on files.
66
+ Databases like TokyoCabinet use concurrency-safe pread()/pwrite()
67
+ functions for safe sharing of database file descriptors across
68
+ processes.
69
+
70
+ * On POSIX-compliant filesystems, it is safe for multiple threads or
71
+ processes to append to one log file as long as all the processes are
72
+ have them unbuffered (File#sync = true) or they are
73
+ record(line)-buffered in userspace before any writes.
74
+
75
+ == Kernel Parameters (Linux sysctl)
76
+
77
+ WARNING: Do not change system parameters unless you know what you're doing!
78
+
79
+ * net.core.rmem_max and net.core.wmem_max can increase the allowed
80
+ size of :rcvbuf and :sndbuf respectively. This is mostly only useful
81
+ for UNIX domain sockets which do not have auto-tuning buffer sizes.
82
+
83
+ * For load testing/benchmarking with UNIX domain sockets, you should
84
+ consider increasing net.core.somaxconn or else nginx will start
85
+ failing to connect under heavy load. You may also consider setting
86
+ a higher :backlog to listen on as noted earlier.
87
+
88
+ * If you're running out of local ports, consider lowering
89
+ net.ipv4.tcp_fin_timeout to 20-30 (default: 60 seconds). Also
90
+ consider widening the usable port range by changing
91
+ net.ipv4.ip_local_port_range.
92
+
93
+ * Setting net.ipv4.tcp_timestamps=1 will also allow setting
94
+ net.ipv4.tcp_tw_reuse=1 and net.ipv4.tcp_tw_recycle=1, which along
95
+ with the above settings can slow down port exhaustion. Not all
96
+ networks are compatible with these settings, check with your friendly
97
+ network administrator before changing these.
98
+
99
+ * Increasing the MTU size can reduce framing overhead for larger
100
+ transfers. One often-overlooked detail is that the loopback
101
+ device (usually "lo") can have its MTU increased, too.