File tree 1 file changed +28
-5
lines changed
internal/terraform/module
1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,13 @@ type moduleLoader struct {
23
23
}
24
24
25
25
func newModuleLoader () * moduleLoader {
26
- nonPrioParallelism := 2 * runtime .NumCPU ()
27
- prioParallelism := 1 * runtime .NumCPU ()
28
-
26
+ p := loaderParallelism (runtime .NumCPU ())
29
27
plc , lc := int64 (0 ), int64 (0 )
30
28
ml := & moduleLoader {
31
29
queue : newModuleOpsQueue (),
32
30
logger : defaultLogger ,
33
- nonPrioParallelism : int64 ( nonPrioParallelism ) ,
34
- prioParallelism : int64 ( prioParallelism ) ,
31
+ nonPrioParallelism : p . NonPriority ,
32
+ prioParallelism : p . Priority ,
35
33
opsToDispatch : make (chan ModuleOperation , 1 ),
36
34
loadingCount : & lc ,
37
35
prioLoadingCount : & plc ,
@@ -40,6 +38,31 @@ func newModuleLoader() *moduleLoader {
40
38
return ml
41
39
}
42
40
41
+ type parallelism struct {
42
+ NonPriority , Priority int64
43
+ }
44
+
45
+ func loaderParallelism (cpu int ) parallelism {
46
+ // Cap utilization for powerful machines
47
+ if cpu >= 4 {
48
+ return parallelism {
49
+ NonPriority : int64 (3 ),
50
+ Priority : int64 (1 ),
51
+ }
52
+ }
53
+ if cpu == 3 {
54
+ return parallelism {
55
+ NonPriority : int64 (2 ),
56
+ Priority : int64 (1 ),
57
+ }
58
+ }
59
+
60
+ return parallelism {
61
+ NonPriority : 1 ,
62
+ Priority : 1 ,
63
+ }
64
+ }
65
+
43
66
func (ml * moduleLoader ) SetLogger (logger * log.Logger ) {
44
67
ml .logger = logger
45
68
}
You can’t perform that action at this time.
0 commit comments