aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/bechmarking and profiling/Basics.html
blob: 5cf3939fd62c6994f9cafb36c006869f6941ed8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.2.7" />
<style type="text/css">

.admin {
  display:none;
}
 
#navAuthor {
  text-align: right;
}
 
.bookinfo, .userinfo, pre {
  padding: 10px;
  background: #eee;
  border: 1px solid #ccc;
}
 
pre { 
  overflow: auto; 
}
 
#content pre, #content ul {
  margin-bottom: 10px;
}
 
#content ol>ol {
  padding-left : 30px;
}
 
div#header h1 a{
	color: #333333;
	text-decoration:  none;		
}
 
div#header p a{
  text-decoration:  none;
	color:            #999;
}
 
.left-floaty {
  padding: 3px 15px;
  float:left;
}
 
.right-floaty {
  float:right;
  padding: 3px 15px;
}
 
.figure {
  border: 1px solid black;
  line-height: normal;
  background: #FFE;
  margin: 1em;
}
 
.figure .caption {
  background: #B00;
  color: white;
  font-weight: bold;
  padding: 4px 24px 4px 8px;
  margin-left: -4px;
  border: 1px dotted #F77;
}
 
.figure .body {
  padding: 0.5em;
  margin-top: 0.5em;
}
 
.figure pre {
  padding: 0px;
  background: transparent;
  border: none;
  font-size: small;
  font-family: mono;
}
 
.figure .lineno {
  text-align: right;
  color: #B00;
  font-family: mono;
  font-size: small;
  padding-right: 1em;
}
.admin {
  display:none;
}
 
#navAuthor {
  text-align: right;
}
 
.bookinfo, .userinfo, pre {
  padding: 10px;
  background: #eee;
  border: 1px solid #ccc;
}
 
pre { 
  overflow: auto; 
}
 
#content pre, #content ul {
  margin-bottom: 10px;
}
 
#content ol>ol {
  padding-left : 30px;
}
 
div#header h1 a{
	color: #333333;
	text-decoration:  none;		
}
 
div#header p a{
  text-decoration:  none;
	color:            #999;
}
 
.left-floaty {
  padding: 3px 15px;
  float:left;
}
 
.right-floaty {
  float:right;
  padding: 3px 15px;
}
 
.figure {
  border: 1px solid black;
  line-height: normal;
  background: #FFE;
  margin: 1em;
}
 
.figure .caption {
  background: #B00;
  color: white;
  font-weight: bold;
  padding: 4px 24px 4px 8px;
  margin-left: -4px;
  border: 1px dotted #F77;
}
 
.figure .body {
  padding: 0.5em;
  margin-top: 0.5em;
}
 
.figure pre {
  padding: 0px;
  background: transparent;
  border: none;
  font-size: small;
  font-family: mono;
}
 
.figure .lineno {
  text-align: right;
  color: #B00;
  font-family: mono;
  font-size: small;
  padding-right: 1em;
}
</style>
<title>Easy way to start on the road to Practical Benchmarking</title>
</head>
<body>
<div id="header">
<h1>Easy way to start on the road to Practical Benchmarking</h1>
</div>
<div id="preamble">
<div class="sectionbody">
<div class="para"><p>So how do we start gathering this data? You already have been. Your logs are not just for error detection.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Processing MediaController#index (for 127.0.0.1 at 2008-07-17 21:30:21) [GET]
  Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--cb57dad9c5e4704f0e1eddb3d498fef544faaf46
  Parameters: {"action"=&gt;"index", "controller"=&gt;"media"}
  Product Columns (0.003187)   SHOW FIELDS FROM `products`
  Product Load (0.000597)   SELECT * FROM `products` WHERE (`products`.`name` = 'Escape Plane') LIMIT 1
Rendering template within layouts/standard
Rendering media/index
  Track Load (0.001507)   SELECT * FROM `tracks` WHERE (`tracks`.product_id = 1) 
  Track Columns (0.002280)   SHOW FIELDS FROM `tracks`
Rendered layouts/_header (0.00051)
Completed in 0.04310 (23 reqs/sec) | Rendering: 0.00819 (19%) | DB: 0.00757 (17%) | 200 OK [http://localhost/media]</tt></pre>
</div></div>
<div class="para"><p><strong>SyslogLogger</strong></p></div>
<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>
<div class="para"><p>By default, SyslogLogger uses the program name ‘rails’, but this can be changed via the first argument to SyslogLogger.new.</p></div>
<div class="para"><p>NOTE! You can only set the SyslogLogger program name when you initialize SyslogLogger for the first time. This is a limitation of the way SyslogLogger uses syslog (and in some ways, a the way syslog(3) works). Attempts to change SyslogLogger’s program name after the first initialization will be ignored.</p></div>
<div class="para"><p>Sample usage with Rails
config/environment/production.rb
Add the following lines:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>  require 'production_log/syslog_logger'
  RAILS_DEFAULT_LOGGER = SyslogLogger.new
config/environment.rb
In 0.10.0, change this line:</tt></pre>
</div></div>
<div class="literalblock">
<div class="content">
<pre><tt>  RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
to:</tt></pre>
</div></div>
<div class="literalblock">
<div class="content">
<pre><tt>  RAILS_DEFAULT_LOGGER ||= Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
Other versions of Rails should have a similar change.</tt></pre>
</div></div>
<div class="para"><p>/etc/syslog.conf
Add the following lines:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt> !rails
 *.*                                             /var/log/production.log
Then touch /var/log/production.log and signal syslogd with a HUP (killall -HUP syslogd, on FreeBSD).</tt></pre>
</div></div>
<div class="para"><p>/etc/newsyslog.conf
Add the following line:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>  /var/log/production.log                 640  7     *    @T00  Z
This creates a log file that is rotated every day at midnight, gzip’d, then kept for 7 days. Consult newsyslog.conf(5) for more details.</tt></pre>
</div></div>
<div class="para"><p>Now restart your Rails app. Your production logs should now be showing up in /var/log/production.log. If you have mulitple machines, you can log them all to a central machine with remote syslog logging for analysis. Consult your syslogd(8) manpage for further details.</p></div>
<div class="para"><p><strong>A Hodel 3000 Compliant Logger for the Rest of Us</strong></p></div>
<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>
<div class="para"><p><a href="http://topfunky.net/svn/plugins/hodel_3000_compliant_logger/lib/hodel_3000_compliant_logger.rb">link to module file</a></p></div>
<div class="para"><p>Just put the module in your lib directory and this to your environment.rb</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>require 'hodel_3000_compliant_logger'
config.logger = Hodel3000CompliantLogger.new(config.log_path)</tt></pre>
</div></div>
<div class="para"><p>-Hodel 3000 Example</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Parameters: {"action"=&gt;"shipping", "controller"=&gt;"checkout"}
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Book Columns (0.003155)   SHOW FIELDS FROM `books`
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Book Load (0.000881)   SELECT * FROM `books` WHERE (`books`.`id` = 1 AND (`books`.`sold` = 1)) 
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: ShippingAddress Columns (0.002683)   SHOW FIELDS FROM `shipping_addresses`
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Book Load (0.000362)   SELECT ounces FROM `books` WHERE (`books`.`id` = 1) 
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Rendering template within layouts/application
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Rendering checkout/shipping
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Book Load (0.000548)   SELECT * FROM `books` WHERE (sold = 0) LIMIT 3
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Author Columns (0.002571)   SHOW FIELDS FROM `authors`
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Author Load (0.000811)   SELECT * FROM `authors` WHERE (`authors`.`id` = 1) 
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Rendered store/_new_books (0.01358)
Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: Completed in 0.37297 (2 reqs/sec) | Rendering: 0.02971 (7%) | DB: 0.01697 (4%) | 200 OK [https://secure.jeffbooks/checkout/shipping]</tt></pre>
</div></div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2008-09-11 20:38:33 EDT
</div>
</div>
</body>
</html>