GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — Answer zero-timeout IO.select with one poll(2) call by sampokuokkanen · Pull Request #9865 · jruby/jruby Conversation
Contributor
A zero-timeout A zero timeout cannot block, so none of that registration is needed to keep it interruptible. When native support is on and every IO has a real, selectable descriptor, check them with poll(2) directly, falling back to the selectors otherwise. Buffered read data still counts as ready, and a socket with a connect in progress goes to the selectors, which finish the connect once it is writable. Readiness is collected per descriptor because macOS reports a descriptor that appears twice in only one of its pollfds.
The POLL* values are the ones Linux, macOS, the BSDs and Solaris share; other systems, such as AIX, keep using the selectors.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsA zero-timeout IO.select registered every channel with a pooled selector, polled it, then cancelled the keys and polled again to flush them before returning the selector. io-event's select backend makes this call on every turn of the event loop. A zero timeout cannot block, so none of that registration is needed to keep it interruptible. When native support is on and every IO has a real, selectable descriptor, check them with poll(2) directly, falling back to the selectors otherwise. Buffered read data still counts as ready, and a socket with a connect in progress goes to the selectors, which finish the connect once it is writable. Readiness is collected per descriptor because macOS reports a descriptor that appears twice in only one of its pollfds. IO.select([r], [w], nil, 0) on a pipe, on an M1 Pro, drops from 14.8us to 1.0us per call, about 14 times faster; MRI 4.0 takes 1.2us. The POLL* values are the ones Linux, macOS, the BSDs and Solaris share; other systems, such as AIX, keep using the selectors.
sampokuokkanen
force-pushed
the
select-zero-timeout
branch
from
59d1943 to
eb9e472
Compare
The poll path took the array sizes once, so a #to_io that shrinks the array it was found in made it read past the end and raise TypeError, where the selectors and MRI return nil. Poll over copies instead. The except array is now checked after the read and write arrays and for its write IO as well, as selectInternal and MRI's select_internal do, and the struct pollfd fields get named offsets.
sampokuokkanen
force-pushed
the
select-zero-timeout
branch
from
eb9e472 to
7d3195b
Compare
The pollfds buffer is kept per thread, so a #to_io that runs another zero-timeout IO.select overwrote the entries already filled in, and the outer select could miss a ready IO. Collect the descriptors first and fill the buffer just before poll(2), once no Ruby code can run. PollSelect itself is only loaded on the first zero-timeout select, so a holder class makes the loading no lazier.
headius
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes good sense, but I'm sure large parts of this should live in jnr-enxio instead of here. The selector registration process in NIO is cumbersome, but when we know we have an ENXIO native channel we could call a method on it that hides all of this native logic rather than maintaining it here. That would then be usable by other consumers of ENXIO and less maintenance burden for JRuby core. Make sense?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
sampokuokkanen
marked this pull request as draft
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |