-
Notifications
You must be signed in to change notification settings - Fork 24
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
Improve parallelism for 'moon test' #296
Conversation
From the provided
These observations focus on efficiency, safety, and idiomatic Rust practices. Adjustments should be made based on the specific requirements and constraints of your application. |
I compare the run time of the main branch and this patch in the standard library core by using the command |
moonc_opt: &MooncOpt, | ||
moonbuild_opt: &MoonbuildOpt, | ||
moonc_opt: MooncOpt, | ||
moonbuild_opt: MoonbuildOpt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change the param type from &MoonbuildOpt to MoonbuildOpt and use Arc::clone() below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MoonbuildOpt
(and MooncOpt
and ModuleDB
) need to be shared in multiple threads, so Arc
is needed. And the Arc::new
want to move the value instead of getting a reference, so I change the parameter.
let mut res_handlers = vec![]; | ||
for handler in handlers { | ||
// Submit tasks to the scheduler | ||
res_handlers.push(runtime.spawn(handler)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need another res_handlers
and spawn
here? IMO the previous runtime.block_on(futures::future::join_all(handlers))
is easy to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using runtime.block_on(futures::future::join_all(handlers))
, the threads created by tokio
are never used. Because the tasks are never spawned/submitted to the scheduler, all of them are run in the current thread. You can debug the code or/and print the thread id in method entry.rs::execute_test
to verify it.
0a5b35f
to
b3d1599
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Currently, when using the command
moon test
,moon
will create 16 threads by using thetokio
library. But these 16 threads will never be used after creating. And these 16 threads become more strange when combining with the argument--no-parallel
. It is a misuse of the librarytokio
.This patch, which want to fix the issue, contains the following features:
--no-parallel
is not provided, run the tests parallellytokio
runtime scheduler (use the threadstokio
created to run the test)--no-parallel
is provided, run the tests sequentiallyThanks for your review.
Related Issues
Type of Pull Request
Does this PR change existing behavior?
Does this PR introduce new dependencies?
Checklist: