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

Parallelize State call in ECM #451

Merged
merged 35 commits into from
Jan 15, 2021
Merged

Parallelize State call in ECM #451

merged 35 commits into from
Jan 15, 2021

Conversation

JShep1
Copy link

@JShep1 JShep1 commented Nov 6, 2020

Ready for review. Below is a plot of 25 randomly sampled PostUpdate profiled points for both before and after this PR.

The before average timestep of PostUpdate was 33.095 ms and after average time for PostUpdate is 22.479 ms in the case of the shapes_population.sdf. This PR is primarily targeted for larger example and will not significantly affect smaller examples (if there are under 50 entity components, no speedup will occur at all due to the nature of the thread spawning in this PR).

My RTF before this PR after 2 minutes of running shapes_population.sdf was 0.602% and after the PR I am getting about 0.669% RTF.

Multi-Threading Results (shapes_population sdf)

I'm going to experiment with the the number of threads and the number of components each thread handles to see if I can tune these two parameters to get a more optimized RTF. I don't think changing the max thread count to anything higher than std::thread::hardware_concurrency() (the max suggested threads that the hardware supports) would speed up anything, this would likely just bottleneck any additional threads and schedule them in when it puts other threads to sleep. Perhaps we could see some speedup with the amount of entity components each thread will run at minimum, but I'm not so sure this would make a huge difference either, it would only affect scenes in which there are between componentsPerThread and componentsPerThread * maxThreads entity components.

John Shepherd added 18 commits October 14, 2020 12:22
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
Signed-off-by: John Shepherd <[email protected]>
@github-actions github-actions bot added the 🏰 citadel Ignition Citadel label Nov 6, 2020
@JShep1 JShep1 changed the base branch from ign-gazebo3 to jshep1/scenebroadcaster_optimizations2 November 10, 2020 00:48
@JShep1 JShep1 changed the base branch from jshep1/scenebroadcaster_optimizations2 to ign-gazebo3 November 10, 2020 00:48
@iche033
Copy link
Contributor

iche033 commented Nov 12, 2020

Here's what I got comparing performance of the State function before (top image) and after (bottom image) the change:

threaded_state

This is from running the shapes_population.sdf world. It does look there it shaved a few ms off the State function. When running with TPE plugin, the RTF before the change is 1.4x% and after is 1.8x%.

Note careful about using remotery for profiling. I noticed that since new threads are spawned every iteration, it made remotery a bit laggy and unresponsive sometimes.

@JShep1
Copy link
Author

JShep1 commented Nov 12, 2020

Good to see that you're seeing improvements... I guess Remotery was a bit wonky for me given all the threads spawning. I'll clean up the logic and make it more generalizable and get the PR in for review soon.

@iche033
Copy link
Contributor

iche033 commented Nov 12, 2020

by the way, I wonder if it's possible to reuse threads, e.g. store in member variable?, and have them wait on a condition_variable until there's work to do.

@JShep1
Copy link
Author

JShep1 commented Nov 12, 2020

by the way, I wonder if it's possible to reuse threads, e.g. store in member variable?, and have them wait on a condition_variable until there's work to do.

That's also what I was thinking and was going to attempt something like that. It would certainly reduce noise in Remotery as well as cut down any overhead from spawning so many threads every iteration.

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

I tested by adding and deleting objects in a shapes.sdf, and spawning objects from fuel and it seems to be work fine for the case of single thread.

Interestingly, I tried shapes_population.sdf and noticed that a sphere is missing (sphere_534):

missing_sphere

I also tried generating a shapes_population.sdf world with n set to 100 and I see a couple of models missing. Do you see the same issue?

src/EntityComponentManager.cc Outdated Show resolved Hide resolved
@JShep1
Copy link
Author

JShep1 commented Dec 17, 2020

I also tried generating a shapes_population.sdf world with n set to 100 and I see a couple of models missing. Do you see the same issue?

Good catch, took me a little bit to find the bug, but I resolved it here: 0ba4684

@JShep1 JShep1 requested review from iche033 and chapulina December 17, 2020 04:45
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

The number of objects in shapes_populations.sdf are now correct for me.

I'll leave it to you and @chapulina to decide on the number of threads to use. Otherwise the PR looks good.

src/EntityComponentManager.cc Outdated Show resolved Hide resolved
src/EntityComponentManager.cc Outdated Show resolved Hide resolved
@chapulina chapulina added the performance Runtime performance label Jan 5, 2021
@JShep1 JShep1 requested a review from chapulina January 8, 2021 01:45
chapulina added a commit that referenced this pull request Jan 14, 2021
Signed-off-by: Louise Poubel <[email protected]>
@chapulina chapulina mentioned this pull request Jan 14, 2021
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements!

@chapulina
Copy link
Contributor

The ABI checker is having the same old false positive. All other CI looks good. Merging!

@chapulina chapulina merged commit ddd7fcd into ign-gazebo3 Jan 15, 2021
@chapulina chapulina deleted the jshep1/parallelize_ecm branch January 15, 2021 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel enhancement New feature or request performance Runtime performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants