From: eregontp@...
Date: 2020-08-18T09:07:29+00:00
Subject: [ruby-core:99624] [Ruby master Feature#17059] epoll as the backend of IO.select on Linux

Issue #17059 has been updated by Eregon (Benoit Daloze).


dsh0416 (Delton Ding) wrote in #note-16:
> I would try to use these methods to deal with the registration then, and replace the `IO.select` in the `Scheduler#run` for performance.

Where do you see `IO.select` in the `Scheduler`?
Here? https://github.com/ruby/ruby/blob/701217572f865375b137d2830d4da0c3e78de046/test/fiber/scheduler.rb#L44
That's a test scheduler, and using `IO.select()` is good enough for prototyping but basically nothing else.

@ioquatix it seems worth clarifying that with a comment there.
Might also be worth linking to the async scheduler as a real-world example there or in `doc/fiber.rdoc`.

Real schedulers like the one for `async` use epoll/kqueue/libev/etc internally, for instance by using `nio4r`.

----------------------------------------
Feature #17059: epoll as the backend of IO.select on Linux
https://bugs.ruby-lang.org/issues/17059#change-87105

* Author: dsh0416 (Delton Ding)
* Status: Rejected
* Priority: Normal
----------------------------------------
Current Ruby's `IO.select` method calls POSIX `select` API directly. With the new non-blocking scheduler, this may be the bottleneck of the I/O scheduling. For keeping the backward compatibilty of the current `IO.select` methods, a proposal may be to create a "duck" `select` which uses the `epoll_wait` as the backend.

One tricky part is that the `fd_set` described in POSIX is write-only, which means it is impossible to iterate for generating the `epoll_event` argument for `epoll_wait`. But similar to the large-size select situation, we could define our own `rb_fdset_t` struct in this case, and implement the following APIs.

```
void rb_fd_init(rb_fdset_t *);
void rb_fd_term(rb_fdset_t *);
void rb_fd_zero(rb_fdset_t *);
void rb_fd_set(int, rb_fdset_t *);
void rb_fd_clr(int, rb_fdset_t *);
int rb_fd_isset(int, const rb_fdset_t *);
void rb_fd_copy(rb_fdset_t *, const fd_set *, int);
void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src);
int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
```

TODO:
1. Implement the fd_set with dynamic allocated fds.
2. Implement the epoll with select API.
3. Edit io.c to use the customized fd_set struct.

I'm trying to work on a branch for this. Any suggestions for this?

---Files--------------------------------
epoll.h (3.62 KB)
epoll.h (6.44 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>