-
Notifications
You must be signed in to change notification settings - Fork 90
Running candidates in parallel (asynchronous)
Scientist runs tasks synchronously by default. This can end up doubling (more or less) the time it takes the original method call to complete, depending on how many candidates are added and how long they take to run.
In cases where Scientist is used for production refactoring, for example, this ends up causing the calling method to return slower than before which may affect the performance of your original code. However, if the candidates can be run at the same time as the control method without affecting each other, then they can be run in parallel so the Scientist call will only take as long as the slowest task (plus a tiny bit of overhead):
await Scientist.ScienceAsync<int>(
"ExperimentName",
3, // number of tasks to run concurrently
experiment => {
experiment.Use(async () => await StartRunningSomething(myData));
experiment.Try(async () => await RunAtTheSameTimeAsTheControlMethod(myData));
experiment.Try(async () => await AlsoRunThisConcurrently(myData));
});As always when using async/await, don't forget to call .ConfigureAwait(false) where appropriate.
- Publishing results
- Controlling comparison
- Adding context
- Expensive setup
- Keeping it clean
- Ignoring mismatches
- Enabling or disabling experiments
- Ramping up experiments
- Running candidates in parallel (asynchronous)
- Testing
- Handling errors
- Designing an experiment
- Finishing an experiment
Sometimes scientists just gotta do weird stuff. We understand.