This is a guest blog post by Rob Martin (@version2beta) originally published in Software Developers Journal in August 2013.
Like many people, I confused the Heisenberg Uncertainty Principle with the Observer Effect. the Heisenberg Uncertainty Principle asserts that we cannot accurately measure pairs of physical properties of particles. that is, if we know one value, the other is unknowable. This is best illustrated by the story of Heisenberg being pulled over by a police officer. The officer asks Heisenberg if he knows how fast he was driving. No, but I know where I am, says Heisenberg. The officer says, Sir, you were driving 76 miles per hour. Heisenberg replies, Great. now I’m lost.
On the other hand, the observer effect describes the impact on a system of measuring things within that system. A common example is measuring the pressure in a tire. It’s hard to do without having a bit of air leak out, thereby affecting the pressure of the tire. The more we measure, the flatter the tire gets.
Instruments that measure code performance are subject to the observer effect too. The mere process of inserting code (or reflecting on existing code) to measure our application’s performance will also affect the performance of the application. If we naively code against a cloud-based metrics tool such as Librato or New Relic, we risk significant impact on our performance waiting for blocking I/O as we record the measurement to a remote location.
I needed a library for measuring code performance, and I wanted to minimize the observer effect. This problem suggested an asynchronous programming pattern that records in real time, but stores the result within another thread or process.