Skip to content

Commit

Permalink
Allow to override the number of parallel cores used, with variable **…
Browse files Browse the repository at this point in the history
…PARALLEL_PROCESS_NUMBER**
  • Loading branch information
nvuillam committed Mar 15, 2024
1 parent f4c433c commit a36ab96
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- Core
- Allow to override the number of parallel cores used, with variable **PARALLEL_PROCESS_NUMBER**

- Media

- New linters

- Fixes
- Fix conflict between prettier and yamllint about spaces

- Doc

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ description: List of common variables that you can use to customize MegaLinter b
| **MEGALINTER_CONFIG** | `.mega-linter.yml` | Name of MegaLinter configuration file. Can be defined remotely, in that case set this environment variable with the remote URL of `.mega-linter.yml` config file |
| **MEGALINTER_FILES_TO_LINT** | \[\] | Comma-separated list of files to analyze. Using this variable will bypass other file listing methods |
| **PARALLEL** | `true` | Process linters in parallel to improve overall MegaLinter performance. If true, linters of same language or formats are grouped in the same parallel process to avoid lock issues if fixing the same files |
| **PARALLEL_PROCESS_NUMBER** | <!-- --> | All available cores are used by default. If there are too many, you need to decrease the number of used cores in order to enhance performances (example: `4`) |
| [**PLUGINS**](#plugins) | \[\] | List of plugin urls to install and run during MegaLinter run |
| [**POST_COMMANDS**](https://github.com/oxsecurity/megalinter/tree/main/docs/config-postcommands.md) | \[\] | Custom bash commands to run after linters |
| [**PRE_COMMANDS**](https://github.com/oxsecurity/megalinter/tree/main/docs/config-precommands.md) | \[\] | Custom bash commands to run before linters |
Expand Down
8 changes: 6 additions & 2 deletions megalinter/MegaLinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,12 @@ def process_linters_parallel(self, active_linters, linters_do_fixes):
linter_groups += [[linter]]
linter_groups = linter_factory.sort_linters_groups_by_speed(linter_groups)
# Execute linters in asynchronous pool to improve overall performances
process_number = mp.cpu_count()
logging.info(f"Processing linters on [{str(process_number)}] parallel cores…")
if config.exists("PARALLEL_PROCESS_NUMBER"):
process_number = int(config.get("PARALLEL_PROCESS_NUMBER"))
logging.info(f"Processing linters on [{str(process_number)}] parallel cores… (according to variable PARALLEL_PROCESS_NUMBER")
else:
process_number = mp.cpu_count()
logging.info(f"Processing linters on [{str(process_number)}] parallel cores… (can be decreased with variable PARALLEL_PROCESS_NUMBER in case of performance issues)")
install_mp_handler()
pool = mp.Pool(
process_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10242,6 +10242,15 @@
"title": "Parallel processing",
"type": "boolean"
},
"PARALLEL_PROCESS_NUMBER": {
"$id": "#/properties/PARALLEL_PROCESS_NUMBER",
"description": "All available cores are used by default. If there are too many, you need to decrease the number of used cores in order to enhance performances",
"examples": [
4
],
"title": "Parallel process number",
"type": "number"
},
"PERL_FILTER_REGEX_EXCLUDE": {
"$id": "#/properties/PERL_FILTER_REGEX_EXCLUDE",
"title": "Excluding regex filter for PERL descriptor",
Expand Down

0 comments on commit a36ab96

Please sign in to comment.