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.
Background
Before this PR, when we ran the test generator, we could only set process numbers at the makefile command level (
-jN
). For example, if there are 10 test generators and we set-j 3
, the 3 processes will start by picking one test generator to run, e.g., process-1 picks the sanity test generator. Once process-1 finishes the first test generator, it will pick another test generator from the queue.However, the execution time of each test generator can significantly differ from one another. Despite utilizing a multi-core machine, the test generator with the longest execution time has a noticeable impact on the overall execution speed. The other cores are idle, waiting for the slowest generator to finish.
Therefore, it would be more beneficial to divide the jobs at the test cases level, rather than only at the test generator level. This approach would allow for a more efficient distribution of work among the available cores, enabling parallel execution of multiple test cases simultaneously and reducing the impact of slower test generators on the overall execution time.
Refactoring
run_generator
function into multiple functionsDiagnostics
dataclass to pass info on each test caseThe goal is to exact the
generate_test_vector
job for each process to execute. Plus, it improves readability essentially.Multiprocessing
pathos.multiprocessing.ProcessingPool
to implement the pool: the args tomultiprocessing.Pool
must be picklable. However, the way we passcase_fn
is not picklable. Therefore, I usepathos
library which can serialize the argument I passMODE_SINGLE_PROCESS
: the previous mode. Just one process perrun_generator
.MODE_MULTIPROCESSING
: use multiprocessing inrun_generator
. It first collects all test cases of the giventest_providers
intoall_test_case_params
, then spawnsnum_process
processes to execute these test cases.How
run_generator
is usedFor the state tests,
run_generator
was called at each(runner_name, preset, fork)
combination:consensus-specs/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py
Lines 96 to 111 in b6df4b5
For example, for the
sanity
tests, there are multiplerun_generator
call for:(sanity, minimal, phase0)
(sanity, minimal, altair)
(sanity, minimal, bellatrix)
(sanity, minimal, capella)
(sanity, minimal, deneb)
(sanity, minimal, eip6110)
(sanity, mainnet, phase0)
(sanity, mainnet, altair)
(sanity, mainnet, bellatrix)
(sanity, mainnet, capella)
(sanity, mainnet, deneb)
(sanity, mainnet, eip6110)
It's possible that the parent process collects 30 test cases from
(sanity, mainnet, phase0)
, but only 3 test cases are the slow test cases.If we only assign one job to run
make generate_tests
at makefile command level, it will be inefficient when the number of the remaining slow test cases is smaller than the number of cores.Therefore, it would be more efficent to set
-jN
withN > 1
. This allows for parallel execution across multiple cores, enabling faster processing when the number of slow test cases is relatively small compared to the available cores.Performance
Platform
Case 1: Run single test generator
Same command for both modes since
-j
jobs won't help when running single generator:Case 2: Run all test generators
MODE_SINGLE_PROCESS
Command and setting
MODE_MULTIPROCESSING
Command and setting
Execution time results
As evident from the results, the
MODE_MULTIPROCESSING
mode outperforms. 🥹🎉