Skip to content

Conversation

aido-mth
Copy link
Contributor

@aido-mth aido-mth commented Aug 12, 2025

Description

This PR adds thread pool, which makes possible parallel execution of wasm modules. Also it provides test, which checks that execution runs in parallel.

Related Issue(s)

Closes #81

Description of Changes

  1. Add task thread pool (wrapper around rayon thread pool)
  2. Provided integration test to check if modules actually run in parallel
    • Added component, that sleeps for 1 second per request tests/integration/components/sleep_component
    • Added tests/integration/tests/serial/parallel_module_execution.rs which can be managed via cargo test
  3. Updated hermes/bin/tests/integration/tests/serial/utils/ to be more generic in usage

Breaking Changes

Describe any breaking changes and the impact.

Please confirm the following checks

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream module

@aido-mth aido-mth moved this from New to 🏗 In progress in Catalyst Aug 12, 2025
@aido-mth aido-mth added rust Pull requests that update Rust code squad: hermetics Hermes Backend, System Development & Integration Team fyi: hermetics For information - Hermes Backend, System Development & Integration Team rr: hermetics Required review by hermes team labels Aug 12, 2025
@aido-mth aido-mth force-pushed the aido/81/parallel_module_execution branch from f22890e to cdc7c8c Compare August 12, 2025 16:12
@rafal-ch rafal-ch moved this from 🏗 In progress to 👀 In review in Catalyst Aug 13, 2025
@aido-mth aido-mth force-pushed the aido/81/parallel_module_execution branch 2 times, most recently from d7bd604 to 2ee63a6 Compare August 19, 2025 12:45
@aido-mth aido-mth marked this pull request as ready for review August 19, 2025 12:45
@aido-mth aido-mth force-pushed the aido/81/parallel_module_execution branch from b422017 to 9ff8a43 Compare August 20, 2025 16:01
@aido-mth aido-mth added the review me PR is ready for review label Aug 21, 2025
@github-project-automation github-project-automation bot moved this from 👀 In review to 🔖 Ready in Catalyst Aug 22, 2025
@aido-mth
Copy link
Contributor Author

Now blocked by issue.

@aido-mth aido-mth requested a review from no30bit as a code owner September 2, 2025 13:49
stevenj and others added 2 commits September 3, 2025 13:09
* feat(hermes): add unit test for parallel execution, rewrite integration test to use db

* chore(hermes): remove env var, add comment describing the reason why we don't need it

* fix(hermes): add busy_handler that always retries SQLITE_BUSY

* fix(hermes): updated sqlite_busy retry delay

* feat(hermes): add WAL mode

* chore(hermes): link issue to TODO comment

---------

Co-authored-by: Steven Johnson <stevenj@users.noreply.github.com>
rafal-ch
rafal-ch previously approved these changes Sep 3, 2025
Copy link
Contributor

@rafal-ch rafal-ch left a comment

Choose a reason for hiding this comment

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

LGTM 👍
I left two nits.

rafal-ch
rafal-ch previously approved these changes Sep 3, 2025
stevenj
stevenj previously approved these changes Sep 4, 2025
Copy link
Collaborator

@stevenj stevenj left a comment

Choose a reason for hiding this comment

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

LGTM

@aido-mth aido-mth dismissed stale reviews from stevenj and rafal-ch via b8cc119 September 4, 2025 10:43
Copy link
Contributor

@cong-or cong-or left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@no30bit no30bit left a comment

Choose a reason for hiding this comment

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

LGTM

@aido-mth aido-mth merged commit a18a2b9 into main Sep 4, 2025
77 of 79 checks passed
@aido-mth aido-mth deleted the aido/81/parallel_module_execution branch September 4, 2025 15:46
@github-project-automation github-project-automation bot moved this from 🔖 Ready to ✅ Done in Catalyst Sep 4, 2025
use rayon::ThreadPoolBuilder;

/// Global counter of currently running tasks.
static TASK_COUNTER: AtomicUsize = AtomicUsize::new(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it a usize? What relationship does it have to pointers or memory? Is it used for indexing?
Unless its got something to do with memory (an index or pointer math) we should pick an appropriately sized variable type so its 100% consistent regardless of platform.
Given that its actually counting concurrently running threads, it probably never needs to be bigger than u16.

static TASK_COUNTER: AtomicUsize = AtomicUsize::new(0);

/// Synchronization primitives for waiting until all tasks finish.
static TASK_WAIT: (Mutex<()>, Condvar) = (Mutex::new(()), Condvar::new());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel if the aim here is to build a countdown latch, then we should have a countdown latch type which does that.
Seems like this is the sort of thing we would use in other places.
It would also be easier to test, in isolation.
would also make the intent of it here more obvious.

@github-project-automation github-project-automation bot moved this from ✅ Done to 🔖 Ready in Catalyst Sep 4, 2025
@rafal-ch rafal-ch moved this from 🔖 Ready to ✅ Done in Catalyst Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fyi: hermetics For information - Hermes Backend, System Development & Integration Team no-track Used to skip tracking in Swarmia analytics, etc. review me PR is ready for review rr: hermetics Required review by hermes team rust Pull requests that update Rust code squad: hermetics Hermes Backend, System Development & Integration Team
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

🛠️ [TASK] : WASM Module::call_func implementation parallelisation
5 participants