Configuring Maximum CPU Parallelism for Ruby Testing Tools in CircleCI

Overview

While running tests in CircleCI jobs you may run into different errors that are the result of the high resources consumption.

Many testing frameworks support running tests in parallels across available CPU cores within a single executor. 

By default, most testing tools will auto-detect the number of available CPUs and use all of them resulting in CPU contention, OOM kills and other resources consumption problems.

You may find complete specs for Docker resource classes here - https://circleci.com/docs/reference/configuration-reference/

Solution

Using parallel_tests gem

The parallel_tests gem uses -n to set the process count:

- run:
    name: Run RSpec in parallel
    command: bundle exec parallel_rspec -n 2 spec/

Set -n to match your resource class vCPUs.

Using native RSpec (no parallelism gem)

RSpec itself is single-threaded. To run in parallel natively, use the --format flag alongside a process-level tool like xargs or CircleCI's built-in test splitting:

- run:
    name: Run RSpec
    command: |
      bundle exec rspec \
        --format progress \
        $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split)
 
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.