-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal for runners #536
proposal for runners #536
Conversation
Fixes #522 |
merging this one as I want to fully revamp the docs in a dedicated PR. If you have feedback, feel free to drop a comment and I will address it later. |
@dbarrosop Am I understanding this correctly that num_workers is no longer available as a configuration option nor can you specify it as an argument to nr.run()? |
It is but in a dedicated section for the runner:
Basically same structure as for configuring the inventory.
You can't but the runner can now be configured with
Or assign it to a variable and keep reusing:
The rationale for this change is that I wanted this part to be pluggable as well as people could implement their own runners with their own business logic. I.e., "run this in the entire datacenter but only one leaf per rack at a time and abort if two switches in the same rack fail but continue if only one fails". You could implement that in your script via filters but being able to do it in this stage with a plugin gives you more control and makes your script more generic as you can keep your script more straighforward and tweak the behavior via runners (i.e., if you know your config replace operation is only doing small changes you could use the ParallelRunner but if you know you are doing more delicate changes use this other running that does an incremental rollout) |
On runners are you open to making a backwards compatible solution so that all of the old num_workers behavior continues to work (num_workers both in config.yaml and as direct argument)? Basically, this form: nr = InitNornir(core={"num_workers": 1})
nr.run(task=my_task) And this form in config.yaml: ---
core:
num_workers: 10 Then dynamically select SerialRunner or ParallelRunner based on this (and set number of threads to be proper-threads). And consequently make all of the Rational: It also is going to cause lots of confusion on documentation and when assisting people side. |
I could be persuaded to put it back raising a deprecationwarning for a certain time (i.e., 6 months) but then I’d want to remove it even without releasing a new major version. Would that work? |
Let me look a bit more at embedding things in the config file: runner:
plugin: ParallelRunner
options:
num_workers: 123 As I didn't experiment with that much. |
Ok, thanks. That part of the code was very messy with many things conflated so this proposal served for both cleaning those bits (separating concerns in a better way) and also making it pluggable, hence my hesitance for backwards compatibility. However, as mentioned earlier, I guess I could live with some backwards compatibility for a period of time so people could transition. |
@dbarrosop Yes, let me keep testing this more with the above section in You can also pretty easily toggle num_workers via adjusting the |
Did I see it correctly that the default behavior (ie no "runner" config and no "with_runner") is still the same as the old behavior (parallel with threads and 20 worker threads)? |
no, the default runner is the parallel one (threaded now that it has been renamed): So, yes, default behavior is still the same |
Okay, I misread David's response the first time...i.e. his initial But then he clarified at the end i.e. the default behavior of |
apologies for being unclear :( |
This PR introduces the concept of runners. Prior to this PR the only way to control the execution was via
num_workers
which basically toggled between using threads or not and configured how many threads to use if workers was greater than 1. With this proposal we can write plugins that act as a "runner", a piece of code that distributes the task across the hosts.Writing a runner is fairly straightforward (or complex, depending of what you want to do). As an example, the runner that implements parallelization as before is this:
The API to use them is slightly different,
num_workers
is no longer available tonr.run
, instead you can configure the runner with the configuration and/or override it withnr.with_runner
:The equivalent of
nr.run(num_workers=1)
now would be:Another example
If you wanted to write a runner that run the task over the hosts in alphabetical order and without threads, you could do something like:
and then set it in the configuration like this:
or:
Todo