-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 usage of ThreadManagerSubsystem with reactor Scheduler #4799
refactor: replace usage of ThreadManagerSubsystem with reactor Scheduler #4799
Conversation
public static Scheduler io() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::io); | ||
} | ||
|
||
public static Scheduler newThread() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::newThread); | ||
} | ||
|
||
public static Scheduler computation() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::computation); | ||
} | ||
|
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 need to have these in a privileged scope.
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 do they need to be in privileged scope? Let's document this here for the future.
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.
a lot of thread actions are guarded by the sandbox.
This pull request introduces 1 alert when merging a01066a into 614315e - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging c9b8f11 into 7409510 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging eb44e11 into 7409510 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 11a257a into fbeed19 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 23b174e into fbeed19 - view on LGTM.com new alerts:
|
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.
Please also have a look at the alert reported by LGTM
@@ -18,14 +23,33 @@ | |||
* </ul> | |||
* | |||
*/ | |||
@API |
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 did the GameThread
become public API?
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 a separate API?
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.
see #4799 (comment)
public static Scheduler io() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::io); | ||
} | ||
|
||
public static Scheduler newThread() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::newThread); | ||
} | ||
|
||
public static Scheduler computation() { | ||
return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::computation); | ||
} | ||
|
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 do they need to be in privileged scope? Let's document this here for the future.
.add("io.reactivex.rxjava3.annotations") | ||
.add("io.reactivex.rxjava3.core") | ||
.add("io.reactivex.rxjava3.disposables") | ||
.add("io.reactivex.rxjava3.exceptions") | ||
.add("io.reactivex.rxjava3.flowables") | ||
.add("io.reactivex.rxjava3.functions") | ||
.add("io.reactivex.rxjava3.internal") | ||
.add("io.reactivex.rxjava3.observables") | ||
.add("io.reactivex.rxjava3.observers") | ||
.add("io.reactivex.rxjava3.parallel") | ||
.add("io.reactivex.rxjava3.plugins") | ||
.add("io.reactivex.rxjava3.processors") | ||
.add("io.reactivex.rxjava3.schedulers") | ||
.add("io.reactivex.rxjava3.subjects") | ||
.add("io.reactivex.rxjava3.subscribers") |
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.
How did you decide what to add here, and what is not added (assuming that there must be something we leave out, or otherwise we could have used a single entry io.reactivex.rxjava3
).
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.
This particular diff has been changed to replace the rxjava packages with reactor packages, but the same question still applies.
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.
or otherwise we could have used a single entry
io.reactivex.rxjava3
I took a look at the places that use this list (which is both in this repo and nui-reflect), and it seemed like it was all .equals
without any wildcard or prefix matching.
@@ -153,16 +154,16 @@ public static void main(String[] args) { | |||
engine.run(new StateHeadlessSetup()); | |||
} else if (loadLastGame) { | |||
engine.initialize(); //initialize the managers first | |||
engine.getFromEngineContext(ThreadManager.class).submitTask("loadGame", () -> { |
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.
It looks like with ThreadManager
we could give the tasks a name such that they are identifiable later, e.g., in logs. Is there a similar concept in RxJava?
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.
It looks like there is a subscriber Context that is useful for things like this.
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.
#4839 added a GameScheduler.scheduleParallel
method that takes a name which it uses in the same way as ThreadManager.submitTask did.
It doesn't address future use cases where we take advantage of Flux's model for pipelines, but it suffices for one-shot Runnables like this.
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.
should be fine for our use cases. i'm not too happy but it should be good for our use cases at this point. not really a ThreadMonitor though :?
….com:MovingBlocks/Terasology into refactor/remove-usage-ThreadManagerSubsystem
This pull request introduces 1 alert when merging cc44241 into acb3181 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 7cf9a36 into acb3181 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 875b4d3 into d3d4a8c - view on LGTM.com new alerts:
|
This reverts commit 27e8b0e.
…isting ThreadMonitor
I brought this up in today's meeting, and it wasn't clear to any of us if/when modules need access to this. skaldarnar's proposal was to leave this implemented, but at a permission level modules wouldn't be able to actually use, with a comment along the lines of "change this if we have a documented use case for it" or something like that. (I don't think we can implement it exactly as proposed, because I don't think the |
how do you propose letting a module schedule something back on the main thread? |
Try to take screenshot:
Need to initialize schedulers eager. Or add warp this place with |
Some discussion convinced me we do have a use case that requires this: We want to allow modules to make OpenGL calls, so we must give them a way to run things on the thread that owns the OpenGL Context. (OpenGL works by pushing things on to a command queue, and you don't want to be mixing that up by doing it from multiple threads.) While we don't currently have module code that makes use of GameThread for OpenGL this way, it's not much of a stretch for me to see that we might. Especially as we use Reactor to move more work off the main thread. |
@keturn CoreRendering is using opengl from modules. |
Oh, this is my fault! When I wrote the method that takes the task name, I didn't run it through the other method with the AccessController wrapping. I'll try the eager initialization. |
Eager works nice. |
Privileges are only required for initialization; this way we don't need `doPrivileged` in the public method.
…age-ThreadManagerSubsystem
…age-ThreadManagerSubsystem
This pull request introduces 1 alert when merging fd32176 into 66264a8 - view on LGTM.com new alerts:
|
fd32176
to
c80f299
Compare
This pull request introduces 1 alert when merging c80f299 into 66264a8 - view on LGTM.com new alerts:
|
eh? that's weird, LGTM-bot. |
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.
Okay, I think the permission-modifying code is isolated enough and adequately commented now.
As for the matter of why we never had to add PermissionProperties before, I think it's a combination:
- The old ThreadManager seems to have been running code outside the security context, so it's possible things were sneaking by, but mostly
- There aren't that many things called from the module sandbox that require reading system properties.
I'm totally stumped on why wildcards don't work for PermissionProperties, but I am not worried enough about the maintenance cost of that list to put more importance on it for the time being.
I already tried wildcards :P |
This replaces the ThreadManagerSubsystem with Scheduler provided by rxjava. pretty straightforward since this subsystem is only ever used in the core engine and not to an extent that would make sense. the threads allocated are mostly unused and sit idle.
toTest:
Contributes to #4798