Recently, a company with whom we work had a Web site that wasn’t as fast as they wanted. So they ran a series of tests using Apache’s benchmarking tool:
- Running a simple “Hello World” page: 500 pages/second
- “Hello World” plus turning on “feature A”: 50 pages/second
- “Hello World” plus both “feature A” and “feature B”: 5 pages/second
So, what feature should be optimized first to get the “biggest bang for the buck”?
This is a great example where your first intuition is probably wrong. How long does each feature take?
- “Hello World” = 500 pages/second -> 0.002 seconds/page
- “Hello World” + “Feature A” = 50 pages/sec -> 0.02 seconds/page
- “Hello World” + “Feature A” + “Feature B” = 5 pages/sec -> 0.2 seconds/page
Solving for each individual feature:
- “Hello World” = 0.002 seconds to execute
- “Feature A” = 0.018 seconds to execute
- “Feature B” = 0.180 seconds to execute
“Feature A” takes 9% of the total time while “Feature B” takes 90% of the total time! So even if you optimized Feature A so that it took absolutely no time at all, you’ll find:
- “Hello World” + “Feature B” = 0.182 seconds -> 5.49 pages/sec
So for your biggest bang for the buck, you need to work on Feature B first.
2 responses to “A Fun Little Math Problem in System Optimization”
Math geniuses are so bloody *showy*. 😉
Thanks for the help! I am glad we had this conversation about “bang for the buck”. It was very enlightening.
It should be noted that even though we thought that feature A and feature B ran serially this was not the case. It turns out that there was a third feature C that was taking the bulk of the 20 milliseconds we erroneously assigned to A. Also, implementing feature B inadvertently replaced feature C, so the 200 milliseconds was all attributed to feature B. Feature A turned out to be a red herring and Feature C really had nothing at all to do with the whole thing.
Ironically, having that math conversation did push us to focus on B, which through serendipity allowed us to discover the mistake we made with respect to blaming feature A.
Yes, this is bizarre. 🙂 If you want to know how something like this could happen shoot me an email. I’ll tell you the whole story offline. 🙂
Having said all that, I am really thankful we had this conversation. So thanks again!