This simple command-line utility
takes as arguments the path to a Rails production log and an optional refresh
interval, which defaults to 10 seconds. It sits on the logfile, watching for new lines,
and summarizes the traffic to the site, refreshing at the given interval until it receives
SIGINT (Ctrl-C):
$ rails_stat log/production.log
~ 1.4 req/sec, 0.0 queries/sec, 7.9 lines/sec
The implementation of rails_stat is very simple (it is based on IOTail). This code
could be used as the basis for a flexible real-time log analytics system.
Rails Optimization Example
To tie these concepts together, we will look at the process of benchmarking, profiling,
and optimizing a Rails action. This example comes from a real application, one
that is fairly large and complicated. We have seen pieces of this application before; it
is a map-based real estate search application. The application deals heavily with
geospatial data, and is based on the PostGIS spatial extensions to PostgreSQL.
We have identified an action to profile: the action that performs the search itself
(POST /searches). This action is not particularly slow in absolute terms, but it is our
most commonly used feature, and any more performance we can get reduces overall
latency and makes our application feel snappier.
Profiling an Action
Once we have decided on an action whose performance we want to improve, we can
profile it to see where our time is being spent.
Pages:
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