1
0

parallel.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ==========================
  2. Running States in Parallel
  3. ==========================
  4. Introduced in Salt version ``2017.7.0`` it is now possible to run select states
  5. in parallel. This is accomplished very easily by adding the ``parallel: True``
  6. option to your state declaration:
  7. .. code-block:: yaml
  8. nginx:
  9. service.running:
  10. - parallel: True
  11. Now ``nginx`` will be started in a separate process from the normal state run
  12. and will therefore not block additional states.
  13. Parallel States and Requisites
  14. ==============================
  15. Parallel States still honor requisites. If a given state requires another state
  16. that has been run in parallel then the state runtime will wait for the required
  17. state to finish.
  18. Given this example:
  19. .. code-block:: yaml
  20. sleep 10:
  21. cmd.run:
  22. - parallel: True
  23. nginx:
  24. service.running:
  25. - parallel: True
  26. - require:
  27. - cmd: sleep 10
  28. sleep 5:
  29. cmd.run:
  30. - parallel: True
  31. The ``sleep 10`` will be started first, then the state system will block on
  32. starting nginx until the ``sleep 10`` completes. Once nginx has been ensured to
  33. be running then the ``sleep 5`` will start.
  34. This means that the order of evaluation of Salt States and requisites are
  35. still honored, and given that in the above case, ``parallel: True`` does not
  36. actually speed things up.
  37. To run the above state much faster make sure that the ``sleep 5`` is evaluated
  38. before the ``nginx`` state
  39. .. code-block:: yaml
  40. sleep 10:
  41. cmd.run:
  42. - parallel: True
  43. sleep 5:
  44. cmd.run:
  45. - parallel: True
  46. nginx:
  47. service.running:
  48. - parallel: True
  49. - require:
  50. - cmd: sleep 10
  51. Now both of the sleep calls will be started in parallel and ``nginx`` will still
  52. wait for the state it requires, but while it waits the ``sleep 5`` state will
  53. also complete.
  54. Things to be Careful of
  55. =======================
  56. Parallel States do not prevent you from creating parallel conflicts on your
  57. system. This means that if you start multiple package installs using Salt then
  58. the package manager will block or fail. If you attempt to manage the same file
  59. with multiple states in parallel then the result can produce an unexpected
  60. file.
  61. Make sure that the states you choose to run in parallel do not conflict, or
  62. else, like in any parallel programming environment, the outcome may not be
  63. what you expect. Doing things like just making all states run in parallel
  64. will almost certainly result in unexpected behavior.
  65. With that said, running states in parallel should be safe the vast majority
  66. of the time and the most likely culprit for unexpected behavior is running
  67. multiple package installs in parallel.