32 seconds per million calls), while a method_missing call and case statement
take 480 nanoseconds. Modulo the accuracy of our measurement, this is a 50%
performance penalty for using method_missing. Balanced against the additional
power we get from method_missing, this certainly seems to be a good trade.
Benchmark is a powerful tool, but it can quickly amount to guesswork and black
magic. There is no use optimizing method dispatch unless it is a bottleneck.*
* Here??™s a hint: at more than two million method calls per second, method dispatch is probably not your
bottleneck.
Measurement Tools | 153
Don??™t just go poking around looking for code to benchmark, though. Profilers are
much more powerful utilities when you don??™t know what needs optimization. We
will consider them next.
Rails Analyzer Tools
The Rails Analyzer Tools (http://rails-analyzer.rubyforge.org/) are a set of utilities that
can help profile your Rails application. While Benchmark is Ruby-specific, and
httperf will benchmark any web site, the Rails Analyzer Tools were written with
Rails in mind.
Production log analyzer
The first tool, the Production Log Analyzer, scans your production logfiles to find
the slowest actions in your deployed application. This is very useful for problem
solving, but it has a number of downsides. It requires the logs to go through the
SyslogLogger (provided with the Rails Analyzer Tools), so you must set this up
before the requests come in.
Pages:
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