Skip to content
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

Add :parallel-threads option to set thread pool size #274

Open
wants to merge 21 commits into
base: parallelize
Choose a base branch
from

Conversation

john-shaffer
Copy link
Contributor

The current parallel runner uses clojure.core/map with futures, which doesn't allow much control over execution. It is probably okay for unit tests, but it uses way too many threads for integration and e2e tests. We have test systems that spawn database and browser processes, and we need a much lower level of parallelism (4 seems ideal on an 8-core machine).

This uses claypoole's pmap to run the tests, which allows for simplifying the code a bit.

@john-shaffer john-shaffer changed the base branch from main to parallelize March 9, 2022 14:54
@alysbrooks
Copy link
Member

Thank you for the PR! I've been holding off on reviewing this because I'm waiting to merge the original PR. I think being able to control the thread pool somehow is a good idea. However, I'm not sure whether bringing in another dependency is worth it.

Out of curiosity, have you run the parallel threads PR against any of your test systems?

@john-shaffer
Copy link
Contributor Author

john-shaffer commented Apr 6, 2022

Thanks for responding!

I considered the issue of adding a dependency, but claypoole is very light-weight and has no dependencies of its own. If that is still a problem, I could look into the possibility of vendoring just the pmap implementation. The additional control is absolutely necessary for heavy-weight test systems, both for speed and to stay within RAM constraints. It is also a useful performance-tuning knob for others.

I have been running this branch for testing locally and in CI for the last month. It has held up fine for hundreds of runs, although the increased parallelism did surface a race condition in etaoin.

@@ -186,4 +186,5 @@
(try+
(System/exit (apply -main* args))
(catch :kaocha/early-exit {exit-code :kaocha/early-exit}
(shutdown-agents)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also shutdown agents if -main* exits normally?

(defn add-desc [testable description]
(assoc testable ::desc
(str (name (::id testable)) " (" description ")")))

(defn- try-require [n]
(try
(require n)
(locking REQUIRE_LOCK
(require n))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -174,7 +189,8 @@
:kaocha/testable test})
m (cond-> m
file (assoc :file file)
line (assoc :line line))]
line (assoc :line line)
thread (assoc :thread thread))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to namespace this? things like type/actual/expected/line/file are standard clojure.test things, if we shove extra data into reporter events we generally namespace them. Not sure how consistent we are in this but generally a good idea.

src/kaocha/testable.clj Outdated Show resolved Hide resolved
@plexus
Copy link
Member

plexus commented May 12, 2022

Hi @john-shaffer , thanks a lot for this PR. There's some good stuff in here, and I appreciate you're helping to make Kaocha better. Sorry it's taken me so long before I managed to make time to have a better look.

I had a look at Claypoole, it has no dependencies of its own, it weighs itself about ~100kB. Also looking at what it does I think it's reasonable to bring that in here.

So, let's see if we can get this into a mergeable state? I see REPL code in source namespaces, a stray tap>, and some comments and stray whitespace that could be cleaned up. The tap> is actually causing CI to fail, let's see if we can get that all green as well. A CHANGELOG entry and where applicable a mention in the docs of new features (like the new command line flag) would be great.

Thanks a lot!

@plexus
Copy link
Member

plexus commented Jul 25, 2022

Hi @john-shaffer , do you still have interest in getting this in a mergable state, or was this a drive-by PR?

alysbrooks and others added 4 commits August 19, 2022 18:32
run-testables ends up being called within its own body, which
kaocha is parallelizing. We generally want to parallelize at the
namespace level, so we use run-test-serial for other testable types.
This way we only create one threadpool at a time.
The previous code references fixtures/f-tests, but there is no such
directory. The test case looks unfinished, so I'm not sure that there
ever was a working f-tests dir.

To fix the test case, I have adapted the code from run-test, just before
run-test-parallel.
@codecov
Copy link

codecov bot commented Aug 20, 2022

Codecov Report

❗ No coverage uploaded for pull request base (parallelize@56c1dc3). Click here to learn what that means.
The diff coverage is n/a.

@@              Coverage Diff               @@
##             parallelize     #274   +/-   ##
==============================================
  Coverage               ?   75.06%           
==============================================
  Files                  ?       51           
  Lines                  ?     2755           
  Branches               ?      256           
==============================================
  Hits                   ?     2068           
  Misses                 ?      525           
  Partials               ?      162           
Flag Coverage Δ
integration 56.66% <0.00%> (?)
unit 69.07% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@john-shaffer
Copy link
Contributor Author

Rebased on current parallelize branch, and updated a failing test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

3 participants