-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor: replace TaskMaster with Reactor #24
base: develop
Are you sure you want to change the base?
Conversation
src/main/java/org/terasology/flexiblepathfinding/PathfinderSystem.java
Outdated
Show resolved
Hide resolved
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.
I think that once we resolve the concern I've noted with JPSImpl.timeLimiter
, this is a fine stepping stone on the Reactor path. It'll let us move on with removing the TaskMaster
class while not disturbing any more than it needs to.
If anyone is actually maintaining this module, they'll want to do another pass later that replaces the old callback-based interfaces with Reactor-compatible asynchronous functions.
src/main/java/org/terasology/flexiblepathfinding/PathfinderSystem.java
Outdated
Show resolved
Hide resolved
src/main/java/org/terasology/flexiblepathfinding/PathfinderSystem.java
Outdated
Show resolved
Hide resolved
boolean result = Boolean.TRUE.equals(Mono.fromCallable(this::performSearch) | ||
.subscribeOn(GameScheduler.parallel()) | ||
.block(Duration.ofMillis((long) (config.maxTime * 1000.0f)))); |
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.
We want to be very careful about when we call block
, right?
This looks weird, because if I understand correctly, this JPSImpl#run
is called by PathfinderSystem#processPath
, which was already sent to run on GameScheduler.parallel()
by PathfinderSystem#requestPath
.
So this is executing on the parallel scheduler, and it adds a new thing to that scheduler, and then blocks one of that scheduler's threads—that sounds like a good way to get a logjam, requiring later tasks to complete before earlier ones yield.
It also looks like the old implementation only did that timeLimiter
stuff if config.executor
was non-null. Can we get away with dropping that feature?
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.
lets do that in another PR. this is just migrating the existing code over.
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.
Oh, I found where it set config.executor
: it was in PathfinderSystem.requestPath. It looks like it did have a second task queue for that purpose. That means this replacement where it's using the same scheduler for both is not equivalent.
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.
I reverted the removal of the TimeLimiter
usage as I don't understand why it is necessary for replacing TaskMaster
with Reactor.
Also, I believe I'm using a new thread for the code path without the time limiter now, so the issue @skaldarnar reported below should be gone. At least when testing this in CoreGameplay
+ WildAnimals
by spawning a deer, I didn't get any exceptions as far as I can see.
…ncurrency-Reactivex # Conflicts: # src/main/java/org/terasology/flexiblepathfinding/JPSImpl.java # src/main/java/org/terasology/flexiblepathfinding/PathfinderSystem.java # src/main/java/org/terasology/flexiblepathfinding/PathfinderTask.java # src/main/java/org/terasology/flexiblepathfinding/ShutdownTask.java
Did a quick test run with after the migration with the
The log about a "Timeout of 10.0" is misleading here (see correction in #26). |
That looks like what I was worried about. |
Gave it a test run under JS. The good news:
The bad news:
Point for comparison: In Core Gameplay, CPU avg across all CPUs is more like 10%, and memory usage is stable. but I guess for PR purposes, the relevant point for comparison is the state of the same game configuration with and without the PR, not compared to Core Gameplay. 🤔 |
More testing:
|
@keturn Regarding spawns, you can always use |
public int requestPath(JPSConfig config, PathfinderCallback callback) { | ||
if (config.requester != null && config.requester.exists()) { | ||
if (entitiesWithPendingTasks.contains(config.requester)) { | ||
return -1; | ||
} | ||
entitiesWithPendingTasks.add(config.requester); | ||
} | ||
|
||
if (config.executor == null) { | ||
config.executor = workerTaskMaster.getExecutorService(); |
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.
The question I have left on this review is: If this assignment of config.executor
goes away, is there anything left using config.executor
at all?
and if not, does that mean we never use TimeLimiter?
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.
Probably that's the case (although we should double-check), yes.
Question for me is, if we don't use it, do we create a negative impact on performance? And if so, how can we model the timeout logic using Reactor / GameScheduler
?
As discussed in today's contributor meeting: let's note down a test plan to check for potential performance impact in searching for valid paths and remove the time limiter logic with a comment to reintroduce it or remodel it with Reactor in case of issues. |
- unclear performance impact without timeout logic - if performance issues arise, reintroduce or reimplement with Reactor
…tivex' into refactor/rework-concurrency-Reactivex
So my first performance test plan was simply to spawn 42 deer in a CoreGameplay + WildAnimals module combo and look at the FPS... Good news: With the current |
What this PR does
TaskMaster
withGameScheduler
, creating and runningJPSImpl
on a separate threadTaskMaster
(viaTimeLimiter
logic)Test Plan
Do the following once for each of the
FlexiblePathfinding#develop
andFlexiblePathfinding#refactor/rework-concurrency-Reactivex
branches:CoreGameplay
world with addedWildAnimals
module and depsspawnPrefab deer
To Do
PR: (MovingBlocks/Terasology#4798, MovingBlocks/Terasology#4799)