ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:81044] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip]
Date: Tue, 9 May 2017 03:38:06 +0000	[thread overview]
Message-ID: <20170509033806.GA27973@starla> (raw)
In-Reply-To: <4a83bbeb-b22b-61ec-a03f-657746843431@atdot.net>

SASADA Koichi <ko1@atdot.net> wrote:
> On 2017/05/08 15:36, Eric Wong wrote:
> > Maybe; if we can avoid GVL and introduce more parallelism.
> >
> > However, I think having one epoll/kqueue FD is better for a
> > whole process; maybe one epoll/kqueue per-core (not per-thread)
> > at maximum.
> >
> > I can easily imagine Ruby doing 100 native threads in one process
> > (8 cores, 10-20 rotational disks, 2 SSD), but 20000-30000 fibers.
> 
> could you elaborate more? 100 epoll threads are not effective?
> Honestly, I have no experience to use epoll/kqueue.

100 epoll FDs is a waste of FDs; especially since it is common
to have a 1024 FD limit.  I already feel bad about timer thread
taking up two FDs; but maybe epoll/kevent can cut reduce that.

In the kernel, every "struct eventpoll" + "struct file" in
Linux is at least 400 bytes of unswappable kernel memory.

Anyways, I've contributed bugfixes to both epoll in the Linux
kernel and also to libkqueue (userspace emulation lib);
and use them both in several projects in and outside of Ruby.

> # context switching to another topic
> 
> > Side note: First, I would like to make fibers smaller.
> > Right now rb_fiber_t stores all of the rb_thread_t
> > struct, but not all fields get used.  I started to work on
> > splitting out to a new struct rb_thread_context_t earlier:
> ...
> > The end goal is to avoid storing all of rb_thread_t inside
> > rb_context_t/rb_fiber_t; and only store rb_thread_context_t.
> > That should reduce memory overhead and maybe make switching
> > faster.
> 
> This is what my goal of Ruby 2.5 (2017) I proposed to my company. If you
> do it, it's great (and I achieved one of my job :)).
> 
> My plan is almost similar but I want to introduce something like
> `mrb_state` which passed to all mruby functions as first argument.
> 
> Do you want to commit this patch before your final goal (lightweight
> fiber switching)?
> 
> 
> FYI: my plan.
> 
> (1) Make separate execution context and make fiber switching lightweight
>   * before 2.5
>   * You named `rb_thread_context_t`, but I don't want to name `thread`
>     so I planned to name it `execution_context` and so on (a bit longer)

OK, I can rename my work-in-progress patch with
s/rb_thread_context_t/rb_execution_context_t/ and commit
later tonight.

> (2-1: extend Fiber) Add Fiber scheduler like you are thinking.
> (2-2: toward Guild) Add `execution_context` as first argument to
>     all C APIs
>   * to keep compatibility, we need to introduce new prefix `rbX_...`
>     for new APIs which receive first argument.
>   * On mruby, `mrb_state` is passed to all of APIs. We need to consider
>     the passed information carefully.

OK, that sounds good.

Also, can you take a look at implementing [Feature #13434]
"better method definition in C API" for rbX_*?
You are more knowledgeable in VM + method definition area;
while I can work on the epoll/kqueue parts for I/O scheduling.

(but I will need to schedule my own human time to work on Ruby :)

  reply	other threads:[~2017-05-09  2:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170402011414.AEA9B64CEE@svn.ruby-lang.org>
     [not found] ` <8a2b82e3-dc07-1945-55f9-5a474e89130b@ruby-lang.org>
2017-04-02  2:35   ` [ruby-core:80531] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] Eric Wong
2017-04-02  3:05     ` [ruby-core:80532] " SASADA Koichi
2017-04-03  4:42       ` [ruby-core:80540] " Eric Wong
2017-05-08  0:33         ` [ruby-core:81027] " Eric Wong
2017-05-08  1:53           ` [ruby-core:81028] " SASADA Koichi
2017-05-08  2:16             ` [ruby-core:81029] " SASADA Koichi
2017-05-08  3:01               ` [ruby-core:81031] " Eric Wong
2017-05-08  3:42                 ` [ruby-core:81033] " SASADA Koichi
2017-05-08  6:36                   ` [ruby-core:81035] " Eric Wong
2017-05-09  2:18                     ` [ruby-core:81042] " SASADA Koichi
2017-05-09  3:38                       ` Eric Wong [this message]
2017-05-09  4:11                         ` [ruby-core:81045] " SASADA Koichi
2017-05-09  5:12                           ` [ruby-core:81047] " Eric Wong
2017-05-09  5:47                             ` [ruby-core:81049] " SASADA Koichi
2017-05-09  6:23                               ` [ruby-core:81053] " Eric Wong
2017-05-09  6:44                                 ` [ruby-core:81054] " SASADA Koichi
2017-05-09 18:51                                   ` [ruby-core:81078] " Eric Wong
2017-05-10  3:24                                     ` [ruby-core:81083] " SASADA Koichi
2017-05-10 10:04                                       ` [ruby-core:81089] " Eric Wong
2017-05-19  4:34                                         ` [ruby-core:81244] " Eric Wong
2017-06-20 19:16                                   ` [ruby-core:81733] " Eric Wong
2017-05-09  5:54                             ` [ruby-core:81050] " SASADA Koichi
2017-05-09  6:15                               ` [ruby-core:81052] " Eric Wong
2017-05-08  2:56             ` [ruby-core:81030] " Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170509033806.GA27973@starla \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).