passenger 2.1.2 → 2.1.3

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

Potentially problematic release.


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

Files changed (244) hide show
  1. data/Rakefile +7 -5
  2. data/doc/Architectural overview.html +729 -1
  3. data/doc/Architectural overview.txt +0 -5
  4. data/doc/Security of user switching support.html +605 -1
  5. data/doc/Users guide.html +110 -106
  6. data/doc/Users guide.txt +49 -0
  7. data/doc/cxxapi/ApplicationPoolServer_8h-source.html +400 -372
  8. data/doc/cxxapi/ApplicationPool_8h-source.html +1 -1
  9. data/doc/cxxapi/Application_8h-source.html +1 -1
  10. data/doc/cxxapi/Bucket_8h-source.html +1 -1
  11. data/doc/cxxapi/CachedFileStat_8h-source.html +56 -65
  12. data/doc/cxxapi/Configuration_8h-source.html +40 -32
  13. data/doc/cxxapi/DirectoryMapper_8h-source.html +1 -1
  14. data/doc/cxxapi/DummySpawnManager_8h-source.html +1 -1
  15. data/doc/cxxapi/Exceptions_8h-source.html +1 -1
  16. data/doc/cxxapi/FileChecker_8h-source.html +29 -30
  17. data/doc/cxxapi/Hooks_8h-source.html +1 -1
  18. data/doc/cxxapi/Logging_8h-source.html +1 -1
  19. data/doc/cxxapi/MessageChannel_8h-source.html +1 -1
  20. data/doc/cxxapi/PoolOptions_8h-source.html +1 -1
  21. data/doc/cxxapi/SpawnManager_8h-source.html +225 -219
  22. data/doc/cxxapi/StandardApplicationPool_8h-source.html +451 -445
  23. data/doc/cxxapi/SystemTime_8h-source.html +1 -1
  24. data/doc/cxxapi/Utils_8h-source.html +201 -140
  25. data/doc/cxxapi/annotated.html +2 -2
  26. data/doc/cxxapi/classClient-members.html +1 -1
  27. data/doc/cxxapi/classClient.html +1 -1
  28. data/doc/cxxapi/classHooks-members.html +1 -1
  29. data/doc/cxxapi/classHooks.html +1 -1
  30. data/doc/cxxapi/classPassenger_1_1Application-members.html +1 -1
  31. data/doc/cxxapi/classPassenger_1_1Application.html +1 -1
  32. data/doc/cxxapi/classPassenger_1_1ApplicationPool-members.html +1 -1
  33. data/doc/cxxapi/classPassenger_1_1ApplicationPool.html +1 -1
  34. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer-members.html +1 -1
  35. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer.html +1 -1
  36. data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.png +0 -0
  37. data/doc/cxxapi/classPassenger_1_1Application_1_1Session-members.html +1 -1
  38. data/doc/cxxapi/classPassenger_1_1Application_1_1Session.html +1 -1
  39. data/doc/cxxapi/{classPassenger_1_1TempFile-members.html → classPassenger_1_1BufferedUpload-members.html} +5 -5
  40. data/doc/cxxapi/{classPassenger_1_1TempFile.html → classPassenger_1_1BufferedUpload.html} +33 -43
  41. data/doc/cxxapi/classPassenger_1_1BusyException-members.html +1 -1
  42. data/doc/cxxapi/classPassenger_1_1BusyException.html +1 -1
  43. data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +1 -1
  44. data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +1 -1
  45. data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +1 -1
  46. data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +1 -1
  47. data/doc/cxxapi/classPassenger_1_1DummySpawnManager-members.html +1 -1
  48. data/doc/cxxapi/classPassenger_1_1DummySpawnManager.html +1 -1
  49. data/doc/cxxapi/classPassenger_1_1FileChecker-members.html +1 -1
  50. data/doc/cxxapi/classPassenger_1_1FileChecker.html +2 -2
  51. data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +1 -1
  52. data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +1 -1
  53. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.png +0 -0
  54. data/doc/cxxapi/classPassenger_1_1FileSystemException-members.html +1 -1
  55. data/doc/cxxapi/classPassenger_1_1FileSystemException.html +1 -1
  56. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.png +0 -0
  57. data/doc/cxxapi/classPassenger_1_1IOException-members.html +1 -1
  58. data/doc/cxxapi/classPassenger_1_1IOException.html +1 -1
  59. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.png +0 -0
  60. data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +1 -1
  61. data/doc/cxxapi/classPassenger_1_1MessageChannel.html +1 -1
  62. data/doc/cxxapi/classPassenger_1_1RuntimeException-members.html +1 -1
  63. data/doc/cxxapi/classPassenger_1_1RuntimeException.html +1 -1
  64. data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +1 -1
  65. data/doc/cxxapi/classPassenger_1_1SpawnException.html +1 -1
  66. data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +1 -1
  67. data/doc/cxxapi/classPassenger_1_1SpawnManager.html +1 -1
  68. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool-members.html +1 -1
  69. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool.html +1 -1
  70. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.png +0 -0
  71. data/doc/cxxapi/classPassenger_1_1SystemException-members.html +1 -1
  72. data/doc/cxxapi/classPassenger_1_1SystemException.html +1 -1
  73. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.png +0 -0
  74. data/doc/cxxapi/classPassenger_1_1SystemTime-members.html +1 -1
  75. data/doc/cxxapi/classPassenger_1_1SystemTime.html +1 -1
  76. data/doc/cxxapi/definitions_8h-source.html +1 -1
  77. data/doc/cxxapi/files.html +1 -1
  78. data/doc/cxxapi/functions.html +12 -11
  79. data/doc/cxxapi/functions_func.html +9 -7
  80. data/doc/cxxapi/functions_type.html +1 -1
  81. data/doc/cxxapi/functions_vars.html +2 -4
  82. data/doc/cxxapi/graph_legend.html +1 -1
  83. data/doc/cxxapi/graph_legend.png +0 -0
  84. data/doc/cxxapi/group__Configuration.html +3 -3
  85. data/doc/cxxapi/group__Configuration.png +0 -0
  86. data/doc/cxxapi/group__Core.html +1 -1
  87. data/doc/cxxapi/group__Core.png +0 -0
  88. data/doc/cxxapi/group__Exceptions.html +1 -1
  89. data/doc/cxxapi/group__Hooks.html +1 -1
  90. data/doc/cxxapi/group__Hooks.png +0 -0
  91. data/doc/cxxapi/group__Support.html +33 -16
  92. data/doc/cxxapi/hierarchy.html +2 -2
  93. data/doc/cxxapi/inherit__graph__0.png +0 -0
  94. data/doc/cxxapi/inherit__graph__1.png +0 -0
  95. data/doc/cxxapi/inherit__graph__10.map +1 -1
  96. data/doc/cxxapi/inherit__graph__10.md5 +1 -1
  97. data/doc/cxxapi/inherit__graph__10.png +0 -0
  98. data/doc/cxxapi/inherit__graph__11.map +1 -1
  99. data/doc/cxxapi/inherit__graph__11.md5 +1 -1
  100. data/doc/cxxapi/inherit__graph__11.png +0 -0
  101. data/doc/cxxapi/inherit__graph__12.map +1 -2
  102. data/doc/cxxapi/inherit__graph__12.md5 +1 -1
  103. data/doc/cxxapi/inherit__graph__12.png +0 -0
  104. data/doc/cxxapi/inherit__graph__13.map +2 -1
  105. data/doc/cxxapi/inherit__graph__13.md5 +1 -1
  106. data/doc/cxxapi/inherit__graph__13.png +0 -0
  107. data/doc/cxxapi/inherit__graph__14.map +1 -1
  108. data/doc/cxxapi/inherit__graph__14.md5 +1 -1
  109. data/doc/cxxapi/inherit__graph__14.png +0 -0
  110. data/doc/cxxapi/inherit__graph__15.map +1 -1
  111. data/doc/cxxapi/inherit__graph__15.md5 +1 -1
  112. data/doc/cxxapi/inherit__graph__15.png +0 -0
  113. data/doc/cxxapi/inherit__graph__16.map +1 -1
  114. data/doc/cxxapi/inherit__graph__16.md5 +1 -1
  115. data/doc/cxxapi/inherit__graph__16.png +0 -0
  116. data/doc/cxxapi/inherit__graph__17.map +1 -1
  117. data/doc/cxxapi/inherit__graph__17.md5 +1 -1
  118. data/doc/cxxapi/inherit__graph__17.png +0 -0
  119. data/doc/cxxapi/inherit__graph__18.map +1 -1
  120. data/doc/cxxapi/inherit__graph__18.md5 +1 -1
  121. data/doc/cxxapi/inherit__graph__18.png +0 -0
  122. data/doc/cxxapi/inherit__graph__19.map +1 -2
  123. data/doc/cxxapi/inherit__graph__19.md5 +1 -1
  124. data/doc/cxxapi/inherit__graph__19.png +0 -0
  125. data/doc/cxxapi/inherit__graph__2.png +0 -0
  126. data/doc/cxxapi/inherit__graph__20.map +2 -1
  127. data/doc/cxxapi/inherit__graph__20.md5 +1 -1
  128. data/doc/cxxapi/inherit__graph__20.png +0 -0
  129. data/doc/cxxapi/inherit__graph__21.map +1 -1
  130. data/doc/cxxapi/inherit__graph__21.md5 +1 -1
  131. data/doc/cxxapi/inherit__graph__21.png +0 -0
  132. data/doc/cxxapi/inherit__graph__3.png +0 -0
  133. data/doc/cxxapi/inherit__graph__4.png +0 -0
  134. data/doc/cxxapi/inherit__graph__5.png +0 -0
  135. data/doc/cxxapi/inherit__graph__6.png +0 -0
  136. data/doc/cxxapi/inherit__graph__7.map +1 -1
  137. data/doc/cxxapi/inherit__graph__7.md5 +1 -1
  138. data/doc/cxxapi/inherit__graph__7.png +0 -0
  139. data/doc/cxxapi/inherit__graph__8.map +1 -1
  140. data/doc/cxxapi/inherit__graph__8.md5 +1 -1
  141. data/doc/cxxapi/inherit__graph__8.png +0 -0
  142. data/doc/cxxapi/inherit__graph__9.map +1 -1
  143. data/doc/cxxapi/inherit__graph__9.md5 +1 -1
  144. data/doc/cxxapi/inherit__graph__9.png +0 -0
  145. data/doc/cxxapi/inherits.html +18 -18
  146. data/doc/cxxapi/main.html +1 -1
  147. data/doc/cxxapi/modules.html +1 -1
  148. data/doc/cxxapi/structPassenger_1_1AnythingToString-members.html +1 -1
  149. data/doc/cxxapi/structPassenger_1_1AnythingToString.html +1 -1
  150. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4-members.html +1 -1
  151. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4.html +1 -1
  152. data/doc/cxxapi/structPassenger_1_1PoolOptions-members.html +1 -1
  153. data/doc/cxxapi/structPassenger_1_1PoolOptions.html +1 -1
  154. data/doc/cxxapi/tree.html +4 -4
  155. data/doc/rdoc/classes/ConditionVariable.html +58 -58
  156. data/doc/rdoc/classes/Exception.html +11 -11
  157. data/doc/rdoc/classes/GC.html +4 -4
  158. data/doc/rdoc/classes/IO.html +14 -14
  159. data/doc/rdoc/classes/PhusionPassenger.html +11 -11
  160. data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +1 -1
  161. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +40 -39
  162. data/doc/rdoc/classes/PhusionPassenger/Application.html +14 -14
  163. data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +12 -12
  164. data/doc/rdoc/classes/PhusionPassenger/Railz.html +1 -1
  165. data/doc/rdoc/classes/PhusionPassenger/Utils.html +15 -8
  166. data/doc/rdoc/classes/PlatformInfo.html +257 -253
  167. data/doc/rdoc/classes/RakeExtensions.html +2 -2
  168. data/doc/rdoc/classes/Signal.html +26 -26
  169. data/doc/rdoc/created.rid +1 -1
  170. data/doc/rdoc/files/DEVELOPERS_TXT.html +1 -1
  171. data/doc/rdoc/files/README.html +1 -1
  172. data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +1 -1
  173. data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +1 -1
  174. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +1 -1
  175. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +1 -1
  176. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +1 -1
  177. data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +1 -1
  178. data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +1 -1
  179. data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +1 -1
  180. data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +1 -1
  181. data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +1 -1
  182. data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +1 -1
  183. data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +1 -1
  184. data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +1 -1
  185. data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +1 -1
  186. data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +1 -1
  187. data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +1 -1
  188. data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +1 -1
  189. data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +1 -1
  190. data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +1 -1
  191. data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +1 -1
  192. data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +1 -1
  193. data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +1 -1
  194. data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +1 -1
  195. data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +9 -9
  196. data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +1 -1
  197. data/doc/rdoc/files/{lib → misc}/rake/extensions_rb.html +2 -2
  198. data/doc/rdoc/fr_file_index.html +1 -1
  199. data/doc/rdoc/fr_method_index.html +22 -22
  200. data/ext/apache2/ApplicationPoolServer.h +43 -15
  201. data/ext/apache2/ApplicationPoolServerExecutable.cpp +27 -52
  202. data/ext/apache2/CachedFileStat.h +7 -16
  203. data/ext/apache2/Configuration.h +9 -1
  204. data/ext/apache2/FileChecker.h +4 -5
  205. data/ext/apache2/Hooks.cpp +20 -22
  206. data/ext/apache2/SpawnManager.h +6 -0
  207. data/ext/apache2/StandardApplicationPool.h +6 -0
  208. data/ext/apache2/Utils.cpp +174 -16
  209. data/ext/apache2/Utils.h +99 -38
  210. data/ext/boost/cstdint.hpp +2 -1
  211. data/ext/oxt/system_calls.cpp +20 -2
  212. data/ext/oxt/system_calls.hpp +2 -0
  213. data/lib/phusion_passenger/abstract_request_handler.rb +5 -1
  214. data/lib/phusion_passenger/admin_tools.rb +1 -1
  215. data/lib/phusion_passenger/admin_tools/control_process.rb +2 -1
  216. data/lib/phusion_passenger/dependencies.rb +7 -4
  217. data/lib/phusion_passenger/platform_info.rb +8 -2
  218. data/lib/phusion_passenger/rack/application_spawner.rb +1 -1
  219. data/lib/phusion_passenger/templates/version_not_found.html.erb +9 -0
  220. data/lib/phusion_passenger/utils.rb +13 -6
  221. data/lib/phusion_passenger/wsgi/application_spawner.rb +1 -1
  222. data/{lib → misc}/rake/cplusplus.rb +0 -0
  223. data/{lib → misc}/rake/extensions.rb +0 -0
  224. data/{lib → misc}/rake/gempackagetask.rb +0 -0
  225. data/{lib → misc}/rake/packagetask.rb +0 -0
  226. data/{lib → misc}/rake/rdoctask.rb +0 -0
  227. data/misc/render_error_pages.rb +6 -5
  228. data/test/CxxTestMain.cpp +109 -7
  229. data/test/UtilsTest.cpp +61 -51
  230. data/test/config.yml.example +6 -2
  231. data/test/integration_tests.rb +4 -0
  232. data/test/ruby/abstract_request_handler_spec.rb +9 -3
  233. data/test/ruby/rack/application_spawner_spec.rb +3 -2
  234. data/test/ruby/rails/application_spawner_spec.rb +15 -4
  235. data/test/ruby/rails/framework_spawner_spec.rb +4 -2
  236. data/test/ruby/rails/spawner_error_handling_spec.rb +4 -4
  237. data/test/ruby/spawn_manager_spec.rb +22 -9
  238. data/test/ruby/utils_spec.rb +18 -12
  239. data/test/ruby/wsgi/application_spawner_spec.rb +16 -7
  240. data/test/stub/apache2/httpd.conf.erb +1 -0
  241. data/test/stub/wsgi/passenger_wsgi.pyc +0 -0
  242. metadata +1064 -1090
  243. data/doc/Users guide Apache.html +0 -3127
  244. data/doc/Users guide Nginx.html +0 -1458
data/Rakefile CHANGED
@@ -17,6 +17,7 @@
17
17
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
 
19
19
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
20
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/misc")
20
21
  require 'rubygems'
21
22
  require 'rake/rdoctask'
22
23
  require 'rake/gempackagetask'
@@ -29,7 +30,7 @@ verbose true
29
30
  ##### Configuration
30
31
 
31
32
  # Don't forget to edit Configuration.h too
32
- PACKAGE_VERSION = "2.1.2"
33
+ PACKAGE_VERSION = "2.1.3"
33
34
  OPTIMIZE = ["yes", "on", "true"].include?(ENV['OPTIMIZE'])
34
35
 
35
36
  PlatformInfo.apxs2.nil? and raise "Could not find 'apxs' or 'apxs2'."
@@ -239,7 +240,9 @@ class TEST
239
240
  ../ext/apache2/Application.h
240
241
  ../ext/apache2/FileChecker.h),
241
242
  'PoolOptionsTest.o' => %w(PoolOptionsTest.cpp ../ext/apache2/PoolOptions.h),
242
- 'FileCheckerTest.o' => %w(FileCheckerTest.cpp ../ext/apache2/FileChecker.h),
243
+ 'FileCheckerTest.o' => %w(FileCheckerTest.cpp
244
+ ../ext/apache2/FileChecker.h
245
+ ../ext/apache2/CachedFileStat.h),
243
246
  'SystemTimeTest.o' => %w(SystemTimeTest.cpp
244
247
  ../ext/apache2/SystemTime.h
245
248
  ../ext/apache2/SystemTime.cpp),
@@ -429,7 +432,7 @@ Rake::RDocTask.new(:clobber_rdoc => "rdoc:clobber", :rerdoc => "rdoc:force") do
429
432
  rd.rdoc_files.include("README", "DEVELOPERS.TXT",
430
433
  "lib/phusion_passenger/*.rb",
431
434
  "lib/phusion_passenger/*/*.rb",
432
- "lib/rake/extensions.rb",
435
+ "misc/rake/extensions.rb",
433
436
  "ext/phusion_passenger/*.c")
434
437
  rd.template = "./doc/template/horo"
435
438
  rd.title = "Passenger Ruby API"
@@ -488,6 +491,7 @@ spec = Gem::Specification.new do |s|
488
491
  'ext/phusion_passenger/*.{c,rb}',
489
492
  'benchmark/*.{cpp,rb}',
490
493
  'misc/*',
494
+ 'misc/*/*',
491
495
  'vendor/**/*',
492
496
  'test/*.{rb,cpp,example}',
493
497
  'test/support/*',
@@ -518,9 +522,7 @@ spec = Gem::Specification.new do |s|
518
522
  s.rdoc_options <<
519
523
  "-S" << "-N" << "-p" << "-H" <<
520
524
  '--main' << 'README' <<
521
- '--template' << './doc/template/horo' <<
522
525
  '--title' << 'Passenger Ruby API'
523
- s.test_file = 'test/support/run_rspec_tests.rb'
524
526
  s.description = "Passenger is an Apache module for Ruby on Rails support."
525
527
  end
526
528
 
@@ -1 +1,729 @@
1
- asciidoc required to build docs
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <meta name="generator" content="AsciiDoc 8.2.5" />
7
+ <style type="text/css">
8
+ /* Debug borders */
9
+ p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10
+ /*
11
+ border: 1px solid red;
12
+ */
13
+ }
14
+
15
+ body {
16
+ margin: 1em 5% 1em 5%;
17
+ }
18
+
19
+ a {
20
+ color: blue;
21
+ text-decoration: underline;
22
+ }
23
+ a:visited {
24
+ color: fuchsia;
25
+ }
26
+
27
+ em {
28
+ font-style: italic;
29
+ }
30
+
31
+ strong {
32
+ font-weight: bold;
33
+ }
34
+
35
+ tt {
36
+ color: navy;
37
+ }
38
+
39
+ h1, h2, h3, h4, h5, h6 {
40
+ color: #527bbd;
41
+ font-family: sans-serif;
42
+ margin-top: 1.2em;
43
+ margin-bottom: 0.5em;
44
+ line-height: 1.3;
45
+ }
46
+
47
+ h1, h2, h3 {
48
+ border-bottom: 2px solid silver;
49
+ }
50
+ h2 {
51
+ padding-top: 0.5em;
52
+ }
53
+ h3 {
54
+ float: left;
55
+ }
56
+ h3 + * {
57
+ clear: left;
58
+ }
59
+
60
+ div.sectionbody {
61
+ font-family: serif;
62
+ margin-left: 0;
63
+ }
64
+
65
+ hr {
66
+ border: 1px solid silver;
67
+ }
68
+
69
+ p {
70
+ margin-top: 0.5em;
71
+ margin-bottom: 0.5em;
72
+ }
73
+
74
+ pre {
75
+ padding: 0;
76
+ margin: 0;
77
+ }
78
+
79
+ span#author {
80
+ color: #527bbd;
81
+ font-family: sans-serif;
82
+ font-weight: bold;
83
+ font-size: 1.1em;
84
+ }
85
+ span#email {
86
+ }
87
+ span#revision {
88
+ font-family: sans-serif;
89
+ }
90
+
91
+ div#footer {
92
+ font-family: sans-serif;
93
+ font-size: small;
94
+ border-top: 2px solid silver;
95
+ padding-top: 0.5em;
96
+ margin-top: 4.0em;
97
+ }
98
+ div#footer-text {
99
+ float: left;
100
+ padding-bottom: 0.5em;
101
+ }
102
+ div#footer-badges {
103
+ float: right;
104
+ padding-bottom: 0.5em;
105
+ }
106
+
107
+ div#preamble,
108
+ div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109
+ div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110
+ div.admonitionblock {
111
+ margin-right: 10%;
112
+ margin-top: 1.5em;
113
+ margin-bottom: 1.5em;
114
+ }
115
+ div.admonitionblock {
116
+ margin-top: 2.5em;
117
+ margin-bottom: 2.5em;
118
+ }
119
+
120
+ div.content { /* Block element content. */
121
+ padding: 0;
122
+ }
123
+
124
+ /* Block element titles. */
125
+ div.title, caption.title {
126
+ font-family: sans-serif;
127
+ font-weight: bold;
128
+ text-align: left;
129
+ margin-top: 1.0em;
130
+ margin-bottom: 0.5em;
131
+ }
132
+ div.title + * {
133
+ margin-top: 0;
134
+ }
135
+
136
+ td div.title:first-child {
137
+ margin-top: 0.0em;
138
+ }
139
+ div.content div.title:first-child {
140
+ margin-top: 0.0em;
141
+ }
142
+ div.content + div.title {
143
+ margin-top: 0.0em;
144
+ }
145
+
146
+ div.sidebarblock > div.content {
147
+ background: #ffffee;
148
+ border: 1px solid silver;
149
+ padding: 0.5em;
150
+ }
151
+
152
+ div.listingblock {
153
+ margin-right: 0%;
154
+ }
155
+ div.listingblock > div.content {
156
+ border: 1px solid silver;
157
+ background: #f4f4f4;
158
+ padding: 0.5em;
159
+ }
160
+
161
+ div.quoteblock > div.content {
162
+ padding-left: 2.0em;
163
+ }
164
+
165
+ div.attribution {
166
+ text-align: right;
167
+ }
168
+ div.verseblock + div.attribution {
169
+ text-align: left;
170
+ }
171
+
172
+ div.admonitionblock .icon {
173
+ vertical-align: top;
174
+ font-size: 1.1em;
175
+ font-weight: bold;
176
+ text-decoration: underline;
177
+ color: #527bbd;
178
+ padding-right: 0.5em;
179
+ }
180
+ div.admonitionblock td.content {
181
+ padding-left: 0.5em;
182
+ border-left: 2px solid silver;
183
+ }
184
+
185
+ div.exampleblock > div.content {
186
+ border-left: 2px solid silver;
187
+ padding: 0.5em;
188
+ }
189
+
190
+ div.verseblock div.content {
191
+ white-space: pre;
192
+ }
193
+
194
+ div.imageblock div.content { padding-left: 0; }
195
+ div.imageblock img { border: 1px solid silver; }
196
+ span.image img { border-style: none; }
197
+
198
+ dl {
199
+ margin-top: 0.8em;
200
+ margin-bottom: 0.8em;
201
+ }
202
+ dt {
203
+ margin-top: 0.5em;
204
+ margin-bottom: 0;
205
+ font-style: italic;
206
+ }
207
+ dd > *:first-child {
208
+ margin-top: 0;
209
+ }
210
+
211
+ ul, ol {
212
+ list-style-position: outside;
213
+ }
214
+ div.olist2 ol {
215
+ list-style-type: lower-alpha;
216
+ }
217
+
218
+ div.tableblock > table {
219
+ border: 3px solid #527bbd;
220
+ }
221
+ thead {
222
+ font-family: sans-serif;
223
+ font-weight: bold;
224
+ }
225
+ tfoot {
226
+ font-weight: bold;
227
+ }
228
+
229
+ div.hlist {
230
+ margin-top: 0.8em;
231
+ margin-bottom: 0.8em;
232
+ }
233
+ div.hlist td {
234
+ padding-bottom: 5px;
235
+ }
236
+ td.hlist1 {
237
+ vertical-align: top;
238
+ font-style: italic;
239
+ padding-right: 0.8em;
240
+ }
241
+ td.hlist2 {
242
+ vertical-align: top;
243
+ }
244
+
245
+ @media print {
246
+ div#footer-badges { display: none; }
247
+ }
248
+
249
+ div#toctitle {
250
+ color: #527bbd;
251
+ font-family: sans-serif;
252
+ font-size: 1.1em;
253
+ font-weight: bold;
254
+ margin-top: 1.0em;
255
+ margin-bottom: 0.1em;
256
+ }
257
+
258
+ div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259
+ margin-top: 0;
260
+ margin-bottom: 0;
261
+ }
262
+ div.toclevel2 {
263
+ margin-left: 2em;
264
+ font-size: 0.9em;
265
+ }
266
+ div.toclevel3 {
267
+ margin-left: 4em;
268
+ font-size: 0.9em;
269
+ }
270
+ div.toclevel4 {
271
+ margin-left: 6em;
272
+ font-size: 0.9em;
273
+ }
274
+ /* Workarounds for IE6's broken and incomplete CSS2. */
275
+
276
+ div.sidebar-content {
277
+ background: #ffffee;
278
+ border: 1px solid silver;
279
+ padding: 0.5em;
280
+ }
281
+ div.sidebar-title, div.image-title {
282
+ font-family: sans-serif;
283
+ font-weight: bold;
284
+ margin-top: 0.0em;
285
+ margin-bottom: 0.5em;
286
+ }
287
+
288
+ div.listingblock div.content {
289
+ border: 1px solid silver;
290
+ background: #f4f4f4;
291
+ padding: 0.5em;
292
+ }
293
+
294
+ div.quoteblock-content {
295
+ padding-left: 2.0em;
296
+ }
297
+
298
+ div.exampleblock-content {
299
+ border-left: 2px solid silver;
300
+ padding-left: 0.5em;
301
+ }
302
+
303
+ /* IE6 sets dynamically generated links as visited. */
304
+ div#toc a:visited { color: blue; }
305
+ </style>
306
+ <script type="text/javascript">
307
+ /*<![CDATA[*/
308
+ window.onload = function(){generateToc(3)}
309
+ /* Author: Mihai Bazon, September 2002
310
+ * http://students.infoiasi.ro/~mishoo
311
+ *
312
+ * Table Of Content generator
313
+ * Version: 0.4
314
+ *
315
+ * Feel free to use this script under the terms of the GNU General Public
316
+ * License, as long as you do not remove or alter this notice.
317
+ */
318
+
319
+ /* modified by Troy D. Hanson, September 2006. License: GPL */
320
+ /* modified by Stuart Rackham, October 2006. License: GPL */
321
+
322
+ function getText(el) {
323
+ var text = "";
324
+ for (var i = el.firstChild; i != null; i = i.nextSibling) {
325
+ if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
326
+ text += i.data;
327
+ else if (i.firstChild != null)
328
+ text += getText(i);
329
+ }
330
+ return text;
331
+ }
332
+
333
+ function TocEntry(el, text, toclevel) {
334
+ this.element = el;
335
+ this.text = text;
336
+ this.toclevel = toclevel;
337
+ }
338
+
339
+ function tocEntries(el, toclevels) {
340
+ var result = new Array;
341
+ var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
342
+ // Function that scans the DOM tree for header elements (the DOM2
343
+ // nodeIterator API would be a better technique but not supported by all
344
+ // browsers).
345
+ var iterate = function (el) {
346
+ for (var i = el.firstChild; i != null; i = i.nextSibling) {
347
+ if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
348
+ var mo = re.exec(i.tagName)
349
+ if (mo)
350
+ result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
351
+ iterate(i);
352
+ }
353
+ }
354
+ }
355
+ iterate(el);
356
+ return result;
357
+ }
358
+
359
+ // This function does the work. toclevels = 1..4.
360
+ function generateToc(toclevels) {
361
+ var toc = document.getElementById("toc");
362
+ var entries = tocEntries(document.getElementsByTagName("body")[0], toclevels);
363
+ for (var i = 0; i < entries.length; ++i) {
364
+ var entry = entries[i];
365
+ if (entry.element.id == "")
366
+ entry.element.id = "toc" + i;
367
+ var a = document.createElement("a");
368
+ a.href = "#" + entry.element.id;
369
+ a.appendChild(document.createTextNode(entry.text));
370
+ var div = document.createElement("div");
371
+ div.appendChild(a);
372
+ div.className = "toclevel" + entry.toclevel;
373
+ toc.appendChild(div);
374
+ }
375
+ }
376
+ /*]]>*/
377
+ </script>
378
+ <title>Passenger architectural overview</title>
379
+ </head>
380
+ <body>
381
+ <div id="header">
382
+ <h1>Passenger architectural overview</h1>
383
+ <div id="toc">
384
+ <div id="toctitle">Table of Contents</div>
385
+ <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
386
+ </div>
387
+ </div>
388
+ <div id="preamble">
389
+ <div class="sectionbody">
390
+ <div class="para"><p>This document describes Passenger's architure in a global way. The purpose of
391
+ this document is to lower the barrier to entry for new contributors, as well
392
+ as to explain (some of the) design choices that we have made.</p></div>
393
+ <div class="para"><p>Or it can be a fun read for people who just want to know how Passenger works.</p></div>
394
+ </div>
395
+ </div>
396
+ <h2 id="_about_the_involved_technologies">1. About the involved technologies</h2>
397
+ <div class="sectionbody">
398
+ <h3 id="typical_web_applications">1.1. Typical web applications</h3><div style="clear:left"></div>
399
+ <div class="para"><p>Before we describe Passenger, it is important to understand how typical web
400
+ applications work, from the point of view of someone who wants to connect the
401
+ application to a web server.</p></div>
402
+ <div class="para"><p>A typical, isolated, web application accepts an HTTP request from some I/O
403
+ channel, processes it internally, and outputs an HTTP response, which is sent
404
+ back to the client. This is done in a loop, until the application is commanded
405
+ to exit. This does not necessarily mean that the web application speaks HTTP
406
+ directly: it just means that the web application accepts some kind of
407
+ representation of an HTTP request.</p></div>
408
+ <div class="para"><p><span class="image">
409
+ <img src="images/typical_isolated_web_application.png" alt="Architecture of a typical web application in isolation" title="Architecture of a typical web application in isolation" />
410
+ </span></p></div>
411
+ <div class="para"><p>Few web applications are accessible directly by HTTP clients. Common setups
412
+ are:</p></div>
413
+ <div class="olist"><ol>
414
+ <li>
415
+ <p>
416
+ The web application is contained in an application server. This application
417
+ server may or may not be able to contain multiple web applications. The
418
+ application server is then connected to the web server. The web server
419
+ dispatches requests to the application server, which in turn dispatches
420
+ requests to the correct web application, in a format that the web application
421
+ understands. Conversely, HTTP responses outputted by the web application are
422
+ sent to the application server, which in turn sends them to the web server,
423
+ and eventually to the HTTP client.
424
+ </p>
425
+ <div class="para"><p>A typical example of such a setup is a J2EE application, contained in the
426
+ Tomcat web server, behind the Apache web server.</p></div>
427
+ </li>
428
+ <li>
429
+ <p>
430
+ The web application is contained in a web server. In this case, the web
431
+ server acts like an application server. This is the case for PHP applications,
432
+ on Apache servers with <em>mod_php</em>. Note that this does not necessarily mean
433
+ that the web application is run inside the same process as the web server:
434
+ it just means that the web server manages applications.
435
+ </p>
436
+ </li>
437
+ <li>
438
+ <p>
439
+ The web application <strong>is</strong> a web server, and can accept HTTP requests
440
+ directly. This is the case for the Trac bug tracking system, running in its
441
+ standalone server. In many setups, such web applications sit behind a different
442
+ web server, instead of accepting HTTP requests directly. The frontend web
443
+ server acts like a reverse HTTP proxy.
444
+ </p>
445
+ </li>
446
+ <li>
447
+ <p>
448
+ The web application does not speak HTTP directly, but is connected directly
449
+ to the web server through some communication adapter. CGI, FastCGI and SCGI
450
+ are good examples of this.
451
+ </p>
452
+ </li>
453
+ </ol></div>
454
+ <div class="para"><p>These descriptions are true for virtually all web applications, whether they're
455
+ based on PHP, Django, J2EE, ASP.NET, Ruby on Rails, or whatever. Note that all
456
+ of these setups provide the same functionality, i.e. no setup can do something
457
+ that a different setup can't. The critical reader will notice that all of these
458
+ setups are identical to the one described in the first diagram, if the
459
+ combination of web servers, application servers, web applications etc. are
460
+ considered to be a single entity; a black box if you will.</p></div>
461
+ <div class="para"><p>It should also be noted that these setups do not enforce any particular
462
+ I/O processing implementation. The web servers, application servers, web
463
+ applications, etc. could process I/O serially (i.e. one request at a time),
464
+ could multiplex I/O with a single thread (e.g. by using <tt>select(2)</tt> or
465
+ <tt>poll(2)</tt>) or it could process I/O with multiple threads and/or multiple
466
+ processes.</p></div>
467
+ <div class="para"><p>Of course, there are many variations possible. For example, load balancers
468
+ could be used. But that is outside the scope of this document.</p></div>
469
+ <h3 id="_ruby_on_rails">1.2. Ruby on Rails</h3><div style="clear:left"></div>
470
+ <div class="para"><p>Every Ruby on Rails application has a <em>dispatcher</em>. This dispatcher is
471
+ responsible for processing HTTP requests. It does not speak HTTP directly.
472
+ Instead, it accepts data structures that contain the information of an
473
+ HTTP request. Thus, the dispatcher is particularly interesting to
474
+ developers who wish to develop software which connects Ruby on Rails to an
475
+ HTTP processing layer (e.g. a web server).</p></div>
476
+ <div class="para"><p>The Ruby on Rails dispatcher can only process requests serially, i.e. one
477
+ at a time. It is not possible to process two requests at the same time
478
+ with threads, because parts of Ruby on Rails are not thread-safe. (In
479
+ practice, this isn't as big of a problem as some people imagine. This will
480
+ be elaborated further in <a href="#concurrent_requests">Handling of concurrent requests</a>.)</p></div>
481
+ <div class="para"><p>A particularly interesting thing to note, is that a lot of the memory
482
+ occupied by Ruby on Rails applications is spent on storing the program code
483
+ (i.e. the <a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree">abstract
484
+ syntax tree (AST)</a>) in memory. This is observed through the use of the
485
+ memory statistics function in <a href="http://www.rubyenterpriseedition.com/">Ruby
486
+ Enterprise Edition</a>. Also, a lot of the startup time of a Ruby on Rails
487
+ application is spent on bootstrapping the Rails framework.</p></div>
488
+ <h3 id="_apache">1.3. Apache</h3><div style="clear:left"></div>
489
+ <div class="para"><p>The Apache web server has a pluggable I/O multiprocessing (the ability to
490
+ handle more than 1 concurrent HTTP client at the same time) architecture. An
491
+ Apache module which implements a particular multiprocessing strategy, is called
492
+ a Multi-Processing Module (MPM). The
493
+ <a href="http://httpd.apache.org/docs/2.0/mod/prefork.html">prefork MPM</a> &#8212; which
494
+ also happens to be the default &#8212; appears to be the most popular one. This MPM
495
+ spawns multiple worker child processes. HTTP requests are first accepted by a
496
+ so-called control process, and then forwarded to one of the worker processes.
497
+ The next section contains a diagram which shows the prefork MPM's architecture.</p></div>
498
+ </div>
499
+ <h2 id="_passenger_architecture">2. Passenger architecture</h2>
500
+ <div class="sectionbody">
501
+ <h3 id="_overview">2.1. Overview</h3><div style="clear:left"></div>
502
+ <div class="para"><p>Passenger's architecture is a lot like setup #2 described in
503
+ <a href="#typical_web_applications">Typical web applications</a>. In other words,
504
+ Passenger extends Apache and allows it to act like an application server.
505
+ Passenger's architecture &#8212; assuming Apache 2 with the prefork MPM is used &#8212;
506
+ is shown in the following diagram:</p></div>
507
+ <div class="para"><p><span class="image">
508
+ <img src="images/passenger_architecture.png" alt="Passenger's architecture" title="Passenger's architecture" />
509
+ </span></p></div>
510
+ <div class="para"><p>Passenger consists of an Apache module, <em>mod_passenger</em>. This is written in
511
+ C++, and can be found in the directory <em>ext/apache2</em>. The module is active in
512
+ the Apache control process and in all the Apache worker processes. When an
513
+ HTTP request comes in, <em>mod_passenger</em> will check whether the request should
514
+ be handled by a Ruby on Rails application. If so, then <em>mod_passenger</em> will
515
+ spawn the corresponding Rails application (if necessary) and forward the
516
+ request to that application.</p></div>
517
+ <div class="para"><p>It should be noted that the Ruby on Rails application does <strong>not</strong> run in the
518
+ same address space as Apache. This differentiates Passenger from other
519
+ application-server-inside-web-server software such as mod_php, mod_perl and
520
+ mod_ruby. If the Rails application crashes or leak memory, it will have no
521
+ effect on Apache. In fact, stability is one of our highest goals. Passenger
522
+ is carefully designed and implemented so that Apache shouldn't crash because
523
+ of Passenger.</p></div>
524
+ <h3 id="_spawning_and_caching_of_code_and_applications">2.2. Spawning and caching of code and applications</h3><div style="clear:left"></div>
525
+ <div class="para"><p>A very naive implementation of Passenger would spawn a Ruby on Rails
526
+ application every time an HTTP request is received, just like CGI would.
527
+ However, spawning Ruby on Rails applications is expensive. It can take 1 or 2
528
+ seconds on a modern PC, and possibly much longer on a heavily loaded server.
529
+ This overhead is particularily unacceptable on shared hosts. A less naive
530
+ implementation would keep spawned Ruby on Rails application instances alive,
531
+ similar to how Lighttpd's FastCGI implementation works.
532
+ However, this still has several problems:</p></div>
533
+ <div class="olist"><ol>
534
+ <li>
535
+ <p>
536
+ The first request to a Rails website will be slow, and subsequent requests
537
+ will be fast. But the first request to a different Rails website - on the
538
+ same web server - will still be slow.
539
+ </p>
540
+ </li>
541
+ <li>
542
+ <p>
543
+ As we've explained earlier in this article, a lot of memory in a Rails
544
+ application is spent on storing the AST of the Ruby on Rails framework and
545
+ the application. Especially on shared hosts and on memory-constrained
546
+ Virtual Private Servers (VPS), this can be a problem.
547
+ </p>
548
+ </li>
549
+ </ol></div>
550
+ <div class="para"><p>Both of these problems are very much solvable, and we've chosen to do just
551
+ that.</p></div>
552
+ <div class="para"><p>The first problem can be solved by preloading Rails applications, i.e. by
553
+ running the Rails application before a request is ever made to that website.
554
+ This is the approach taken by most Rails hosts, for example in the form of a
555
+ Mongrel cluster which is running all the time. However, this is unacceptable
556
+ for a shared host: such an application would just sit there and waste memory
557
+ even if it's not doing anything. Instead, we've chosen to take a different
558
+ approach, which solves both of the aforementioned problems.</p></div>
559
+ <div class="para"><p>We spawn Rails applications via a <em>spawn server</em>. The spawn server caches Ruby
560
+ on Rails framework code and application code in memory. Spawning a Rails
561
+ application for the first time will still be slow, but subsequent spawn
562
+ attempts will be very fast. Furthermore, because the framework code is cached
563
+ independently from the application code, spawning a different Rails application
564
+ will also be very fast, as long as that application is using a Rails framework
565
+ version that has already been cached.</p></div>
566
+ <div class="para"><p>Another implication of the spawn server is that different Ruby on Rails will
567
+ share memory with each other, thus solving problem #2. This is described in
568
+ detail in <a href="#spawn_server">the next section</a>.</p></div>
569
+ <div class="para"><p>But despite the caching of framework code and application code, spawning is
570
+ still expensive compared to an HTTP request. We want to avoid spawning whenever
571
+ possible. This is why we've introduced the <strong>application pool</strong>. Spawned
572
+ application instances are kept alive, and their handles are stored into this
573
+ pool, allowing each application instance to be reused later. Thus, Passenger
574
+ has very good average case performance.</p></div>
575
+ <div class="para"><p>The application pool is shared between different worker processes. Because the
576
+ worker processes cannot share memory with each other, either shared memory must
577
+ be used to implement the application pool, or a client/server architecture must
578
+ be implemented. We've chosen the latter because it is easier
579
+ to implement. The Apache control process acts like a server for the application
580
+ pool. However, this does not mean that all HTTP request/response data go
581
+ through the control process. A worker process queries the pool for a connection
582
+ session with a Rails application. Once this session has been obtained, the
583
+ worker process will communicate directly with the Rails application.</p></div>
584
+ <div class="para"><p>The application pool is implemented inside <em>mod_passenger</em>. One can find
585
+ detailed documentation about it in
586
+ <a href="cxxapi/index.html">the C++ API documentation</a>,
587
+ in particular the documentation about the <tt>ApplicationPool</tt>,
588
+ <tt>StandardApplicationPool</tt> and <tt>ApplicationPoolServer</tt> classes.</p></div>
589
+ <div class="para"><p>The application pool is responsible for spawning applications, caching
590
+ spawned applications' handles, and cleaning up applications which have been
591
+ idle for an extended period of time.</p></div>
592
+ <h3 id="spawn_server">2.3. The spawn server</h3><div style="clear:left"></div>
593
+ <div class="para"><p>The spawn server is written in Ruby, and its code can be found in the directory
594
+ <em>lib/passenger</em>. Its main executable is <em>bin/passenger-spawn-server</em>.
595
+ <a href="rdoc/index.html">The spawn server's RDoc documentation</a> documents the
596
+ implementation in detail.</p></div>
597
+ <div class="para"><p>The spawn server consists of 3 logical layers:</p></div>
598
+ <div class="olist"><ol>
599
+ <li>
600
+ <p>
601
+ <strong>The spawn manager.</strong> This is the topmost layer, and acts like a fascade for
602
+ all the underlying layers. Clients who use the spawn server only communicate
603
+ with this layer.
604
+ </p>
605
+ </li>
606
+ <li>
607
+ <p>
608
+ <strong>The framework spawner server.</strong> The spawn manager spawns a framework spawner
609
+ server for each unique Ruby on Rails framework version. Each framework
610
+ spawner server caches the code for exactly one Ruby on Rails framework
611
+ version. A spawn request for an application is forwarded to the framework
612
+ spawner server that contains the correct Ruby on Rails version for the
613
+ application.
614
+ </p>
615
+ </li>
616
+ <li>
617
+ <p>
618
+ <strong>The application spawner server.</strong> This is to the framework spawner server
619
+ what the framework spawner server is to the spawn manager. The framework
620
+ spawner server spawns an application spawner server for each unique Ruby on
621
+ Rails application (here &#8220;application&#8221; does not mean a running process, but
622
+ a set of (source code) files). An application spawner server caches the
623
+ code for exactly one application.
624
+ </p>
625
+ </li>
626
+ </ol></div>
627
+ <div class="para"><p><span class="image">
628
+ <img src="images/spawn_server_architecture.png" alt="The spawn server's architecture" title="The spawn server's architecture" />
629
+ </span></p></div>
630
+ <div class="para"><p>As you can see, we have two layers of code caching: when the spawn server
631
+ receives a request to spawn a new application instance, it will forward the
632
+ request to the correct framework spawner server (and will spawn that framework
633
+ spawner server if it doesn't already exist), which &#8212; in turn &#8212; will forward
634
+ it to the correct application spawner server (which will, again, be created if
635
+ it doesn't already exist).</p></div>
636
+ <div class="para"><p>Each layer is only responsible for the layer directly below. The spawn manager
637
+ only knows about framework spawner servers, and a framework spawner server only
638
+ knows about its application spawner servers. The application spawner server is,
639
+ however, not responsible for managing spawned application instances. If an
640
+ application instance is spawned by mod_passenger, its information will be sent
641
+ back to mod_passenger, which will be fully responsible for managing the
642
+ application instance's life time (through the application pool).</p></div>
643
+ <div class="para"><p>Also note that each layer is a seperate process. This is required because a
644
+ single Ruby process can only load a single Ruby on Rails framework and a
645
+ single application.</p></div>
646
+ <h4 id="_memory_sharing">2.3.1. Memory sharing</h4>
647
+ <div class="para"><p>On most modern Unix operating systems, when a child process is created, it will
648
+ share most of its memory with the parent process. Processes are not supposed to
649
+ be able to access each others' memory, so the operating system makes a copy of
650
+ a piece of memory when it is written to by the parent process or the child
651
+ process. This is called copy-on-write (COW). Detailed background information
652
+ can be found on <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise
653
+ Edition's website</a>.</p></div>
654
+ <div class="para"><p>The spawn server makes use of this useful fact. Each layer shares its Ruby AST
655
+ memory with all of its lower layers, as long as the AST nodes in question
656
+ haven't been written to. This means that all spawned Rails applications will
657
+ &#8212; if possible &#8212; share the Ruby on Rails framework's code, as well as its own
658
+ application code, with each other. This results in a dramatic reduction in
659
+ memory usage.</p></div>
660
+ <div class="admonitionblock">
661
+ <table><tr>
662
+ <td class="icon">
663
+ <img src="./images/icons/note.png" alt="Note" />
664
+ </td>
665
+ <td class="content">
666
+ <div class="para"><p>Sharing memory only works if <a href="http://www.rubyenterpriseedition.com/">Ruby
667
+ Enterprise Edition</a> is used. This is because the standard Ruby interpreter's
668
+ garbage collector isn't copy-on-write friendly. Please visit the Ruby
669
+ Enterprise Edition website for technical details.</p></div>
670
+ <div class="para"><p>Passenger works fine with standard Ruby. You still get to enjoy reduced Rails
671
+ startup times. You just won't be able to benefit from memory sharing.</p></div>
672
+ </td>
673
+ </tr></table>
674
+ </div>
675
+ <div class="para"><p>Note that <a href="http://rubini.us/">Rubinius</a>'s garbage collector is already
676
+ copy-on-write friendly.</p></div>
677
+ <h3 id="concurrent_requests">2.4. Handling of concurrent requests</h3><div style="clear:left"></div>
678
+ <div class="para"><p>As explained earlier, a single Rails application instance can only handle a
679
+ single request at the same time. This is obviously undesirable. But before we
680
+ dive into the solution, let us take a look how the &#8220;competition&#8221; solves this
681
+ problem. PHP has similar problems: a single PHP script can also process only
682
+ one HTTP request at a time.</p></div>
683
+ <div class="ilist"><ul>
684
+ <li>
685
+ <p>
686
+ mod_php &#8220;solves&#8221; this problem by using Apache's MPM. In other words,
687
+ mod_php doesn't do anything by itself at all. A single Apache worker
688
+ process/thread can only handle 1 PHP request at a time, but Apache spawns
689
+ multiple worker processes/threads.
690
+ </p>
691
+ </li>
692
+ <li>
693
+ <p>
694
+ PHP-FastCGI solves the problem by spawning multiple persistent PHP servers.
695
+ The number of PHP servers is independent from the number of Apache worker
696
+ processes/threads. This approach is a lot like existing Rails setups, in
697
+ which a frontend web server proxies requests to a persistent Mongrel cluster.
698
+ </p>
699
+ </li>
700
+ </ul></div>
701
+ <div class="para"><p>Passenger cannot use the mod_php way because it would force us to spawn a new
702
+ Rails application for each request, which is &#8212; as explained earlier &#8212;
703
+ unacceptably slow. Instead, Passenger uses the PHP-FastCGI approach. We
704
+ maintain a pool of application instances, and whenever a request is received,
705
+ we forward the request to one of the application instances in the pool. The
706
+ size of the pool is configurable, which is useful for administrators of servers
707
+ that are either heavily loaded or have little memory.</p></div>
708
+ <div class="para"><p>The reader might also be interested in studying the application pool's
709
+ algorithm, which is non-trivial. The algorithm is documented in detail in
710
+ <a href="ApplicationPool%20algorithm.txt">ApplicationPool algorithm.txt</a>.</p></div>
711
+ </div>
712
+ <h2 id="_appendix_a_about_this_document">3. Appendix A: About this document</h2>
713
+ <div class="sectionbody">
714
+ <div class="para"><p>The text of this document is licensed under the
715
+ <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
716
+ Attribution-Share Alike 3.0 Unported License</a>.</p></div>
717
+ <div class="para"><p><span class="image">
718
+ <a class="image" href="link:http://creativecommons.org/licenses/by-sa/3.0/">
719
+ <img src="images/by_sa.png" alt="images/by_sa.png" />
720
+ </a>
721
+ </span></p></div>
722
+ </div>
723
+ <div id="footer">
724
+ <div id="footer-text">
725
+ Last updated 2009-03-30 15:30:58 CEST
726
+ </div>
727
+ </div>
728
+ </body>
729
+ </html>