Prev | Current Page 220 | Next

Brad Ediger

"Advanced Rails"


This technique is called black-box analysis: we measure how much traffic the server
can handle, while treating it as a ???black box.??? For now, we don??™t really care what??™s
inside the box, only about how fast it can serve requests. We will leave the minutiae
of profiling and tweaking until later.
For this stage, we will need a benchmarking utility??”but first, a brief diversion into
the world of mathematics.
Statistics: The least you need to know
It doesn??™t take much knowledge of statistics to properly interpret the results of blackbox
analysis, but there are some things you need to know.
Statistical analysis deals with the results of multiple samples, which in this case correspond
to HTTPresponse times. In Ruby fashion, we will illustrate this with a Ruby
array:
samples = %w(10 11 12 10 10).map{|x|x.to_f}
The average, or mean, of these samples is their sum divided by the number of samples.
This is straightforward to translate into Ruby??”adding a few methods to
Enumerable:
module Enumerable
def sum(identity = 0)
inject(identity) {|sum, x| sum + x}
end
def mean
sum.to_f / length
end
end
Measurement Tools | 149
This gives us predictable results:
samples.sum # => 53.0
samples.length # => 5
samples.mean # => 10.6
Everyone is familiar with the mean, but the problem is that by itself, the mean is
nearly worthless for describing a data set. Consider these two sets of samples:
samples1 = %w(10 11 12 10 10 9 12 10 9 9).


Pages:
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