Sometimes we envy you. Such great things are still waiting for you! For example, more and more fantastic ruby libraries appear and we can’t keep silent about that. Meet Scientist Ruby library for refactoring critical paths.
Scientist Ruby library is used for careful refactoring critical paths. Let’s start from the beginning.
The first thing to do, you need to compare the current and refactored behaviors under load. Wrap a
use block around the code’s original behavior, and wrap
try around the new behavior.
experiment.run will always return whatever the
use block returns, but it does a bunch of stuff behind the scenes:
- It decides whether or not to run the
- Randomizes the order in which
tryblocks are run,
- Measures the durations of all behaviors,
- Compares the result of
tryto the result of
- Swallows any exceptions raised in the
- Publishes all this information.
Scientist compares control and candidate values using
==. To override this behavior, use
compare to define how to compare observed values instead. You can disable an experiment by setting a
run_if block. If this returns
false, the experiment will merely return the control value. Otherwise, it defers to the experiment’s configured
Try it by yourself and read more here.
And one more famous book you have to read. Meet ‘The Well-Grounded Rubyist‘. The 3rd edition. You can always rely on us!