Skip to content

Conversation

@ioquatix
Copy link

Copy link
Collaborator

@matthewd matthewd 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 following up on this @ioquatix!

@ioquatix
Copy link
Author

ioquatix commented Feb 25, 2023

@matthewd can you please approve and run the workflows.

@ioquatix ioquatix force-pushed the main branch 3 times, most recently from 61269c1 to dc88886 Compare February 25, 2023 07:47
@ioquatix
Copy link
Author

There is one more piece we should consider exposing, which is the "resolve DNS" to use the fiber scheduler hook.

@ioquatix
Copy link
Author

So, writing this PR has made me realise we need a set of shims for the blocking C APIs, e.g. open, addrinfo, etc. We have the code, it's just not exposed. I supposed we can do that for Ruby 3.3.

We should also extend the test suite to run within a fiber scheduler (probably Async).

@matthewd
Copy link
Collaborator

matthewd commented Mar 2, 2023

@ioquatix is this good to go? It seems fine to me, not sure if you've kept it in draft for a reason, or just not hit the button?

@ioquatix
Copy link
Author

ioquatix commented Mar 2, 2023

It's probably as good as we can make it.. but I want to review it this weekend. This week has been pretty busy, have not had much time for open source stuff.

@kirs
Copy link

kirs commented Oct 4, 2024

👋 just wanted to say that I appreciate this WIP PR by Samuel and I'd really really love to see this happen in the upstream, and to be able to use trilogy with fiber scheduler for IO-heavy workloads.

@casperisfine
Copy link
Contributor

I'd really really love to see this happen in the upstream, and to be able to use trilogy with fiber scheduler for IO-heavy workloads.

So my knowledge of the fiber scheduler is limited, but AFAIK you can already use it today? My understanding is that this PR make it a bit more efficient, but rb_wait_for_single_fd is already enough to be usable.

As for it happening, there's not much work needed, all the blockers are listed in review comments.

@ioquatix ioquatix marked this pull request as ready for review October 25, 2024 05:24
@ioquatix
Copy link
Author

I've rebased and updated the PR.

rb_wait_for_single_fd is okay but it's a slow path. rb_io_wait is the fast path.

@matthewd can you please run CI.

@ioquatix ioquatix force-pushed the main branch 3 times, most recently from cc37ef9 to a3baae0 Compare October 25, 2024 06:47
@ioquatix ioquatix force-pushed the main branch 6 times, most recently from ab563aa to effb070 Compare October 25, 2024 07:57
@ioquatix
Copy link
Author

ioquatix commented Oct 25, 2024

I recall why I gave up on this PR for a while, we were missing rb_io_open_descriptor which is needed to create a "temporary non-owning FMODE_EXTERNAL IO instance". Since that's now available in recent CRuby, it is possible to implement it correctly.

@ioquatix
Copy link
Author

I believe all the feedback has been addressed, so this is good to go.

Copy link

@eregon eregon left a comment

Choose a reason for hiding this comment

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

What's the performance gain with this?
Is it worth the duplication of _cb_ruby_wait and additional complexity?

@ioquatix
Copy link
Author

ioquatix commented Feb 24, 2025

What's the performance gain with this?

It should be slightly more efficient, but I imagine there isn't much performance difference (except for GC overhead due to the temporary IO objects created).

Is it worth the duplication of _cb_ruby_wait and additional complexity?

I would say yes. rb_wait_for_single_fd creates a temporary IO instance for each call, which creates extra (pointless) garbage. It's better for Ruby extensions that do IO to use a proper IO object IMHO. I would like to deprecate rb_wait_for_single_fd. It's messy/difficult for some platforms to implement, e.g. JRuby.

@ioquatix
Copy link
Author

I think now that rb_trilogy_wait_protected was extracted out, maybe we can simplify this PR a little to address the complexity @eregon mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants