-
Notifications
You must be signed in to change notification settings - Fork 5.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
Thread Scheduler for light weight concurrency. #1870
Conversation
62ffa82
to
a2d3b45
Compare
86287d1
to
9d83559
Compare
Okay I will resume work on this issue. |
@hkdnet I fixed that issue. Thanks :) |
@funny-falcon here is updated example using As you can see it require no change to underlying C since the scheduler is implemented in pure Ruby. |
I have rebased on trunk so that tests will run. |
What's the status of this feature? Will it be merged? |
I would like to think we can merge this sooner rather than later. It's minimal surface area and the potential benefit is huge. That being said, I think that the action of merging this, gently tugs on the rudder controlling the direction of Ruby, and that part might require the input of the captain. So, it's not really my place to merge it, but requires further discussion with Matz et al. |
@ioquatix This looks very simple and not invasive for the implementation, so that's definitely a very nice aspect of it. I'm not super familiar with selectors, but is having hooks in |
@eregon yes it's correct, users need to explicitly opt into |
@ioquatix What about things like |
A better solution would be to make all IO non-blocking in the context of a Thread with a selector defined, but I think I just wanted to keep this POC simple. |
Keep in mind, with |
Are you going to RubyKaigi? That could be a good venue to engage Matz in. I think this addition would jive quite well with Ruby 3x3. There are a lot of us glued to MRI. Working with MRI changes is much easier than switching to JRuby for quite a number of people. |
Yes, I am going to RubyKaigi to discuss it with Matz. The design goal of this PR is to be simple enough that the majority of Ruby platforms can support it. |
@ioquatix how'd it go? |
I got buy in from JRuby and TruffleRuby so we are going to push forward on those fronts to start with, to prove the concept. |
b5d0135
to
41cb0d1
Compare
I don't know if I'd say that 😁 Without a design document that we can iterate on I will not commit to anything. We need to see and discuss the design before moving forward. |
@MSP-Greg do you have any idea why https://github.com/ruby/ruby/pull/1870/checks?check_run_id=584638152#step:14:887 is failing? |
We discussed it years ago and you said you were keen to try it out :) |
Sorry, stuffed up the PR, here is the link: #3032 |
Re the MinGW SSL errors, MSYS2's OpenSSL uses a path relative to the exe file for the location of Hence, using |
@MSP-Greg thanks for the quick reply. I'll try using |
Ruby concurrency can be greatly enhanced by concurrent, deterministic IO.
Fibers have been shown many times to be a great abstraction for this purpose. They retain normal code flow and don't require any kind of Thread synchronisation. They are enjoyable to write code with because you don't have to concern yourself with thread synchronisation or other complicated issues.
The basic idea is that if some operation would block, it yields the Fiber, and other Fibers within the thread can continue to execute.
There are a number of ways to implement this. Here is a proof of concept to amend the existing rb_io_wait_readable/rb_io_wait_writable.
This design minimally affects the Ruby implementation and allows flexibility for selector implementation. With a small amount of work, we can support EventMachine (65 million downloads), NIO4r (21 million downloads). It would be trivial to back port.
This PR isn't complete but I am seeking feedback. If it's a good idea, I will do my best to see it through to completion, including support for EventMachine and NIO4r.
https://bugs.ruby-lang.org/issues/14736