mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: limit parallelism
This commit is contained in:
parent
0175d1babc
commit
fa222a44c3
@ -59,6 +59,7 @@ type Context struct {
|
|||||||
variables map[string]string
|
variables map[string]string
|
||||||
|
|
||||||
l sync.Mutex // Lock acquired during any task
|
l sync.Mutex // Lock acquired during any task
|
||||||
|
parallelSem Semaphore
|
||||||
providerInputConfig map[string]map[string]interface{}
|
providerInputConfig map[string]map[string]interface{}
|
||||||
runCh <-chan struct{}
|
runCh <-chan struct{}
|
||||||
}
|
}
|
||||||
@ -82,17 +83,27 @@ func NewContext(opts *ContextOpts) *Context {
|
|||||||
state.init()
|
state.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine parallelism, default to 10. We do this both to limit
|
||||||
|
// CPU pressure but also to have an extra guard against rate throttling
|
||||||
|
// from providers.
|
||||||
|
par := opts.Parallelism
|
||||||
|
if par == 0 {
|
||||||
|
par = 10
|
||||||
|
}
|
||||||
|
|
||||||
return &Context{
|
return &Context{
|
||||||
diff: opts.Diff,
|
diff: opts.Diff,
|
||||||
hooks: hooks,
|
hooks: hooks,
|
||||||
module: opts.Module,
|
module: opts.Module,
|
||||||
providers: opts.Providers,
|
providers: opts.Providers,
|
||||||
|
provisioners: opts.Provisioners,
|
||||||
|
state: state,
|
||||||
|
uiInput: opts.UIInput,
|
||||||
|
variables: opts.Variables,
|
||||||
|
|
||||||
|
parallelSem: NewSemaphore(par),
|
||||||
providerInputConfig: make(map[string]map[string]interface{}),
|
providerInputConfig: make(map[string]map[string]interface{}),
|
||||||
provisioners: opts.Provisioners,
|
|
||||||
sh: sh,
|
sh: sh,
|
||||||
state: state,
|
|
||||||
uiInput: opts.UIInput,
|
|
||||||
variables: opts.Variables,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,9 @@ func (w *ContextGraphWalker) EnterGraph(g *Graph) EvalContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *ContextGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode {
|
func (w *ContextGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode {
|
||||||
|
// Acquire a lock on the semaphore
|
||||||
|
w.Context.parallelSem.Acquire()
|
||||||
|
|
||||||
// We want to filter the evaluation tree to only include operations
|
// We want to filter the evaluation tree to only include operations
|
||||||
// that belong in this operation.
|
// that belong in this operation.
|
||||||
return EvalFilter(n, EvalNodeFilterOp(w.Operation))
|
return EvalFilter(n, EvalNodeFilterOp(w.Operation))
|
||||||
@ -91,6 +94,9 @@ func (w *ContextGraphWalker) EnterEvalTree(v dag.Vertex, n EvalNode) EvalNode {
|
|||||||
|
|
||||||
func (w *ContextGraphWalker) ExitEvalTree(
|
func (w *ContextGraphWalker) ExitEvalTree(
|
||||||
v dag.Vertex, output interface{}, err error) error {
|
v dag.Vertex, output interface{}, err error) error {
|
||||||
|
// Release the semaphore
|
||||||
|
w.Context.parallelSem.Release()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user