rails 2.2.2 → 3.0.0

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

Potentially problematic release.


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

Files changed (336) hide show
  1. data/bin/rails +8 -18
  2. metadata +118 -452
  3. data/CHANGELOG +0 -2071
  4. data/MIT-LICENSE +0 -20
  5. data/README +0 -256
  6. data/Rakefile +0 -411
  7. data/bin/about +0 -4
  8. data/bin/console +0 -3
  9. data/bin/dbconsole +0 -3
  10. data/bin/destroy +0 -3
  11. data/bin/generate +0 -3
  12. data/bin/performance/benchmarker +0 -3
  13. data/bin/performance/profiler +0 -3
  14. data/bin/performance/request +0 -3
  15. data/bin/plugin +0 -3
  16. data/bin/process/inspector +0 -3
  17. data/bin/process/reaper +0 -3
  18. data/bin/process/spawner +0 -3
  19. data/bin/runner +0 -3
  20. data/bin/server +0 -3
  21. data/builtin/rails_info/rails/info.rb +0 -125
  22. data/builtin/rails_info/rails/info_controller.rb +0 -9
  23. data/builtin/rails_info/rails/info_helper.rb +0 -2
  24. data/builtin/rails_info/rails_info_controller.rb +0 -2
  25. data/config.ru +0 -17
  26. data/configs/apache.conf +0 -40
  27. data/configs/databases/frontbase.yml +0 -28
  28. data/configs/databases/ibm_db.yml +0 -62
  29. data/configs/databases/mysql.yml +0 -57
  30. data/configs/databases/oracle.yml +0 -39
  31. data/configs/databases/postgresql.yml +0 -51
  32. data/configs/databases/sqlite2.yml +0 -19
  33. data/configs/databases/sqlite3.yml +0 -22
  34. data/configs/empty.log +0 -0
  35. data/configs/initializers/inflections.rb +0 -10
  36. data/configs/initializers/mime_types.rb +0 -5
  37. data/configs/initializers/new_rails_defaults.rb +0 -17
  38. data/configs/lighttpd.conf +0 -54
  39. data/configs/locales/en.yml +0 -5
  40. data/configs/routes.rb +0 -43
  41. data/dispatches/dispatch.fcgi +0 -24
  42. data/dispatches/dispatch.rb +0 -10
  43. data/dispatches/gateway.cgi +0 -97
  44. data/doc/README_FOR_APP +0 -5
  45. data/doc/guides/html/2_2_release_notes.html +0 -1185
  46. data/doc/guides/html/actioncontroller_basics.html +0 -1270
  47. data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
  48. data/doc/guides/html/association_basics.html +0 -2585
  49. data/doc/guides/html/authors.html +0 -240
  50. data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
  51. data/doc/guides/html/caching_with_rails.html +0 -583
  52. data/doc/guides/html/command_line.html +0 -434
  53. data/doc/guides/html/configuring.html +0 -438
  54. data/doc/guides/html/creating_plugins.html +0 -1594
  55. data/doc/guides/html/debugging_rails_applications.html +0 -1175
  56. data/doc/guides/html/finders.html +0 -1090
  57. data/doc/guides/html/form_helpers.html +0 -638
  58. data/doc/guides/html/getting_started_with_rails.html +0 -2066
  59. data/doc/guides/html/index.html +0 -349
  60. data/doc/guides/html/layouts_and_rendering.html +0 -1406
  61. data/doc/guides/html/migrations.html +0 -921
  62. data/doc/guides/html/routing_outside_in.html +0 -2213
  63. data/doc/guides/html/security.html +0 -1346
  64. data/doc/guides/html/testing_rails_applications.html +0 -1859
  65. data/doc/guides/source/2_2_release_notes.txt +0 -435
  66. data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
  67. data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
  68. data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
  69. data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
  70. data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
  71. data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
  72. data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
  73. data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
  74. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
  75. data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
  76. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
  77. data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
  78. data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
  79. data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
  80. data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
  81. data/doc/guides/source/active_record_basics.txt +0 -181
  82. data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
  83. data/doc/guides/source/association_basics.txt +0 -1840
  84. data/doc/guides/source/authors.txt +0 -39
  85. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
  86. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
  87. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
  88. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
  89. data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
  90. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
  91. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
  92. data/doc/guides/source/caching_with_rails.txt +0 -367
  93. data/doc/guides/source/command_line.txt +0 -147
  94. data/doc/guides/source/configuring.txt +0 -225
  95. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
  96. data/doc/guides/source/creating_plugins/appendix.txt +0 -46
  97. data/doc/guides/source/creating_plugins/controllers.txt +0 -59
  98. data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
  99. data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
  100. data/doc/guides/source/creating_plugins/gem.txt +0 -1
  101. data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
  102. data/doc/guides/source/creating_plugins/helpers.txt +0 -51
  103. data/doc/guides/source/creating_plugins/index.txt +0 -52
  104. data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
  105. data/doc/guides/source/creating_plugins/models.txt +0 -76
  106. data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
  107. data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
  108. data/doc/guides/source/debugging_rails_applications.txt +0 -733
  109. data/doc/guides/source/finders.txt +0 -668
  110. data/doc/guides/source/form_helpers.txt +0 -345
  111. data/doc/guides/source/getting_started_with_rails.txt +0 -1256
  112. data/doc/guides/source/images/belongs_to.png +0 -0
  113. data/doc/guides/source/images/bullet.gif +0 -0
  114. data/doc/guides/source/images/csrf.png +0 -0
  115. data/doc/guides/source/images/habtm.png +0 -0
  116. data/doc/guides/source/images/has_many.png +0 -0
  117. data/doc/guides/source/images/has_many_through.png +0 -0
  118. data/doc/guides/source/images/has_one.png +0 -0
  119. data/doc/guides/source/images/has_one_through.png +0 -0
  120. data/doc/guides/source/images/header_backdrop.png +0 -0
  121. data/doc/guides/source/images/icons/README +0 -5
  122. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  123. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  124. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  125. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  126. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  127. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  128. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  129. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  130. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  131. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  132. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  133. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  134. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  135. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  136. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  137. data/doc/guides/source/images/icons/caution.png +0 -0
  138. data/doc/guides/source/images/icons/example.png +0 -0
  139. data/doc/guides/source/images/icons/home.png +0 -0
  140. data/doc/guides/source/images/icons/important.png +0 -0
  141. data/doc/guides/source/images/icons/next.png +0 -0
  142. data/doc/guides/source/images/icons/note.png +0 -0
  143. data/doc/guides/source/images/icons/prev.png +0 -0
  144. data/doc/guides/source/images/icons/tip.png +0 -0
  145. data/doc/guides/source/images/icons/up.png +0 -0
  146. data/doc/guides/source/images/icons/warning.png +0 -0
  147. data/doc/guides/source/images/polymorphic.png +0 -0
  148. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  149. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  150. data/doc/guides/source/images/session_fixation.png +0 -0
  151. data/doc/guides/source/index.txt +0 -118
  152. data/doc/guides/source/layouts_and_rendering.txt +0 -982
  153. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
  154. data/doc/guides/source/migrations/changelog.txt +0 -5
  155. data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
  156. data/doc/guides/source/migrations/foreign_keys.txt +0 -8
  157. data/doc/guides/source/migrations/index.txt +0 -22
  158. data/doc/guides/source/migrations/rakeing_around.txt +0 -111
  159. data/doc/guides/source/migrations/scheming.txt +0 -47
  160. data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
  161. data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
  162. data/doc/guides/source/routing_outside_in.txt +0 -986
  163. data/doc/guides/source/security.txt +0 -984
  164. data/doc/guides/source/stylesheets/base.css +0 -358
  165. data/doc/guides/source/stylesheets/forms.css +0 -35
  166. data/doc/guides/source/stylesheets/more.css +0 -82
  167. data/doc/guides/source/templates/guides.html.erb +0 -97
  168. data/doc/guides/source/templates/inline.css +0 -165
  169. data/doc/guides/source/testing_rails_applications.txt +0 -995
  170. data/environments/boot.rb +0 -109
  171. data/environments/development.rb +0 -17
  172. data/environments/environment.rb +0 -75
  173. data/environments/production.rb +0 -24
  174. data/environments/test.rb +0 -22
  175. data/fresh_rakefile +0 -10
  176. data/helpers/application.rb +0 -15
  177. data/helpers/application_helper.rb +0 -3
  178. data/helpers/performance_test.rb +0 -9
  179. data/helpers/test_helper.rb +0 -38
  180. data/html/404.html +0 -30
  181. data/html/422.html +0 -30
  182. data/html/500.html +0 -33
  183. data/html/favicon.ico +0 -0
  184. data/html/images/rails.png +0 -0
  185. data/html/index.html +0 -274
  186. data/html/javascripts/application.js +0 -2
  187. data/html/javascripts/controls.js +0 -963
  188. data/html/javascripts/dragdrop.js +0 -973
  189. data/html/javascripts/effects.js +0 -1128
  190. data/html/javascripts/prototype.js +0 -4320
  191. data/html/robots.txt +0 -5
  192. data/lib/code_statistics.rb +0 -107
  193. data/lib/commands.rb +0 -17
  194. data/lib/commands/about.rb +0 -3
  195. data/lib/commands/console.rb +0 -45
  196. data/lib/commands/dbconsole.rb +0 -67
  197. data/lib/commands/destroy.rb +0 -6
  198. data/lib/commands/generate.rb +0 -6
  199. data/lib/commands/ncgi/listener +0 -86
  200. data/lib/commands/ncgi/tracker +0 -69
  201. data/lib/commands/performance/benchmarker.rb +0 -24
  202. data/lib/commands/performance/profiler.rb +0 -50
  203. data/lib/commands/performance/request.rb +0 -6
  204. data/lib/commands/plugin.rb +0 -967
  205. data/lib/commands/process/inspector.rb +0 -68
  206. data/lib/commands/process/reaper.rb +0 -149
  207. data/lib/commands/process/spawner.rb +0 -219
  208. data/lib/commands/process/spinner.rb +0 -57
  209. data/lib/commands/runner.rb +0 -48
  210. data/lib/commands/server.rb +0 -49
  211. data/lib/commands/servers/base.rb +0 -31
  212. data/lib/commands/servers/lighttpd.rb +0 -94
  213. data/lib/commands/servers/mongrel.rb +0 -69
  214. data/lib/commands/servers/new_mongrel.rb +0 -16
  215. data/lib/commands/servers/thin.rb +0 -25
  216. data/lib/commands/servers/webrick.rb +0 -66
  217. data/lib/commands/update.rb +0 -4
  218. data/lib/console_app.rb +0 -30
  219. data/lib/console_sandbox.rb +0 -6
  220. data/lib/console_with_helpers.rb +0 -26
  221. data/lib/dispatcher.rb +0 -24
  222. data/lib/fcgi_handler.rb +0 -237
  223. data/lib/initializer.rb +0 -1038
  224. data/lib/performance_test_help.rb +0 -5
  225. data/lib/rails/gem_builder.rb +0 -21
  226. data/lib/rails/gem_dependency.rb +0 -251
  227. data/lib/rails/mongrel_server/commands.rb +0 -342
  228. data/lib/rails/mongrel_server/handler.rb +0 -55
  229. data/lib/rails/plugin.rb +0 -124
  230. data/lib/rails/plugin/loader.rb +0 -152
  231. data/lib/rails/plugin/locator.rb +0 -100
  232. data/lib/rails/rack.rb +0 -6
  233. data/lib/rails/rack/logger.rb +0 -28
  234. data/lib/rails/rack/static.rb +0 -35
  235. data/lib/rails/vendor_gem_source_index.rb +0 -140
  236. data/lib/rails/version.rb +0 -9
  237. data/lib/rails_generator.rb +0 -43
  238. data/lib/rails_generator/base.rb +0 -263
  239. data/lib/rails_generator/commands.rb +0 -616
  240. data/lib/rails_generator/generated_attribute.rb +0 -46
  241. data/lib/rails_generator/generators/applications/app/USAGE +0 -9
  242. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -184
  243. data/lib/rails_generator/generators/components/controller/USAGE +0 -29
  244. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -37
  245. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
  246. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
  247. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  248. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
  249. data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
  250. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
  251. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
  252. data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
  253. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
  254. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
  255. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  256. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
  257. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
  258. data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
  259. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  260. data/lib/rails_generator/generators/components/migration/USAGE +0 -29
  261. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
  262. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
  263. data/lib/rails_generator/generators/components/model/USAGE +0 -27
  264. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -45
  265. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -19
  266. data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
  267. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
  268. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
  269. data/lib/rails_generator/generators/components/observer/USAGE +0 -13
  270. data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
  271. data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
  272. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
  273. data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
  274. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
  275. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
  276. data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
  277. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
  278. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
  279. data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
  280. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
  281. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  282. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  283. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  284. data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
  285. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  286. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  287. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -3
  288. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
  289. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  290. data/lib/rails_generator/generators/components/resource/USAGE +0 -23
  291. data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -74
  292. data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
  293. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
  294. data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
  295. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
  296. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -100
  297. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -85
  298. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
  299. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  300. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
  301. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
  302. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
  303. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
  304. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
  305. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
  306. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
  307. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
  308. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
  309. data/lib/rails_generator/lookup.rb +0 -249
  310. data/lib/rails_generator/manifest.rb +0 -53
  311. data/lib/rails_generator/options.rb +0 -150
  312. data/lib/rails_generator/scripts.rb +0 -89
  313. data/lib/rails_generator/scripts/destroy.rb +0 -29
  314. data/lib/rails_generator/scripts/generate.rb +0 -7
  315. data/lib/rails_generator/scripts/update.rb +0 -12
  316. data/lib/rails_generator/secret_key_generator.rb +0 -22
  317. data/lib/rails_generator/simple_logger.rb +0 -46
  318. data/lib/rails_generator/spec.rb +0 -44
  319. data/lib/railties_path.rb +0 -1
  320. data/lib/ruby_version_check.rb +0 -17
  321. data/lib/rubyprof_ext.rb +0 -35
  322. data/lib/source_annotation_extractor.rb +0 -102
  323. data/lib/tasks/annotations.rake +0 -20
  324. data/lib/tasks/databases.rake +0 -416
  325. data/lib/tasks/documentation.rake +0 -95
  326. data/lib/tasks/framework.rake +0 -118
  327. data/lib/tasks/gems.rake +0 -80
  328. data/lib/tasks/log.rake +0 -9
  329. data/lib/tasks/misc.rake +0 -56
  330. data/lib/tasks/rails.rb +0 -8
  331. data/lib/tasks/routes.rake +0 -17
  332. data/lib/tasks/statistics.rake +0 -18
  333. data/lib/tasks/testing.rake +0 -139
  334. data/lib/tasks/tmp.rake +0 -37
  335. data/lib/test_help.rb +0 -27
  336. data/lib/webrick_server.rb +0 -156
@@ -1,240 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
- <title>About the Authors</title>
6
- <!--[if lt IE 8]>
7
- <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
8
- <![endif]-->
9
- <link href="stylesheets/base.css" media="screen" rel="Stylesheet" type="text/css" />
10
- <link href="stylesheets/forms.css" media="screen" rel="Stylesheet" type="text/css" />
11
- <link href="stylesheets/more.css" media="screen" rel="Stylesheet" type="text/css" />
12
- <style type="text/css">
13
- div#container {
14
- max-width: 900px;
15
- padding-bottom: 3em;
16
- }
17
-
18
- div#content {
19
- margin-left: 200px;
20
- }
21
-
22
- div#container.notoc {
23
- max-width: 600px;
24
- }
25
-
26
- .notoc div#content {
27
- margin-left: 0;
28
- }
29
-
30
- pre {
31
- line-height: 1.4em;
32
- }
33
-
34
- #content p tt {
35
- background: #eeeeee;
36
- border: solid 1px #cccccc;
37
- padding: 3px;
38
- }
39
-
40
- dt {
41
- font-weight: bold;
42
- }
43
-
44
- #content dt tt {
45
- font-size: 10pt;
46
- }
47
-
48
- dd {
49
- margin-left: 3em;
50
- }
51
-
52
- #content dt tt, #content pre tt {
53
- background: none;
54
- padding: 0;
55
- border: 0;
56
- }
57
-
58
- #content .olist ol {
59
- margin-left: 2em;
60
- }
61
-
62
- #header {
63
- position: relative;
64
- max-width: 840px;
65
- margin-left: auto;
66
- margin-right: auto;
67
- }
68
-
69
- #header.notoc {
70
- max-width: 580px;
71
- }
72
-
73
- #logo {
74
- position: absolute;
75
- left: 10px;
76
- top: 10px;
77
- width: 110px;
78
- height: 140px;
79
- }
80
-
81
- div#header h1#site_title {
82
- background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat;
83
- position: absolute;
84
- width: 392px;
85
- height: 55px;
86
- left: 145px;
87
- top: 20px;
88
- margin: 0;
89
- padding: 0;
90
- }
91
-
92
- #site_title span {
93
- display: none;
94
- }
95
-
96
- #site_title_tagline {
97
- display: none;
98
- }
99
-
100
- ul#navMain {
101
- position: absolute;
102
- margin: 0;
103
- padding: 0;
104
- top: 97px;
105
- left: 145px;
106
- }
107
-
108
- .left-floaty, .right-floaty {
109
- padding: 15px;
110
- }
111
-
112
- .admonitionblock,
113
- .tableblock {
114
- margin-left: 1em;
115
- margin-right: 1em;
116
- margin-top: 0.25em;
117
- margin-bottom: 1em;
118
- }
119
-
120
- .admonitionblock .icon {
121
- padding-right: 8px;
122
- }
123
-
124
- .admonitionblock .content {
125
- border: solid 1px #ffda78;
126
- background: #fffebd;
127
- padding: 10px;
128
- padding-top: 8px;
129
- padding-bottom: 8px;
130
- }
131
-
132
- .admonitionblock .title {
133
- font-size: 140%;
134
- margin-bottom: 0.5em;
135
- }
136
-
137
- .tableblock table {
138
- border: solid 1px #aaaaff;
139
- background: #f0f0ff;
140
- }
141
-
142
- .tableblock th {
143
- background: #e0e0e0;
144
- }
145
-
146
- .tableblock th,
147
- .tableblock td {
148
- padding: 3px;
149
- padding-left: 5px;
150
- padding-right: 5px;
151
- }
152
-
153
- .sidebarblock {
154
- margin-top: 0.25em;
155
- margin: 1em;
156
- border: solid 1px #ccccbb;
157
- padding: 8px;
158
- background: #ffffe0;
159
- }
160
-
161
- .sidebarblock .sidebar-title {
162
- font-size: 140%;
163
- font-weight: 600;
164
- margin-bottom: 0.3em;
165
- }
166
-
167
- .sidebarblock .sidebar-content > .para:last-child > p {
168
- margin-bottom: 0;
169
- }
170
-
171
- .sidebarblock .sidebar-title a {
172
- text-decoration: none;
173
- }
174
-
175
- .sidebarblock .sidebar-title a:hover {
176
- text-decoration: underline;
177
- }
178
-
179
- </style>
180
- </head>
181
- <body>
182
- <div id="header" class="notoc">
183
- <div id="logo">
184
- <a href="index.html" title="Ruby on Rails"><img src="images/rails_logo_remix.gif" alt="Rails" height="140" width="110" /></a>
185
- </div>
186
-
187
- <h1 id="site_title"><span>Ruby on Rails</span></h1>
188
- <h2 id="site_title_tagline">Sustainable productivity for web-application development</h2>
189
-
190
- <ul id="navMain">
191
- <li class="first-child"><a href="http://www.rubyonrails.org/" title="Ruby on Rails" class="ruby_on_rails">Ruby on Rails</a></li>
192
- <li><a class="manuals" href="index.html" title="Manuals Index">Guides Index</a></li>
193
- </ul>
194
- </div>
195
-
196
- <div id="container" class="notoc">
197
-
198
- <div id="content">
199
- <h1>About the Authors</h1>
200
- <div id="preamble">
201
- <div class="sectionbody">
202
- <div class="sidebarblock" id="fcheung">
203
- <div class="sidebar-content">
204
- <div class="sidebar-title">Frederick Cheung</div>
205
- <div class="para"><p>Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006.
206
- He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.</p></div>
207
- </div></div>
208
- <div class="sidebarblock" id="mgunderloy">
209
- <div class="sidebar-content">
210
- <div class="sidebar-title">Mike Gunderloy</div>
211
- <div class="para"><p>Mike Gunderloy is an independent consultant who brings 25 years of experience in a variety of languages to bear on his current
212
- work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a>.</p></div>
213
- </div></div>
214
- <div class="sidebarblock" id="miloops">
215
- <div class="sidebar-content">
216
- <div class="sidebar-title">Emilio Tagua</div>
217
- <div class="para"><p>Emilio Tagua &#8212; a.k.a. miloops &#8212; is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist.
218
- Cofounder of <a href="http://www.eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008.
219
- Can be found at gmail, twitter, freenode, everywhere as miloops.</p></div>
220
- </div></div>
221
- <div class="sidebarblock" id="hawe">
222
- <div class="sidebar-content">
223
- <div class="sidebar-title">Heiko Webers</div>
224
- <div class="para"><p>Heiko Webers is the founder of <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development
225
- company focused on Ruby on Rails. He blogs at <a href="http://www.rorsecurity.info">http://www.rorsecurity.info</a>. After 10 years of desktop application development,
226
- Heiko has rarely looked back.</p></div>
227
- </div></div>
228
- <div class="sidebarblock" id="toretore">
229
- <div class="sidebar-content">
230
- <div class="sidebar-title">Tore Darell</div>
231
- <div class="para"><p>Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails
232
- and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no/">Sneaky Abstractions</a>.</p></div>
233
- </div></div>
234
- </div>
235
- </div>
236
-
237
- </div>
238
- </div>
239
- </body>
240
- </html>
@@ -1,1018 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
- <title>Benchmarking and Profiling Rails</title>
6
- <!--[if lt IE 8]>
7
- <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
8
- <![endif]-->
9
- <link href="stylesheets/base.css" media="screen" rel="Stylesheet" type="text/css" />
10
- <link href="stylesheets/forms.css" media="screen" rel="Stylesheet" type="text/css" />
11
- <link href="stylesheets/more.css" media="screen" rel="Stylesheet" type="text/css" />
12
- <style type="text/css">
13
- div#container {
14
- max-width: 900px;
15
- padding-bottom: 3em;
16
- }
17
-
18
- div#content {
19
- margin-left: 200px;
20
- }
21
-
22
- div#container.notoc {
23
- max-width: 600px;
24
- }
25
-
26
- .notoc div#content {
27
- margin-left: 0;
28
- }
29
-
30
- pre {
31
- line-height: 1.4em;
32
- }
33
-
34
- #content p tt {
35
- background: #eeeeee;
36
- border: solid 1px #cccccc;
37
- padding: 3px;
38
- }
39
-
40
- dt {
41
- font-weight: bold;
42
- }
43
-
44
- #content dt tt {
45
- font-size: 10pt;
46
- }
47
-
48
- dd {
49
- margin-left: 3em;
50
- }
51
-
52
- #content dt tt, #content pre tt {
53
- background: none;
54
- padding: 0;
55
- border: 0;
56
- }
57
-
58
- #content .olist ol {
59
- margin-left: 2em;
60
- }
61
-
62
- #header {
63
- position: relative;
64
- max-width: 840px;
65
- margin-left: auto;
66
- margin-right: auto;
67
- }
68
-
69
- #header.notoc {
70
- max-width: 580px;
71
- }
72
-
73
- #logo {
74
- position: absolute;
75
- left: 10px;
76
- top: 10px;
77
- width: 110px;
78
- height: 140px;
79
- }
80
-
81
- div#header h1#site_title {
82
- background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat;
83
- position: absolute;
84
- width: 392px;
85
- height: 55px;
86
- left: 145px;
87
- top: 20px;
88
- margin: 0;
89
- padding: 0;
90
- }
91
-
92
- #site_title span {
93
- display: none;
94
- }
95
-
96
- #site_title_tagline {
97
- display: none;
98
- }
99
-
100
- ul#navMain {
101
- position: absolute;
102
- margin: 0;
103
- padding: 0;
104
- top: 97px;
105
- left: 145px;
106
- }
107
-
108
- .left-floaty, .right-floaty {
109
- padding: 15px;
110
- }
111
-
112
- .admonitionblock,
113
- .tableblock {
114
- margin-left: 1em;
115
- margin-right: 1em;
116
- margin-top: 0.25em;
117
- margin-bottom: 1em;
118
- }
119
-
120
- .admonitionblock .icon {
121
- padding-right: 8px;
122
- }
123
-
124
- .admonitionblock .content {
125
- border: solid 1px #ffda78;
126
- background: #fffebd;
127
- padding: 10px;
128
- padding-top: 8px;
129
- padding-bottom: 8px;
130
- }
131
-
132
- .admonitionblock .title {
133
- font-size: 140%;
134
- margin-bottom: 0.5em;
135
- }
136
-
137
- .tableblock table {
138
- border: solid 1px #aaaaff;
139
- background: #f0f0ff;
140
- }
141
-
142
- .tableblock th {
143
- background: #e0e0e0;
144
- }
145
-
146
- .tableblock th,
147
- .tableblock td {
148
- padding: 3px;
149
- padding-left: 5px;
150
- padding-right: 5px;
151
- }
152
-
153
- .sidebarblock {
154
- margin-top: 0.25em;
155
- margin: 1em;
156
- border: solid 1px #ccccbb;
157
- padding: 8px;
158
- background: #ffffe0;
159
- }
160
-
161
- .sidebarblock .sidebar-title {
162
- font-size: 140%;
163
- font-weight: 600;
164
- margin-bottom: 0.3em;
165
- }
166
-
167
- .sidebarblock .sidebar-content > .para:last-child > p {
168
- margin-bottom: 0;
169
- }
170
-
171
- .sidebarblock .sidebar-title a {
172
- text-decoration: none;
173
- }
174
-
175
- .sidebarblock .sidebar-title a:hover {
176
- text-decoration: underline;
177
- }
178
-
179
- </style>
180
- </head>
181
- <body>
182
- <div id="header" >
183
- <div id="logo">
184
- <a href="index.html" title="Ruby on Rails"><img src="images/rails_logo_remix.gif" alt="Rails" height="140" width="110" /></a>
185
- </div>
186
-
187
- <h1 id="site_title"><span>Ruby on Rails</span></h1>
188
- <h2 id="site_title_tagline">Sustainable productivity for web-application development</h2>
189
-
190
- <ul id="navMain">
191
- <li class="first-child"><a href="http://www.rubyonrails.org/" title="Ruby on Rails" class="ruby_on_rails">Ruby on Rails</a></li>
192
- <li><a class="manuals" href="index.html" title="Manuals Index">Guides Index</a></li>
193
- </ul>
194
- </div>
195
-
196
- <div id="container">
197
-
198
- <div id="sidebar">
199
- <h2>Chapters</h2>
200
- <ol>
201
- <li>
202
- <a href="#_why_benchmark_and_profile">Why Benchmark and Profile ?</a>
203
- <ul>
204
-
205
- <li><a href="#_what_is_the_difference_between_benchmarking_and_profiling">What is the difference between benchmarking and profiling ?</a></li>
206
-
207
- </ul>
208
- </li>
209
- <li>
210
- <a href="#_using_and_understanding_the_log_files">Using and understanding the log files</a>
211
- </li>
212
- <li>
213
- <a href="#_helper_methods">Helper methods</a>
214
- </li>
215
- <li>
216
- <a href="#_performance_test_cases">Performance Test Cases</a>
217
- <ul>
218
-
219
- <li><a href="#_modes">Modes</a></li>
220
-
221
- <li><a href="#_metrics">Metrics</a></li>
222
-
223
- <li><a href="#_preparing_ruby_and_ruby_prof">Preparing Ruby and Ruby-prof</a></li>
224
-
225
- <li><a href="#_installing_jeremy_kemper_s_ruby_prof">Installing Jeremy Kemper's ruby-prof</a></li>
226
-
227
- <li><a href="#_generating_performance_test">Generating performance test</a></li>
228
-
229
- <li><a href="#_running_tests">Running tests</a></li>
230
-
231
- </ul>
232
- </li>
233
- <li>
234
- <a href="#_understanding_performance_tests_outputs">Understanding Performance Tests Outputs</a>
235
- <ul>
236
-
237
- <li><a href="#_our_first_performance_test">Our First Performance Test</a></li>
238
-
239
- <li><a href="#_flat_files">Flat Files</a></li>
240
-
241
- <li><a href="#_graph_files">Graph Files</a></li>
242
-
243
- <li><a href="#_tree_files">Tree Files</a></li>
244
-
245
- </ul>
246
- </li>
247
- <li>
248
- <a href="#_getting_to_the_point_of_all_of_this">Getting to the Point of all of this</a>
249
- </li>
250
- <li>
251
- <a href="#_real_life_example">Real Life Example</a>
252
- <ul>
253
-
254
- <li><a href="#_the_setup">The setup</a></li>
255
-
256
- </ul>
257
- </li>
258
- <li>
259
- <a href="#_get_yourself_a_game_plan">Get Yourself a Game Plan</a>
260
- <ul>
261
-
262
- <li><a href="#_the_analysis_process">The Analysis Process</a></li>
263
-
264
- </ul>
265
- </li>
266
- <li>
267
- <a href="#_other_profiling_tools">Other Profiling Tools</a>
268
- <ul>
269
-
270
- <li><a href="#_httperf">httperf</a></li>
271
-
272
- <li><a href="#_rails_analyzer">Rails Analyzer</a></li>
273
-
274
- <li><a href="#_palmist">Palmist</a></li>
275
-
276
- <li><a href="#_new_relic">New Relic</a></li>
277
-
278
- </ul>
279
- </li>
280
- <li>
281
- <a href="#_changelog">Changelog</a>
282
- </li>
283
- </ol>
284
- </div>
285
-
286
- <div id="content">
287
- <h1>Benchmarking and Profiling Rails</h1>
288
- <div id="preamble">
289
- <div class="sectionbody">
290
- <div class="para"><p>This guide covers the benchmarking and profiling tactics/tools of Rails and Ruby in general. By referring to this guide, you will be able to:</p></div>
291
- <div class="ilist"><ul>
292
- <li>
293
- <p>
294
- Understand the various types of benchmarking and profiling metrics
295
- </p>
296
- </li>
297
- <li>
298
- <p>
299
- Generate performance/benchmarking tests
300
- </p>
301
- </li>
302
- <li>
303
- <p>
304
- Use GC patched Ruby binary to measure memory usage and object allocation
305
- </p>
306
- </li>
307
- <li>
308
- <p>
309
- Understand the information provided by Rails inside the log files
310
- </p>
311
- </li>
312
- <li>
313
- <p>
314
- Learn about various tools facilitating benchmarking and profiling
315
- </p>
316
- </li>
317
- </ul></div>
318
- </div>
319
- </div>
320
- <h2 id="_why_benchmark_and_profile">1. Why Benchmark and Profile ?</h2>
321
- <div class="sectionbody">
322
- <div class="para"><p>Benchmarking and Profiling is an integral part of the development cycle. It is very important that you don't make your end users wait for too long before the page is completely loaded. Ensuring a plesant browsing experience to the end users and cutting cost of unnecessary hardwares is important for any web application.</p></div>
323
- <h3 id="_what_is_the_difference_between_benchmarking_and_profiling">1.1. What is the difference between benchmarking and profiling ?</h3>
324
- <div class="para"><p>Benchmarking is the process of finding out if a piece of code is slow or not. Whereas profiling is the process of finding out what exactly is slowing down that piece of code.</p></div>
325
- </div>
326
- <h2 id="_using_and_understanding_the_log_files">2. Using and understanding the log files</h2>
327
- <div class="sectionbody">
328
- <div class="para"><p>Rails logs files containt basic but very useful information about the time taken to serve every request. A typical log entry looks something like :</p></div>
329
- <div class="listingblock">
330
- <div class="content"><!-- Generator: GNU source-highlight 2.9
331
- by Lorenzo Bettini
332
- http://www.lorenzobettini.it
333
- http://www.gnu.org/software/src-highlite -->
334
- <pre><tt>Processing ItemsController<span style="font-style: italic"><span style="color: #9A1900">#index (for 127.0.0.1 at 2008-10-17 00:08:18) [GET]</span></span>
335
- Session ID<span style="color: #990000">:</span> BAh7BiIKZmxhc2hJQzonQWN0aHsABjoKQHVzZWR7AA<span style="color: #990000">==--</span>83cff4fe0a897074a65335
336
- Parameters<span style="color: #990000">:</span> <span style="color: #FF0000">{</span><span style="color: #FF0000">"action"</span><span style="color: #990000">=&gt;</span><span style="color: #FF0000">"index"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"controller"</span><span style="color: #990000">=&gt;</span><span style="color: #FF0000">"items"</span><span style="color: #FF0000">}</span>
337
- Rendering template within layouts<span style="color: #990000">/</span>items
338
- Rendering items<span style="color: #990000">/</span>index
339
- Completed <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> 5ms <span style="color: #990000">(</span>View<span style="color: #990000">:</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> DB<span style="color: #990000">:</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #993399">200</span> OK <span style="color: #990000">[</span>http<span style="color: #990000">:</span><span style="color: #FF6600">//localhost/</span>items<span style="color: #990000">]</span>
340
- </tt></pre></div></div>
341
- <div class="para"><p>For this section, we're only interested in the last line from that log entry:</p></div>
342
- <div class="listingblock">
343
- <div class="content"><!-- Generator: GNU source-highlight 2.9
344
- by Lorenzo Bettini
345
- http://www.lorenzobettini.it
346
- http://www.gnu.org/software/src-highlite -->
347
- <pre><tt>Completed <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> 5ms <span style="color: #990000">(</span>View<span style="color: #990000">:</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> DB<span style="color: #990000">:</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #993399">200</span> OK <span style="color: #990000">[</span>http<span style="color: #990000">:</span><span style="color: #FF6600">//localhost/</span>items<span style="color: #990000">]</span>
348
- </tt></pre></div></div>
349
- <div class="para"><p>This data is fairly straight forward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It's safe to assume that the remaining 3 ms were spent inside the controller.</p></div>
350
- </div>
351
- <h2 id="_helper_methods">3. Helper methods</h2>
352
- <div class="sectionbody">
353
- <div class="para"><p>Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a specific code. The method is called <tt>benchmark()</tt> in all three components.</p></div>
354
- <div class="listingblock">
355
- <div class="content"><!-- Generator: GNU source-highlight 2.9
356
- by Lorenzo Bettini
357
- http://www.lorenzobettini.it
358
- http://www.gnu.org/software/src-highlite -->
359
- <pre><tt>Project<span style="color: #990000">.</span>benchmark<span style="color: #990000">(</span><span style="color: #FF0000">"Creating project"</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>
360
- project <span style="color: #990000">=</span> Project<span style="color: #990000">.</span>create<span style="color: #990000">(</span><span style="color: #FF0000">"name"</span> <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"stuff"</span><span style="color: #990000">)</span>
361
- project<span style="color: #990000">.</span>create_manager<span style="color: #990000">(</span><span style="color: #FF0000">"name"</span> <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"David"</span><span style="color: #990000">)</span>
362
- project<span style="color: #990000">.</span>milestones <span style="color: #990000">&lt;&lt;</span> Milestone<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">)</span>
363
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
364
- </tt></pre></div></div>
365
- <div class="para"><p>The above code benchmarks the multiple statments enclosed inside <tt>Project.benchmark("Creating project") do..end</tt> block and prints the results inside log files. The statement inside log files will look like:</p></div>
366
- <div class="listingblock">
367
- <div class="content"><!-- Generator: GNU source-highlight 2.9
368
- by Lorenzo Bettini
369
- http://www.lorenzobettini.it
370
- http://www.gnu.org/software/src-highlite -->
371
- <pre><tt>Creating projectem <span style="color: #990000">(</span><span style="color: #993399">185</span><span style="color: #990000">.</span>3ms<span style="color: #990000">)</span>
372
- </tt></pre></div></div>
373
- <div class="para"><p>Please refer to <a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336">API docs</a> for optional options to <tt>benchmark()</tt></p></div>
374
- <div class="para"><p>Similarly, you could use this helper method inside <a href="http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715">controllers</a> ( Note that it's a class method here ):</p></div>
375
- <div class="listingblock">
376
- <div class="content"><!-- Generator: GNU source-highlight 2.9
377
- by Lorenzo Bettini
378
- http://www.lorenzobettini.it
379
- http://www.gnu.org/software/src-highlite -->
380
- <pre><tt><span style="font-weight: bold"><span style="color: #0000FF">def</span></span> process_projects
381
- <span style="font-weight: bold"><span style="color: #0000FF">self</span></span><span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #0000FF">class</span></span><span style="color: #990000">.</span>benchmark<span style="color: #990000">(</span><span style="color: #FF0000">"Processing projects"</span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>
382
- Project<span style="color: #990000">.</span>process<span style="color: #990000">(</span>params<span style="color: #990000">[:</span>project_ids<span style="color: #990000">])</span>
383
- Project<span style="color: #990000">.</span>update_cached_projects
384
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
385
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
386
- </tt></pre></div></div>
387
- <div class="para"><p>and <a href="http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715">views</a>:</p></div>
388
- <div class="listingblock">
389
- <div class="content"><!-- Generator: GNU source-highlight 2.9
390
- by Lorenzo Bettini
391
- http://www.lorenzobettini.it
392
- http://www.gnu.org/software/src-highlite -->
393
- <pre><tt><span style="color: #FF0000">&lt;% benchmark("Showing projects partial") do %&gt;</span>
394
- <span style="color: #FF0000">&lt;%= render :partial =&gt;</span> <span style="color: #009900">@projects</span> <span style="color: #990000">%&gt;</span>
395
- <span style="color: #FF0000">&lt;% end %&gt;</span>
396
- </tt></pre></div></div>
397
- </div>
398
- <h2 id="_performance_test_cases">4. Performance Test Cases</h2>
399
- <div class="sectionbody">
400
- <div class="para"><p>Rails provides a very easy to write performance test cases, which look just like the regular integration tests.</p></div>
401
- <div class="para"><p>If you have a look at <tt>test/performance/browsing_test.rb</tt> in a newly created Rails application:</p></div>
402
- <div class="listingblock">
403
- <div class="content"><!-- Generator: GNU source-highlight 2.9
404
- by Lorenzo Bettini
405
- http://www.lorenzobettini.it
406
- http://www.gnu.org/software/src-highlite -->
407
- <pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'test_helper'</span>
408
- <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'performance_test_help'</span>
409
-
410
- <span style="font-style: italic"><span style="color: #9A1900"># Profiling results for each test method are written to tmp/performance.</span></span>
411
- <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> BrowsingTest <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>PerformanceTest
412
- <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_homepage
413
- get <span style="color: #FF0000">'/'</span>
414
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
415
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
416
- </tt></pre></div></div>
417
- <div class="para"><p>This is an automatically generated example performance test file, for testing performance of homepage(<em>/</em>) of the application.</p></div>
418
- <h3 id="_modes">4.1. Modes</h3>
419
- <h4 id="_benchmarking">4.1.1. Benchmarking</h4>
420
- <h4 id="_profiling">4.1.2. Profiling</h4>
421
- <h3 id="_metrics">4.2. Metrics</h3>
422
- <h4 id="_process_time">4.2.1. Process Time</h4>
423
- <div class="para"><p>CPU Cycles.</p></div>
424
- <h4 id="_memory">4.2.2. Memory</h4>
425
- <div class="para"><p>Memory taken.</p></div>
426
- <h4 id="_objects">4.2.3. Objects</h4>
427
- <div class="para"><p>Objects allocated.</p></div>
428
- <h4 id="_gc_runs">4.2.4. GC Runs</h4>
429
- <div class="para"><p>Number of times the Ruby GC was run.</p></div>
430
- <h4 id="_gc_time">4.2.5. GC Time</h4>
431
- <div class="para"><p>Time spent running the Ruby GC.</p></div>
432
- <h3 id="_preparing_ruby_and_ruby_prof">4.3. Preparing Ruby and Ruby-prof</h3>
433
- <div class="para"><p>Before we go ahead, Rails performance testing requires you to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time. This process is very straight forward. If you've never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory:</p></div>
434
- <h4 id="_compile">4.3.1. Compile</h4>
435
- <div class="listingblock">
436
- <div class="content"><!-- Generator: GNU source-highlight 2.9
437
- by Lorenzo Bettini
438
- http://www.lorenzobettini.it
439
- http://www.gnu.org/software/src-highlite -->
440
- <pre><tt><span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ mkdir rubygc
441
- <span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ wget ftp<span style="color: #990000">:</span>//ftp<span style="color: #990000">.</span>ruby-lang<span style="color: #990000">.</span>org/pub/ruby<span style="color: #990000">/</span><span style="color: #993399">1.8</span>/ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span><span style="color: #990000">.</span>tar<span style="color: #990000">.</span>gz
442
- <span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ tar -xzvf ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span><span style="color: #990000">.</span>tar<span style="color: #990000">.</span>gz
443
- <span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ cd ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span>
444
- <span style="color: #990000">[</span>lifo@null ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span><span style="color: #990000">]</span>$ curl http<span style="color: #990000">:</span>//rubyforge<span style="color: #990000">.</span>org/tracker/download<span style="color: #990000">.</span>php<span style="color: #990000">/</span><span style="color: #993399">1814</span><span style="color: #990000">/</span><span style="color: #993399">7062</span><span style="color: #990000">/</span><span style="color: #993399">17676</span><span style="color: #990000">/</span><span style="color: #993399">3291</span>/ruby186gc<span style="color: #990000">.</span>patch <span style="color: #990000">|</span> patch -p<span style="color: #993399">0</span>
445
- <span style="color: #990000">[</span>lifo@null ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span><span style="color: #990000">]</span>$ <span style="color: #990000">.</span>/configure --prefix<span style="color: #990000">=</span>/Users/lifo/rubygc
446
- <span style="color: #990000">[</span>lifo@null ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6</span>-p<span style="color: #993399">111</span><span style="color: #990000">]</span>$ make <span style="color: #990000">&amp;&amp;</span> make install
447
- </tt></pre></div></div>
448
- <h4 id="_prepare_aliases">4.3.2. Prepare aliases</h4>
449
- <div class="para"><p>Add the following lines in your ~/.profile for convenience:</p></div>
450
- <div class="listingblock">
451
- <div class="content">
452
- <pre><tt>alias gcruby='/Users/lifo/rubygc/bin/ruby'
453
- alias gcrake='/Users/lifo/rubygc/bin/rake'
454
- alias gcgem='/Users/lifo/rubygc/bin/gem'
455
- alias gcirb='/Users/lifo/rubygc/bin/irb'
456
- alias gcrails='/Users/lifo/rubygc/bin/rails'</tt></pre>
457
- </div></div>
458
- <h4 id="_install_rubygems_and_some_basic_gems">4.3.3. Install rubygems and some basic gems</h4>
459
- <div class="listingblock">
460
- <div class="content">
461
- <pre><tt>[lifo@null ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
462
- [lifo@null ~]$ tar -xzvf rubygems-1.2.0.tgz
463
- [lifo@null ~]$ cd rubygems-1.2.0
464
- [lifo@null rubygems-1.2.0]$ gcruby setup.rb
465
- [lifo@null rubygems-1.2.0]$ cd ~
466
- [lifo@null ~]$ gcgem install rake
467
- [lifo@null ~]$ gcgem install rails</tt></pre>
468
- </div></div>
469
- <h4 id="_install_mysql_gem">4.3.4. Install MySQL gem</h4>
470
- <div class="listingblock">
471
- <div class="content">
472
- <pre><tt>[lifo@null ~]$ gcgem install mysql</tt></pre>
473
- </div></div>
474
- <div class="para"><p>If this fails, you can try to install it manually:</p></div>
475
- <div class="listingblock">
476
- <div class="content">
477
- <pre><tt>[lifo@null ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/
478
- [lifo@null mysql-2.7]$ gcruby extconf.rb --with-mysql-config
479
- [lifo@null mysql-2.7]$ make &amp;&amp; make install</tt></pre>
480
- </div></div>
481
- <h3 id="_installing_jeremy_kemper_s_ruby_prof">4.4. Installing Jeremy Kemper's ruby-prof</h3>
482
- <div class="para"><p>We also need to install Jeremy's ruby-prof gem using our newly built ruby:</p></div>
483
- <div class="listingblock">
484
- <div class="content"><!-- Generator: GNU source-highlight 2.9
485
- by Lorenzo Bettini
486
- http://www.lorenzobettini.it
487
- http://www.gnu.org/software/src-highlite -->
488
- <pre><tt><span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ git clone git<span style="color: #990000">:</span>//github<span style="color: #990000">.</span>com/jeremy/ruby-prof<span style="color: #990000">.</span>git
489
- <span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ cd ruby-prof<span style="color: #990000">/</span>
490
- <span style="color: #990000">[</span>lifo@null ruby-prof <span style="color: #990000">(</span>master<span style="color: #990000">)]</span>$ gcrake gem
491
- <span style="color: #990000">[</span>lifo@null ruby-prof <span style="color: #990000">(</span>master<span style="color: #990000">)]</span>$ gcgem install pkg/ruby-prof-<span style="color: #993399">0.6</span><span style="color: #990000">.</span><span style="color: #993399">1</span><span style="color: #990000">.</span>gem
492
- </tt></pre></div></div>
493
- <h3 id="_generating_performance_test">4.5. Generating performance test</h3>
494
- <div class="para"><p>Rails provides a simple generator for creating new performance tests:</p></div>
495
- <div class="listingblock">
496
- <div class="content"><!-- Generator: GNU source-highlight 2.9
497
- by Lorenzo Bettini
498
- http://www.lorenzobettini.it
499
- http://www.gnu.org/software/src-highlite -->
500
- <pre><tt><span style="color: #990000">[</span>lifo@null application <span style="color: #990000">(</span>master<span style="color: #990000">)]</span>$ script/generate performance_test homepage
501
- </tt></pre></div></div>
502
- <div class="para"><p>This will generate <tt>test/performance/homepage_test.rb</tt>:</p></div>
503
- <div class="listingblock">
504
- <div class="content"><!-- Generator: GNU source-highlight 2.9
505
- by Lorenzo Bettini
506
- http://www.lorenzobettini.it
507
- http://www.gnu.org/software/src-highlite -->
508
- <pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'test_helper'</span>
509
- <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'performance_test_help'</span>
510
-
511
- <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> HomepageTest <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>PerformanceTest
512
- <span style="font-style: italic"><span style="color: #9A1900"># Replace this with your real tests.</span></span>
513
- <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_homepage
514
- get <span style="color: #FF0000">'/'</span>
515
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
516
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
517
- </tt></pre></div></div>
518
- <div class="para"><p>Which you can modify to suit your needs.</p></div>
519
- <h3 id="_running_tests">4.6. Running tests</h3>
520
- </div>
521
- <h2 id="_understanding_performance_tests_outputs">5. Understanding Performance Tests Outputs</h2>
522
- <div class="sectionbody">
523
- <h3 id="_our_first_performance_test">5.1. Our First Performance Test</h3>
524
- <div class="para"><p>So how do we profile a request.</p></div>
525
- <div class="para"><p>One of the things that is important to us is how long it takes to render the home page - so let's make a request to the home page. Once the request is complete, the results will be outputted in the terminal.</p></div>
526
- <div class="para"><p>In the terminal run</p></div>
527
- <div class="listingblock">
528
- <div class="content"><!-- Generator: GNU source-highlight 2.9
529
- by Lorenzo Bettini
530
- http://www.lorenzobettini.it
531
- http://www.gnu.org/software/src-highlite -->
532
- <pre><tt><span style="color: #990000">[</span>User profiling_tester<span style="color: #990000">]</span>$ gcruby tests<span style="color: #FF6600">/performance/</span>homepage<span style="color: #990000">.</span>rb
533
- </tt></pre></div></div>
534
- <div class="para"><p>After the tests runs for a few seconds you should see something like this.</p></div>
535
- <div class="listingblock">
536
- <div class="content">
537
- <pre><tt>HomepageTest#test_homepage (19 ms warmup)
538
- process_time: 26 ms
539
- memory: 298.79 KB
540
- objects: 1917
541
-
542
- Finished in 2.207428 seconds.</tt></pre>
543
- </div></div>
544
- <div class="para"><p>Simple but efficient.</p></div>
545
- <div class="ilist"><ul>
546
- <li>
547
- <p>
548
- Process Time refers to amount of time necessary to complete the action.
549
- </p>
550
- </li>
551
- <li>
552
- <p>
553
- memory is the amount of information loaded into memory
554
- </p>
555
- </li>
556
- <li>
557
- <p>
558
- object ??? #TODO find a good definition. Is it the amount of objects put into a ruby heap for this process?
559
- </p>
560
- </li>
561
- </ul></div>
562
- <div class="para"><p>In addition we also gain three types of itemized log files for each of these outputs. They can be found in your tmp directory of your application.</p></div>
563
- <div class="para"><p><strong>The Three types are</strong></p></div>
564
- <div class="ilist"><ul>
565
- <li>
566
- <p>
567
- Flat File - A simple text file with the data laid out in a grid
568
- </p>
569
- </li>
570
- <li>
571
- <p>
572
- Graphical File - A html colored coded version of the simple text file with hyperlinks between the various methods. Most useful is the bolding of the main processes for each portion of the action.
573
- </p>
574
- </li>
575
- <li>
576
- <p>
577
- Tree File - A file output that can be use in conjunction with KCachegrind to visualize the process
578
- </p>
579
- </li>
580
- </ul></div>
581
- <div class="admonitionblock">
582
- <table><tr>
583
- <td class="icon">
584
- <img src="./images/icons/note.png" alt="Note" />
585
- </td>
586
- <td class="content">KCachegrind is Linux only. For Mac this means you have to do a full KDE install to have it working in your OS. Which is over 3 gigs in size. For windows there is clone called wincachegrind but it is no longer actively being developed.</td>
587
- </tr></table>
588
- </div>
589
- <div class="para"><p>Below are examples for Flat Files and Graphical Files</p></div>
590
- <h3 id="_flat_files">5.2. Flat Files</h3>
591
- <div class="exampleblock">
592
- <div class="title">Example: Flat File Output Processing Time</div>
593
- <div class="exampleblock-content">
594
- <div class="para"><p>Thread ID: 2279160
595
- Total: 0.026097</p></div>
596
- <div class="literalblock">
597
- <div class="content">
598
- <pre><tt>%self total self wait child calls name
599
- 6.41 0.06 0.04 0.00 0.02 571 Kernel#===
600
- 3.17 0.00 0.00 0.00 0.00 172 Hash#[]
601
- 2.42 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_exit
602
- 2.05 0.00 0.00 0.00 0.00 15 Array#each
603
- 1.56 0.00 0.00 0.00 0.00 6 Logger#add
604
- 1.55 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_enter
605
- 1.36 0.03 0.00 0.00 0.03 1 ActionController::Integration::Session#process
606
- 1.31 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_release
607
- 1.15 0.00 0.00 0.00 0.00 8 MonitorMixin#synchronize-1
608
- 1.09 0.00 0.00 0.00 0.00 23 Class#new
609
- 1.03 0.01 0.00 0.00 0.01 5 MonitorMixin#synchronize
610
- 0.89 0.00 0.00 0.00 0.00 74 Hash#default
611
- 0.89 0.00 0.00 0.00 0.00 6 Hodel3000CompliantLogger#format_message
612
- 0.80 0.00 0.00 0.00 0.00 9 c
613
- 0.80 0.00 0.00 0.00 0.00 11 ActiveRecord::ConnectionAdapters::ConnectionHandler#retrieve_connection_pool
614
- 0.79 0.01 0.00 0.00 0.01 1 ActionController::Benchmarking#perform_action_without_rescue
615
- 0.18 0.00 0.00 0.00 0.00 17 &lt;Class::Object&gt;#allocate</tt></pre>
616
- </div></div>
617
- </div></div>
618
- <div class="para"><p>So what do these columns tell us:</p></div>
619
- <div class="ilist"><ul>
620
- <li>
621
- <p>
622
- %self - The percentage of time spent processing the method. This is derived from self_time/total_time
623
- </p>
624
- </li>
625
- <li>
626
- <p>
627
- total - The time spent in this method and its children.
628
- </p>
629
- </li>
630
- <li>
631
- <p>
632
- self - The time spent in this method.
633
- </p>
634
- </li>
635
- <li>
636
- <p>
637
- wait - Time processed was queued
638
- </p>
639
- </li>
640
- <li>
641
- <p>
642
- child - The time spent in this method's children.
643
- </p>
644
- </li>
645
- <li>
646
- <p>
647
- calls - The number of times this method was called.
648
- </p>
649
- </li>
650
- <li>
651
- <p>
652
- name - The name of the method.
653
- </p>
654
- </li>
655
- </ul></div>
656
- <div class="para"><p>Name can be displayed three seperate ways:
657
- <strong> #toplevel - The root method that calls all other methods
658
- </strong> MyObject#method - Example Hash#each, The class Hash is calling the method each
659
- * &lt;Object:MyObject&gt;#test - The &lt;&gt; characters indicate a singleton method on a singleton class. Example &lt;Class::Object&gt;#allocate</p></div>
660
- <div class="para"><p>Methods are sorted based on %self. Hence the ones taking the most time and resources will be at the top.</p></div>
661
- <div class="para"><p>So for Array#each which is calling each on the class array. We find that it processing time is 2% of the total and was called 15 times. The rest of the information is 0.00 because the process is so fast it isn't recording times less then 100 ms.</p></div>
662
- <div class="exampleblock">
663
- <div class="title">Example: Flat File Memory Output</div>
664
- <div class="exampleblock-content">
665
- <div class="para"><p>Thread ID: 2279160
666
- Total: 509.724609</p></div>
667
- <div class="literalblock">
668
- <div class="content">
669
- <pre><tt>%self total self wait child calls name
670
- 4.62 23.57 23.57 0.00 0.00 34 String#split
671
- 3.95 57.66 20.13 0.00 37.53 3 &lt;Module::YAML&gt;#quick_emit
672
- 2.82 23.70 14.35 0.00 9.34 2 &lt;Module::YAML&gt;#quick_emit-1
673
- 1.37 35.87 6.96 0.00 28.91 1 ActionView::Helpers::FormTagHelper#form_tag
674
- 1.35 7.69 6.88 0.00 0.81 1 ActionController::HttpAuthentication::Basic::ControllerMethods#authenticate_with_http_basic
675
- 1.06 6.09 5.42 0.00 0.67 90 String#gsub
676
- 1.01 5.13 5.13 0.00 0.00 27 Array#-</tt></pre>
677
- </div></div>
678
- </div></div>
679
- <div class="para"><p>Very similar to the processing time format. The main difference here is that instead of calculating time we are now concerned with the amount of KB put into memory <strong>(or is it strictly into the heap) can I get clarification on this minor point?</strong></p></div>
680
- <div class="para"><p>So for &lt;Module::YAML&gt;#quick_emit which is singleton method on the class YAML it uses 57.66 KB in total, 23.57 through its own actions, 6.69 from actions it calls itself and that it was called twice.</p></div>
681
- <div class="exampleblock">
682
- <div class="title">Example: Flat File Objects</div>
683
- <div class="exampleblock-content">
684
- <div class="para"><p>Thread ID: 2279160
685
- Total: 6537.000000</p></div>
686
- <div class="literalblock">
687
- <div class="content">
688
- <pre><tt>%self total self wait child calls name
689
- 15.16 1096.00 991.00 0.00 105.00 66 Hash#each
690
- 5.25 343.00 343.00 0.00 0.00 4 Mysql::Result#each_hash
691
- 4.74 2203.00 310.00 0.00 1893.00 42 Array#each
692
- 3.75 4529.00 245.00 0.00 4284.00 1 ActionView::Base::CompiledTemplates#_run_erb_47app47views47layouts47application46html46erb
693
- 2.00 136.00 131.00 0.00 5.00 90 String#gsub
694
- 1.73 113.00 113.00 0.00 0.00 34 String#split
695
- 1.44 111.00 94.00 0.00 17.00 31 Array#each-1</tt></pre>
696
- </div></div>
697
- </div></div>
698
- <div class="literalblock">
699
- <div class="content">
700
- <pre><tt>#TODO Find correct terminology for how to describe what this is exactly profiling as in are there really 2203 array objects or 2203 pointers to array objects?.</tt></pre>
701
- </div></div>
702
- <h3 id="_graph_files">5.3. Graph Files</h3>
703
- <div class="para"><p>While the information gleamed from flat files is very useful we still don't know which processes each method is calling. We only know how many. This is not true for a graph file. Below is a text representation of a graph file. The actual graph file is an html entity and an example of which can be found <a href="examples/graph.html">Here</a></p></div>
704
- <div class="para"><p>#TODO (Handily the graph file has links both between it many processes and to the files that actually contain them for debugging.
705
- )</p></div>
706
- <div class="exampleblock">
707
- <div class="title">Example: Graph File</div>
708
- <div class="exampleblock-content">
709
- <div class="para"><p>Thread ID: 21277412</p></div>
710
- <div class="literalblock">
711
- <div class="content">
712
- <pre><tt> %total %self total self children calls Name
713
- /____________________________________________________________________________/
714
- 100.00% 0.00% 8.77 0.00 8.77 1 #toplevel*
715
- 8.77 0.00 8.77 1/1 Object#run_primes
716
- /____________________________________________________________________________/
717
- 8.77 0.00 8.77 1/1 #toplevel
718
- 100.00% 0.00% 8.77 0.00 8.77 1 Object#run_primes*
719
- 0.02 0.00 0.02 1/1 Object#make_random_array
720
- 2.09 0.00 2.09 1/1 Object#find_largest
721
- 6.66 0.00 6.66 1/1 Object#find_primes
722
- /____________________________________________________________________________/
723
- 0.02 0.02 0.00 1/1 Object#make_random_array
724
- 0.18% 0.18% 0.02 0.02 0.00 1 Array#each_index
725
- 0.00 0.00 0.00 500/500 Kernel.rand
726
- 0.00 0.00 0.00 500/501 Array#[]=
727
- /____________________________________________________________________________/</tt></pre>
728
- </div></div>
729
- </div></div>
730
- <div class="para"><p>As you can see the calls have been separated into slices, no longer is the order determined by process time but instead from hierarchy. Each slice profiles a primary entry, with the primary entry's parents being shown above itself and it's children found below. A primary entry can be ascertained by it having values in the %total and %self columns. Here the main entry here have been bolded for connivence.</p></div>
731
- <div class="para"><p>So if we look at the last slice. The primary entry would be Array#each_index. It takes 0.18% of the total process time and it is only called once. It is called from Object#make_random_array which is only called once. It's children are Kernal.rand which is called by it all 500 its times that it was call in this action and Arry#[]= which was called 500 times by Array#each_index and once by some other entry.</p></div>
732
- <h3 id="_tree_files">5.4. Tree Files</h3>
733
- <div class="para"><p>It's pointless trying to represent a tree file textually so here's a few pretty pictures of it's usefulness</p></div>
734
- <div class="para"><div class="title">KCachegrind Graph</div><p><span class="image">
735
- <img src="images/kgraph.png" alt="Graph created by KCachegrind" title="Graph created by KCachegrind" />
736
- </span></p></div>
737
- <div class="para"><div class="title">KCachegrind List</div><p><span class="image">
738
- <img src="images/klist.png" alt="List created by KCachegrind" title="List created by KCachegrind" />
739
- </span></p></div>
740
- <div class="para"><p>#TODO Add a bit more information to this.</p></div>
741
- </div>
742
- <h2 id="_getting_to_the_point_of_all_of_this">6. Getting to the Point of all of this</h2>
743
- <div class="sectionbody">
744
- <div class="para"><p>Now I know all of this is a bit dry and academic. But it's a very powerful tool when you know how to leverage it properly. Which we are going to take a look at in our next section</p></div>
745
- </div>
746
- <h2 id="_real_life_example">7. Real Life Example</h2>
747
- <div class="sectionbody">
748
- <h3 id="_the_setup">7.1. The setup</h3>
749
- <div class="para"><p>So I have been building this application for the last month and feel pretty good about the ruby code. I'm readying it for beta testers when I discover to my shock that with less then twenty people it starts to crash. It's a pretty simple Ecommerce site so I'm very confused by what I'm seeing. On running looking through my log files I find to my shock that the lowest time for a page run is running around 240 ms. My database finds aren't the problems so I'm lost as to what is happening to cause all this. Lets run a benchmark.</p></div>
750
- <div class="listingblock">
751
- <div class="content"><!-- Generator: GNU source-highlight 2.9
752
- by Lorenzo Bettini
753
- http://www.lorenzobettini.it
754
- http://www.gnu.org/software/src-highlite -->
755
- <pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> HomepageTest <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>PerformanceTest
756
- <span style="font-style: italic"><span style="color: #9A1900"># Replace this with your real tests.</span></span>
757
- <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_homepage
758
- get <span style="color: #FF0000">'/'</span>
759
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
760
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
761
- </tt></pre></div></div>
762
- <div class="listingblock">
763
- <div class="title">Example: Output</div>
764
- <div class="content">
765
- <pre><tt>HomepageTest#test_homepage (115 ms warmup)
766
- process_time: 591 ms
767
- memory: 3052.90 KB
768
- objects: 59471</tt></pre>
769
- </div></div>
770
- <div class="para"><p>Obviously something is very very wrong here. 3052.90 Kb to load my minimal homepage. For Comparison for another site running well I get this for my homepage test.</p></div>
771
- <div class="listingblock">
772
- <div class="title">Example: Default</div>
773
- <div class="content">
774
- <pre><tt>HomepageTest#test_homepage (19 ms warmup)
775
- process_time: 26 ms
776
- memory: 298.79 KB
777
- objects: 1917</tt></pre>
778
- </div></div>
779
- <div class="para"><p>that over a factor of ten difference. Lets look at our flat process time file to see if anything pops out at us.</p></div>
780
- <div class="listingblock">
781
- <div class="title">Example: Process time</div>
782
- <div class="content">
783
- <pre><tt>20.73 0.39 0.12 0.00 0.27 420 Pathname#cleanpath_aggressive
784
- 17.07 0.14 0.10 0.00 0.04 3186 Pathname#chop_basename
785
- 6.47 0.06 0.04 0.00 0.02 6571 Kernel#===
786
- 5.04 0.06 0.03 0.00 0.03 840 Pathname#initialize
787
- 5.03 0.05 0.03 0.00 0.02 4 ERB::Compiler::ExplicitScanner#scan
788
- 4.51 0.03 0.03 0.00 0.00 9504 String#==
789
- 2.94 0.46 0.02 0.00 0.44 1393 String#gsub
790
- 2.66 0.09 0.02 0.00 0.07 480 Array#each
791
- 2.46 0.01 0.01 0.00 0.00 3606 Regexp#to_s</tt></pre>
792
- </div></div>
793
- <div class="para"><p>Yes indeed we seem to have found the problem. Pathname#cleanpath_aggressive is taking nearly a quarter our process time and Pathname#chop_basename another 17%. From here I do a few more benchmarks to make sure that these processes are slowing down the other pages. They are so now I know what I must do. <strong>If we can get rid of or shorten these processes we can make our pages run much quicker</strong>.</p></div>
794
- <div class="para"><p>Now both of these are main ruby processes so are goal right now is to find out what other process is calling them. Glancing at our Graph file I see that #cleanpath is calling #cleanpath_aggressive. #cleanpath is being called by String#gsub and from there some html template errors. But my page seems to be rendering fine. why would it be calling template errors. I'm decide to check my object flat file to see if I can find any more information.</p></div>
795
- <div class="listingblock">
796
- <div class="title">Example: Objects Created</div>
797
- <div class="content">
798
- <pre><tt>20.74 34800.00 12324.00 0.00 22476.00 420 Pathname#cleanpath_aggressive
799
- 16.79 18696.00 9978.00 0.00 8718.00 3186 Pathname#chop_basename
800
- 11.47 13197.00 6813.00 0.00 6384.00 480 Array#each
801
- 8.51 41964.00 5059.00 0.00 36905.00 1386 String#gsub
802
- 6.07 3606.00 3606.00 0.00 0.00 3606 Regexp#to_s</tt></pre>
803
- </div></div>
804
- <div class="para"><p>nope nothing new here. Lets look at memory usage</p></div>
805
- <div class="listingblock">
806
- <div class="title">Example: Memory Consuption</div>
807
- <div class="content">
808
- <pre><tt> 40.17 1706.80 1223.70 0.00 483.10 3186 Pathname#chop_basename
809
- 14.92 454.47 454.47 0.00 0.00 3606 Regexp#to_s
810
- 7.09 2381.36 215.99 0.00 2165.37 1386 String#gsub
811
- 5.08 231.19 154.73 0.00 76.46 420 Pathname#prepend_prefix
812
- 2.34 71.35 71.35 0.00 0.00 1265 String#initialize_copy</tt></pre>
813
- </div></div>
814
- <div class="para"><p>Ok so it seems Regexp#to_s is the second costliest process. At this point I try to figure out what could be calling a regular expression cause I very rarely use them. Going over my standard layout I discover at the top.</p></div>
815
- <div class="listingblock">
816
- <div class="content"><!-- Generator: GNU source-highlight 2.9
817
- by Lorenzo Bettini
818
- http://www.lorenzobettini.it
819
- http://www.gnu.org/software/src-highlite -->
820
- <pre><tt>&lt;%if request.env["HTTP_USER_AGENT"].match(/Opera/)%&gt;
821
- &lt;%= stylesheet_link_tag "opera" %&gt;
822
- &lt;% end %&gt;
823
- </tt></pre></div></div>
824
- <div class="para"><p>That's wrong. I mistakenly am using a search function for a simple compare function. Lets fix that.</p></div>
825
- <div class="listingblock">
826
- <div class="content"><!-- Generator: GNU source-highlight 2.9
827
- by Lorenzo Bettini
828
- http://www.lorenzobettini.it
829
- http://www.gnu.org/software/src-highlite -->
830
- <pre><tt>&lt;%if request.env["HTTP_USER_AGENT"] =~ /Opera/%&gt;
831
- &lt;%= stylesheet_link_tag "opera" %&gt;
832
- &lt;% end %&gt;
833
- </tt></pre></div></div>
834
- <div class="para"><p>I'll now try my test again.</p></div>
835
- <div class="listingblock">
836
- <div class="content">
837
- <pre><tt>process_time: 75 ms
838
- memory: 519.95 KB
839
- objects: 6537</tt></pre>
840
- </div></div>
841
- <div class="para"><p>Much better. The problem has been solved. Now I should have realized earlier due to the String#gsub that my problem had to be with reqexp serch function but such knowledge comes with time. Looking through the mass output data is a skill.</p></div>
842
- </div>
843
- <h2 id="_get_yourself_a_game_plan">8. Get Yourself a Game Plan</h2>
844
- <div class="sectionbody">
845
- <div class="para"><p>You end up dealing with a large amount of data whenever you profile an application. It's crucial to use a rigorous approach to analyzing your application's performance else fail miserably in a vortex of numbers. This leads us to -</p></div>
846
- <h3 id="_the_analysis_process">8.1. The Analysis Process</h3>
847
- <div class="para"><p>I’m going to give an example methodology for conducting your benchmarking and profiling on an application. It is based on your typical scientific method.</p></div>
848
- <div class="para"><p>For something as complex as Benchmarking you need to take any methodology with a grain of salt but there are some basic strictures that you can depend on.</p></div>
849
- <div class="para"><p>Formulate a question you need to answer which is simple, tests the smallest measurable thing possible, and is exact. This is typically the hardest part of the experiment. From there some steps that you should follow are.</p></div>
850
- <div class="ilist"><ul>
851
- <li>
852
- <p>
853
- Develop a set of variables and processes to measure in order to answer this question!
854
- </p>
855
- </li>
856
- <li>
857
- <p>
858
- Profile based on the question and variables. Key problems to avoid when designing this experiment are:
859
- </p>
860
- <div class="ilist"><ul>
861
- <li>
862
- <p>
863
- Confounding: Test one thing at a time, keep everything the same so you don't poison the data with uncontrolled processes.
864
- </p>
865
- </li>
866
- <li>
867
- <p>
868
- Cross Contamination: Make sure that runs from one test do not harm the other tests.
869
- </p>
870
- </li>
871
- <li>
872
- <p>
873
- Steady States: If you’re testing long running process. You must take the ramp up time and performance hit into your initial measurements.
874
- </p>
875
- </li>
876
- <li>
877
- <p>
878
- Sampling Error: Data should perform have a steady variance or range. If you get wild swings or sudden spikes, etc. then you must either account for the reason why or you have a sampling error.
879
- </p>
880
- </li>
881
- <li>
882
- <p>
883
- Measurement Error: Aka Human error, always go through your calculations at least twice to make sure there are no mathematical errors. .
884
- </p>
885
- </li>
886
- </ul></div>
887
- </li>
888
- <li>
889
- <p>
890
- Do a small run of the experiment to verify the design.
891
- </p>
892
- </li>
893
- <li>
894
- <p>
895
- Use the small run to determine a proper sample size.
896
- </p>
897
- </li>
898
- <li>
899
- <p>
900
- Run the test.
901
- </p>
902
- </li>
903
- <li>
904
- <p>
905
- Perform the analysis on the results and determine where to go from there.
906
- </p>
907
- </li>
908
- </ul></div>
909
- <div class="para"><p>Note: Even though we are using the typical scientific method; developing a hypothesis is not always useful in terms of profiling.</p></div>
910
- </div>
911
- <h2 id="_other_profiling_tools">9. Other Profiling Tools</h2>
912
- <div class="sectionbody">
913
- <div class="para"><p>There are a lot of great profiling tools out there. Some free, some not so free. This is a sort list detailing some of them.</p></div>
914
- <h3 id="_httperf">9.1. httperf</h3>
915
- <div class="para"><p><a href="http://www.hpl.hp.com/research/linux/httperf/">http://www.hpl.hp.com/research/linux/httperf/</a></p></div>
916
- <div class="para"><p>A necessary tool in your arsenal. Very useful for load testing your website.</p></div>
917
- <div class="para"><p>#TODO write and link to a short article on how to use httperf. Anybody have a good tutorial availble.</p></div>
918
- <h3 id="_rails_analyzer">9.2. Rails Analyzer</h3>
919
- <div class="para"><p>The Rails Analyzer project contains a collection of tools for Rails. It's open source and pretty speedy. It's not being actively worked on but is still contains some very useful tools.</p></div>
920
- <div class="ilist"><ul>
921
- <li>
922
- <p>
923
- The Production Log Analyzer examines Rails log files and gives back a report. It also includes action_grep which will give you all log results for a particular action.
924
- </p>
925
- </li>
926
- <li>
927
- <p>
928
- The Action Profiler similar to Ruby-Prof profiler.
929
- </p>
930
- </li>
931
- <li>
932
- <p>
933
- rails_stat which gives a live counter of requests per second of a running Rails app.
934
- </p>
935
- </li>
936
- <li>
937
- <p>
938
- The SQL Dependency Grapher allows you to visualize the frequency of table dependencies in a Rails application.
939
- </p>
940
- </li>
941
- </ul></div>
942
- <div class="para"><p>Their project homepage can be found at <a href="http://rails-analyzer.rubyforge.org/">http://rails-analyzer.rubyforge.org/</a></p></div>
943
- <div class="para"><p>The one major caveat is that it needs your log to be in a different format from how rails sets it up specifically SyslogLogger.</p></div>
944
- <h4 id="_sysloglogger">9.2.1. SyslogLogger</h4>
945
- <div class="para"><p>SyslogLogger is a Logger work-alike that logs via syslog instead of to a file. You can add SyslogLogger to your Rails production environment to aggregate logs between multiple machines.</p></div>
946
- <div class="para"><p>More information can be found out at <a href="http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html">http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html</a></p></div>
947
- <div class="para"><p>If you don't have access to your machines root system or just want something a bit easier to implement there is also a module developed by Geoffrey Grosenbach</p></div>
948
- <h4 id="_a_hodel_3000_compliant_logger_for_the_rest_of_us">9.2.2. A Hodel 3000 Compliant Logger for the Rest of Us</h4>
949
- <div class="para"><p>Directions taken from
950
- <a href="http://topfunky.net/svn/plugins/hodel_3000_compliant_logger/lib/hodel_3000_compliant_logger.rb">link to module file</a></p></div>
951
- <div class="para"><p>Just put the module in your lib directory and add this to your environment.rb in it's config portion.</p></div>
952
- <div class="listingblock">
953
- <div class="content">
954
- <pre><tt>require 'hodel_3000_compliant_logger'
955
- config.logger = Hodel3000CompliantLogger.new(config.log_path)</tt></pre>
956
- </div></div>
957
- <div class="para"><p>It's that simple. Your log output on restart should look like this.</p></div>
958
- <div class="listingblock">
959
- <div class="title">Example: Hodel 3000 Example</div>
960
- <div class="content">
961
- <pre><tt>Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
962
- Parameters: {"action"=&gt;"shipping", "controller"=&gt;"checkout"}
963
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
964
- [4;36;1mBook Columns (0.003155) SHOW FIELDS FROM `books`
965
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
966
- [4;35;1mBook Load (0.000881) SELECT * FROM `books` WHERE (`books`.`id` = 1 AND (`books`.`sold` = 1)) 
967
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
968
- [4;36;1mShippingAddress Columns (0.002683) SHOW FIELDS FROM `shipping_addresses`
969
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
970
- [4;35;1mBook Load (0.000362) SELECT ounces FROM `books` WHERE (`books`.`id` = 1) 
971
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
972
- Rendering template within layouts/application
973
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
974
- Rendering checkout/shipping
975
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
976
- [4;36;1mBook Load (0.000548) SELECT * FROM `books`
977
- WHERE (sold = 0) LIMIT 3
978
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: 
979
- [4;35;1mAuthor Columns (0.002571) SHOW FIELDS FROM `authors`
980
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
981
- Author Load (0.000811) SELECT * FROM `authors` WHERE (`authors`.`id` = 1) 
982
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
983
- Rendered store/_new_books (0.01358)
984
- Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:
985
- Completed in 0.37297 (2 reqs/sec) | Rendering: 0.02971 (7%) | DB: 0.01697 (4%) | 200 OK [https://secure.jeffbooks/checkout/shipping]</tt></pre>
986
- </div></div>
987
- <h3 id="_palmist">9.3. Palmist</h3>
988
- <div class="para"><p>An open source mysql query analyzer. Full featured and easy to work with. Also requires Hodel 3000
989
- <a href="http://www.flyingmachinestudios.com/projects/">http://www.flyingmachinestudios.com/projects/</a></p></div>
990
- <h3 id="_new_relic">9.4. New Relic</h3>
991
- <div class="para"><p><a href="http://www.newrelic.com/">http://www.newrelic.com/</a></p></div>
992
- <div class="para"><p>Pretty nifty performance tools, pricey though. They do have a basic free
993
- service both for when in development and when you put your application into production. Very simple installation and signup.</p></div>
994
- <div class="para"><p>#TODO more in-depth without being like an advertisement.</p></div>
995
- <h4 id="_manage">9.4.1. Manage</h4>
996
- <div class="para"><p>Like new relic a production monitoring tool.</p></div>
997
- </div>
998
- <h2 id="_changelog">10. Changelog</h2>
999
- <div class="sectionbody">
1000
- <div class="para"><p><a href="http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4">Lighthouse ticket</a></p></div>
1001
- <div class="ilist"><ul>
1002
- <li>
1003
- <p>
1004
- October 17, 2008: First revision by Pratik
1005
- </p>
1006
- </li>
1007
- <li>
1008
- <p>
1009
- September 6, 2008: Initial version by Matthew Bergman &lt;<a href="mailto:MzbPhoto@gmail.com">MzbPhoto@gmail.com</a>&gt;
1010
- </p>
1011
- </li>
1012
- </ul></div>
1013
- </div>
1014
-
1015
- </div>
1016
- </div>
1017
- </body>
1018
- </html>