-
Notifications
You must be signed in to change notification settings - Fork 132
Docs for parallel execution of CI #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
94b93fa
remove unnecessary env
enzofab91 c9608ec
CR fixes
enzofab91 c6b2063
CR fixes
enzofab91 59317d0
Update cpu quantity info
enzofab91 d0d4799
Update cpu quantity info
enzofab91 13448df
Text change
enzofab91 acc8fa7
remove unnecessary env
enzofab91 c1f8862
CR fixes
enzofab91 32f1f3e
CR fixes
enzofab91 9bdbc00
Update cpu quantity info
enzofab91 631014f
Update cpu quantity info
enzofab91 d9dacce
Text change
enzofab91 8f7745b
fix review comments
rodrieiz 155cee1
Merge branch 'parallel_ci_docs' of https://github.com/rootstrap/rails…
enzofab91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# CI | ||
|
||
## Parallelization with Parallel Tests & Knapsack | ||
Knapsack and Parallel Tests gems allow us to run tests in several nodes at the same time, benefiting us in the execution time. Knapsack parallelizes them at node level while Parallel Tests does it at CPU level. | ||
|
||
Knapsack splits tests based on an execution time report. In case there are files that were not added in the report, they will all run on the same node and may overload it, so it is strongly recommended to update the report frequently. | ||
|
||
## Configuration | ||
In case you want to use this you will need a script that split spec files called `parallel_tests` which sets up the configuration, assuming you have `n_nodes * cpu_cores_quantity`. | ||
|
||
On Github Actions you can add any nodes you want using matrix strategy, setting up some variables: | ||
|
||
```sh | ||
ci_node_total: [4] | ||
# set N-1 indexes for parallel jobs | ||
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc | ||
ci_node_index: [0, 1, 2, 3] | ||
``` | ||
|
||
CPU cores quantity on every node are obtained automatically from Github Actions config `echo "cpu_cores=$(nproc)" >> $GITHUB_ENV`. | ||
|
||
If you want to update it manually you can do it by updating this variable: | ||
`PARALLEL_TESTS_CONCURRENCY: 2` | ||
rodrieiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To update tests on local machine you can by executing `KNAPSACK_CI_NODE_TOTAL=4 KNAPSACK_CI_NODE_INDEX=1 PARALLEL_TESTS_CONCURRENCY=2 bundle exec parallel_rspec -n 2 -e './bin/parallel_tests'`. This will run subset of tests files corresponding to second node. | ||
|
||
## Generating report | ||
Knapsack report needs to be updated frequently to balance execution time among nodes. This can be done manually by executing: | ||
`KNAPSACK_GENERATE_REPORT=true bundle exec rspec` | ||
|
||
It is also recommended to generate the report in the CI for a better precision. For this you have available a workflow in Github Actions that triggers the report generation and creates a pull request automatically. This workflow can be scheduled in the frequency you want or even can be manually triggered. | ||
|
||
To schedule the cron task you have to do it in `.github/workflows/update_knapsack_report.yml:6` | ||
It is now scheduled for February 31 so will never run. | ||
|
||
```sh | ||
- cron: '0 5 31 2 *' | ||
# The above cron does not run. Replace with the wanted periodicity. | ||
``` | ||
## Coverage | ||
When splitting tests in different nodes, each report covers only a part of the code files being tested. | ||
For this reason a job in the CI is added to sums coverages from all nodes to be used by SimpleCov. This job will be executed after all nodes have finished and will send the final report to CodeClimate. | ||
|
||
For the case of CPU cores we do not need to add extra configuration since the report of each node contains the info of all the cores that have been splited. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏