Skip to content

Commit cbeb769

Browse files
committed
Small concurrency tweaks
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent e792cc2 commit cbeb769

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

cmd/mal/mal.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,21 @@ func main() {
244244
returnCode = ExitInvalidRules
245245
}
246246

247+
concurrency := concurrencyFlag
248+
if concurrency < 1 {
249+
concurrency = 1
250+
}
251+
247252
var pool *malcontent.ScannerPool
248253
if mc.ScannerPool == nil {
249-
pool, err = malcontent.NewScannerPool(yrs, runtime.NumCPU())
254+
pool, err = malcontent.NewScannerPool(yrs, concurrency)
250255
if err != nil {
251256
returnCode = ExitInvalidRules
252257
}
253258
}
254259

255260
mc = malcontent.Config{
256-
Concurrency: concurrencyFlag,
261+
Concurrency: concurrency,
257262
ExitFirstHit: exitFirstHitFlag,
258263
ExitFirstMiss: exitFirstMissFlag,
259264
IgnoreSelf: ignoreSelfFlag,

pkg/action/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func scanSinglePath(ctx context.Context, c malcontent.Config, path string, ruleF
5757

5858
var pool *malcontent.ScannerPool
5959
if c.ScannerPool == nil {
60-
pool, err = malcontent.NewScannerPool(yrs, runtime.NumCPU())
60+
pool, err = malcontent.NewScannerPool(yrs, c.Concurrency)
6161
if err != nil {
6262
return nil, fmt.Errorf("failed to create scanner pool: %w", err)
6363
}

pkg/refresh/action.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func actionRefresh(ctx context.Context) ([]TestData, error) {
6767
}
6868

6969
c := &malcontent.Config{
70+
Concurrency: runtime.NumCPU(),
7071
IgnoreSelf: false,
7172
MinFileRisk: 0,
7273
MinRisk: 0,

pkg/refresh/diff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func diffRefresh(ctx context.Context, rc Config) ([]TestData, error) {
193193
}
194194

195195
c := &malcontent.Config{
196+
Concurrency: runtime.NumCPU(),
196197
FileRiskChange: td.riskChange,
197198
FileRiskIncrease: td.riskIncrease,
198199
MinFileRisk: minFileRisk,

pkg/refresh/refresh.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func discoverTestData(rc Config) (map[string]string, error) {
7272
// newConfig returns a new malcontent Config with parent configurations.
7373
func newConfig(rc Config) *malcontent.Config {
7474
return &malcontent.Config{
75+
Concurrency: runtime.NumCPU(),
7576
IgnoreTags: []string{"harmless"},
7677
MinFileRisk: 1,
7778
MinRisk: 1,

0 commit comments

Comments
 (0)