At bob.io we were migrating a ton of repositories from our oldie Jenkins to GitHub Actions and everything was going really smooth, in some of our tests with mocha and chai we shaved a nice 40% running time, and with the matrix strategy, we can run a lot of test in parallel removing a lot of friction from our CI process.
We were in heaven until we migrated a frontend app with tests made in Jest.
On our first try the tests took a hefty amount of time
For reference the same tests in Jenkins π€
The same tests on my computer π
At first glance, it appeared that is CPU bound, but in mocha and chai the history was the opposite, we reduced the run times, so I did a small investigation using the time command like this:
-v npm run test
In my computer the tests were parallelized and used a good amount of CPU power
Meanwhile, in the Github runners, the history was different
Looks like, under the hood, Jest checks the number of cores available and uses as much as possible but never uses all the cores, the instances running our test have 2 cores available but Jest only uses 1.
After digging into the Jest documentation I found the maxWorkers option which allows you to control the number of CPU cores used.
I tried to run the same test but forced the workers to fully use the available cores in the runner:
-v npm run test -- --maxWorkers=2
Not 200% but better CPU usage:
Just for the sake of curiosity, I tested with 3 workers and it took 1:34 so we left it with 2 workers.
Top comments (0)