Skip to content

Salt parallelization is sequential if the parallel state object has any requisites #49273

Closed

Description

@ferringb

Description of Issue/Question

Whatever backing scheduler is used for the parallelization feature seems to only work if the state has no requisites. If it does- for example, a dependency on a pkg.install- parallelization doesn't occur, instead it's ran sequentially.

Unfortunately, this kind of strongly limits the parallelization usefulness; whether it be formatting disks or dumping files into a directory, each of those will have a requisite that must be satisfied first- which in turn results in the parallel section being serialized.

Setup + reproduction

test-case.sls; this should parallelize to ~10s total clock, but doesn't.

barrier:
  test.nop 
  
{%- for x in [1,2,3] %}
blah-{{x}}:
  cmd.run:
    - name: sleep 10
    - require:
      - barrier
    - parallel: true
    - require_in:
      - barrier2
{% endfor %}

barrier2:
  test.nop

The following is the render results. Note the start timestamps, and total runtime. warnings truncated from output:

local:
----------
          ID: barrier
    Function: test.nop
      Result: True
     Comment: Success!
     Started: 06:53:52.316003
    Duration: 0.311 ms
     Changes:   
----------
          ID: blah-1
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:53:52.317096
    Duration: 10008.755 ms
     Changes:   
              ----------
              pid:
                  13508
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: blah-2
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:54:02.333901
    Duration: 10012.71 ms
     Changes:   
              ----------
              pid:
                  13510
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: blah-3
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:54:12.353356
    Duration: 10011.777 ms
     Changes:   
              ----------
              pid:
                  13512
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: barrier2
    Function: test.nop
      Result: True
     Comment: Success!
     Started: 06:54:22.371214
    Duration: 0.502 ms
     Changes:   

Summary for local
------------
Succeeded: 5 (changed=3)
Failed:    0
------------
Total states run:     5
Total run time:  30.034 s

real	0m44.792s
user	0m3.196s
sys	0m0.657s

Contrast that with this test case- note that there is no barrier1, IE the parallelized content doesn't have any requisites of their own.

{%- for x in [1,2,3] %}
blah-{{x}}:
  cmd.run:
    - name: sleep 10
    - require_in:
      - barrier2
    - parallel: true
{% endfor %}

barrier2:
  test.nop 

Output is thus; it's 20s faster since the 3 sleeps are ran in parallel now.

local:
----------
          ID: blah-1
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:56:31.062373
    Duration: 10009.84 ms
     Changes:   
              ----------
              pid:
                  13680
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: blah-2
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:56:31.066379
    Duration: 10009.478 ms
     Changes:   
              ----------
              pid:
                  13681
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: blah-3
    Function: cmd.run
        Name: sleep 10
      Result: True
     Comment: Command "sleep 10" run
     Started: 06:56:31.068708
    Duration: 10009.141 ms
     Changes:   
              ----------
              pid:
                  13682
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: barrier2
    Function: test.nop
      Result: True
     Comment: Success!
     Started: 06:56:41.084674
    Duration: 0.537 ms
     Changes:   

Summary for local
------------
Succeeded: 4 (changed=3)
Failed:    0
------------
Total states run:     4
Total run time:  30.029 s

real	0m24.015s
user	0m1.909s
sys	0m0.612s

Versions Report

I've verified this behaviour for 2017.7.2 through 2018.3.2 for the minion, and 2017.7.2 for the master. I've validated this behaviour both via master side salt call's, and via salt-call from the minion itself.

Activity

  1. changed the title [-]Salt parallelization [/-] [+]Salt parallelization is sequential if the parallel state object has any requisites[/+] on Aug 23, 2018
  2. gtmanfred commented on Aug 23, 2018

    @gtmanfred
    Contributor

    @thatch45 can you comment on this?

    Thanks,
    Daniel

  3. added
    pending-discussion
    on Aug 23, 2018
  4. added this to the Blocked milestone on Aug 23, 2018
  5. thatch45 commented on Aug 23, 2018

    @thatch45
    Contributor

    At first I looked at this and said "yes, that sounds right" but then I tested it and it does not behave the way I think it should. So the require_ins should make barrier2 wait for all of the parallels to run, but it should not block until it gets evaluated. So I thought that it would fix it if you added an order: last to the barier2 state, but that does not work, what works is getting rid of the shared require of barrier.

    So in a nutshell, this does look odd, the barrier requisite should be resolved first and then the 3 sleeps should run at the same time.

    So yes, this is a bug, I need to figure out what is causing this

  6. added
    bug
    Core
    and removed
    pending-discussion
    on Aug 23, 2018
  7. modified the milestones: Blocked, Approved on Aug 23, 2018
  8. added
    severity-medium
    P2
    on Aug 23, 2018
  9. 29 remaining items

  10. added
    P4
    severity-medium
    on Jan 10, 2020
  11. modified the milestones: Blocked, Approved on Jan 10, 2020
  12. Oloremo commented on Apr 26, 2020

    @Oloremo
    Contributor

    @garethgreenaway Any updates on this?

  13. removed
    P4
    on Jun 3, 2020
  14. added
    Aluminium
    on Sep 1, 2020
  15. modified the milestones: Approved, Aluminium on Sep 1, 2020
  16. bitskri3g commented on Oct 16, 2020

    @bitskri3g

    +1. Fixing this would allow for massive speed increases in many situations. Might I also suggest adding a tunable that allows for some kind of max concurrency limit? I have a routine that goes through and calls the keystone-ng module and creates projects for users and then assigns them roles. The project must be created prior to the role being assigned for each user, but there is no reason that those two serial steps can't be executed in parallel for each of the 1000 users that we have (so, 1000 separate threads that create a project and assign a role, in that order). That said, running 1000 threads simultaneously that make REST API calls is probably a poor decision, so the ability to 'cap' the number of parallel states that are able to be run at any one time (global minion config option?) would be very useful.

  17. garethgreenaway commented on Nov 18, 2020

    @garethgreenaway
    Contributor

    Apologies for the delay on this one, I had a chance to look into this. I believe I've traced it down to the fact that if there is a requisite.....we call call_chunk from within call_chunk on the req, here: https://github.com/saltstack/salt/blob/master/salt/state.py#L2954 and then call it again on the original chunk once the requisite has been met, here: https://github.com/saltstack/salt/blob/master/salt/state.py#L2965, that second call is the one that ends up doing the call to call_parallel and I think that might be the issue. Still digging in to see what the fix would be.

  18. garethgreenaway commented on Nov 18, 2020

    @garethgreenaway
    Contributor

    Had a realization this morning when looking at this again with fresh eyes. The issue turned out to be that when we run check_requisite it ends up running reconcile_procs on all the running states. So using the example states above the barrier would run first, then the first state in the loop would run and run check_requisite to check the barrier requisite. Because both barrier and the first sleep state are now in the list of running states the while loop for reconcile_procs would continue until the first sleep state is finished. We would then see similar behavior for the second and third sleep states.

    The PR filters out any states that aren't in the requisites and only runs reconcile_procs on those states.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Aluminiumbugseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions