-
Notifications
You must be signed in to change notification settings - Fork 553
Add support for Native multithreaded execution #4201
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
Add support for Native multithreaded execution #4201
Conversation
So, I'm running this on Linux, and without 489fbb9 it tries to use
|
This is great! Thank you for pushing this forward to the next obstacle. One of the things that occurred to me as I poked at my branch originally is SN's tooling for introspecting thread state is really really limited so far as I understand it. Maybe this is just my ignorance and LLVM has some magic we could turn on, but I strongly suspect we're going to need better introspection to run down some of these problems. What I'm thinking is we're probably going to end up building that, or at least leaning in heavily to do so, and that's probably a large part of what we'll need to do to get this off the ground. We should chat with the SN folks. |
The reason it's hanging is because we haven't implemented interruption yet for the Native I/O-polling systems. This wasn't necessary when it was single-threaded, but now it's critical :)
Compare with: cats-effect/core/jvm/src/main/scala/cats/effect/unsafe/SelectorSystem.scala Lines 97 to 100 in 9ce05f2
|
Oh, the other reason it may be hanging is indeed related to GC. On Scala Native, blocking native calls need to be annotated explicitly with the For now it's fine to just mark it |
You know, I didn't even think about this. Makes loads of sense though. Pipes time! |
@armanbilge Thanks, I've tried to do the 2 things you mentioned. In 62b8141 I turned on the |
core/native/src/main/scala/cats/effect/unsafe/EpollSystem.scala
Outdated
Show resolved
Hide resolved
Interesting. So I merged your branch with
Edit: Appears to be a macOS only thing. Compiles and runs on Linux. Lovely. |
Okay got around the issue with Lorenzo's help. It's fixed in SN main, so I updated to a local snapshot (lol) on my branch and made progress. I'll dig into interruption for kqueue |
Update:
Will get back to this later. |
I pushed more. Kqueue is pretty close to working I think. |
Unexpected (expected?) bonus from @durban's fix: CI is much faster now! |
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.
As noted previously, looking for all three approvals here before merge.
For those of you with more time than sense, here's another snapshot: |
The merge-base changed after approval.
val next = if (diff != java.lang.Double.POSITIVE_INFINITY) { | ||
val next = if (diff != java.lang.Float.POSITIVE_INFINITY) { |
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.
Is this a bugfix that's not specific to Native?
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's not really a bugfix, more like a "stlye" thing; there is no real bug (i.e., it doesn't need to go into 3.6.x), because Double.POSITIVE_INFINITY == Float.POSITIVE_INFINITY
.
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 it's good (enough ;)! Opened a bunch of follow-up issues, but they are essentially just optimizations. We seem to be getting green CI consistently and on Cirrus as well which is amazing.
Huge props to Daniel and Daniel for driving this effort from start-to-finish.
The merge-base changed after approval.
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.
Nice catch
The merge-base changed after approval.
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.
@durban ready to land this? 😃
The merge-base changed after approval.
I went over this whole PR, and I have one real concern: whether we're invoking undefined behavior in Various things that we should look at (not in this PR, but probably before 3.7.0):
|
Oh that's fascinating. Can you open an issue on our side to track this so we don't lose it? I wouldn't want to do a proper 3.7 with that question outstanding.
Yeah I think @armanbilge has an issue for this. It's going to be dependent on getting
I don't think so. It's bounded by the number of distinct lambdas (not closures), no?
Can you make an issue for this one too? Agreed we should look really carefully at them.
I think it was cargo-culted from Scala.js, where in turn I cargo-culted it from the original I don't think it was ever needed on Native.
Oh, that feels like a bug. I wonder if we should pull that back? |
Can you share more details (maybe a follow-up issue)? I saw your SN issue but I didn't have a chance to think about it carefully.
It's keyed by classes, and there's a finite number of classes in a compiled artifact.
It wasn't a mistake. We don't need it anymore. We needed it before because we couldn't block on completion of the main fiber in the main method. e.g. consider an application that is just
JS doesn't really support pollers ... you're relying on the runtime for this. Did we put |
@djspiewak @armanbilge Okay, I promise I'll open an issue for everything you've mentioned, just not right now... |
This is on top of @djspiewak's
wip/multithreaded-wstp
branch.I did nothing so far, except default toSleepSystem
in 489fbb9. This makes it possible to runIOSpec
on scala-native; it (sometimes) passes on my machine ;-). It's probably too early to have this as a PR, but I'm doing it anyway to avoid duplicating work, and maybe to have a discussion aboutEpollSystem
(see below). (@djspiewak feel free to close this PR if you have other plans with your branch.)