Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Extend FFI::Platform::POSIX with faster native IO methods #2078

Open
sempervictus opened this Issue · 0 comments

2 participants

@sempervictus

Several gems exist in the community allowing for fast IO operations using c bindings to kernel IO functionality. ruby_io_splice (http://bogomips.org/ruby_io_splice/), io-extra (http://rubydoc.info/gems/io-extra/1.2.6/frames), and sleepy_penguin (http://bogomips.org/sleepy_penguin/) are good examples of this.

Placing this functionality into FFI, with analogous calls for other platforms where possible can yield considerable performance gains over current IO implementation by avoiding user space interaction where possible, and may provide a foundation for rewriting/extending ::IO further.

Example: eventfd (http://www.kernel.org/doc/man-pages/online/pages/man2/eventfd.2.html)

module EventFd
extend FFI::Library
attach_function :eventfd, [:int, :int], :int
attach_function :close, [:int], :int
end

efd = EventFd.eventfd(0,0)
io = IO.new(efd)

The "io" object is now a selectable, readable, writable IO object. There are issues with how InternalBuffer keeps track of R/W position, though should suffice for PoC.

C ext implementation of eventfd (far more complete, but IMO less readable) is at http://bogomips.org/sleepy_penguin.git/tree/ext/sleepy_penguin/eventfd.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.