-
Notifications
You must be signed in to change notification settings - Fork 180
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
Make pg more Ruby-3.0 fiber scheduler friendly #342
Comments
Awesome, let me know if I can provide any further help :) cc @tenderlove |
I just wrote a PoC class PG::Connection
module FiberScheduler
[
:exec, :query, :exec_params, :prepare,
:exec_prepared, :describe_portal, :describe_prepared
].each do |method|
module_eval <<-CODE, __FILE__, __LINE__ + 1
def #{method}
Fiber.scheduler.io_wait(socket_io, IO::WRITABLE, 5)
super
Fiber.scheduler.io_wait(socket_obj, IO::READABLE, 5)
end
CODE
end
end
include FiberScheduler
end then do set It's dirty, but pass all tests (except Any directive or guidance? A question, I'm stucking on adding |
@larskanis @ioquatix could you take a look PR #364 ? I'm done a PR:
Todo:
Help needed:
|
If the scheduler is set you should use non-blocking event driven I/O. There shouldn't be a need to add |
You're right, I redo my work, only 2 test cases I don't know how to fix https://github.com/ged/ruby-pg/blob/master/spec/pg/connection_spec.rb#L1670-L1695 |
One pain point I've met is somewhere hanging when fiber scheduler enabled, but I don't know where. |
|
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
…iber.scheduler Fixes ged#342
This was raised by @ioquatix in ffi/ffi#797 (comment) :
In order to support the upcoming Ruby 3.0 fiber scheduler, you need to do only one thing:
When you would call a blocking function that does I/O, instead call
IO#wait_readable
orIO#wait_writable
respectively.If you want to support Ruby 2.x, then allow the user to inject a custom IO class, which responds to
.new
and implements#wait_readable
and#wait_writable
.You can check how to do it here:
https://github.com/socketry/db-postgres/blob/6fbdd03dd6b04c57c5b7995b60e3f626c674e609/lib/db/postgres/native/connection.rb#L106-L139
We will be augmenting the C interface with some improvements for invoking
IO#wait_readable/wait_writable
but it hasn't landed yet.Feature description is here: https://bugs.ruby-lang.org/issues/16786
The text was updated successfully, but these errors were encountered: