ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: samuel@oriontransfer.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:87777] [Ruby trunk Feature#14736] Thread selector for flexible cooperative fiber based concurrency
Date: Wed, 04 Jul 2018 08:08:33 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-72799.20180704080831.9ff1207970ee5d43@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14736.20180504031225@ruby-lang.org

Issue #14736 has been updated by ioquatix (Samuel Williams).


@normalperson that's awesome, great effort! I really appreciate you taking these PRs seriously and the effort you are putting into it.

I'd love to have a systematic comparison. Honestly, the port scanner isn't a great benchmark because port scanning is either limited by system resources (scanning localhost) or heavily network bound (scanning remote system).

Considering that `async` is pure ruby on a single thread, 3x slower is actually pretty good. If we merge this PR (Thread.selector), I can probably improve performance quite a bit.

Your implementation of `Threadlet` could be easily implemented in terms of the PR suggested here. But this PR allows flexibility for other implementations (like NIO4r). I still think that flexibility is pretty important, especially considering it will allow JRuby to implement it without too many changes.

The benefit of stackful coroutines is they make blocking completely transparent. If you look at the go code, it's a lot more complex, requires synchronisation, etc. The feedback I had about async was it was super easy to use. My priority is good API followed by performance.

Honestly, I really liked the performance of the go code, and the design is really great, but I don't think it's good for general purpose computing. Most people will find the required locking/synchronisation too complex.

----------------------------------------
Feature #14736: Thread selector for flexible cooperative fiber based concurrency
https://bugs.ruby-lang.org/issues/14736#change-72799

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby concurrency can be greatly enhanced by concurrent, deterministic IO.

Fibers have been shown many times to be a great abstraction for this purpose. The retain normal code flow and don't require any kind of Thread synchronisation. They are enjoyable to write code with because you don't have to concern yourself with thread synchronisation or other complicated issues.

The basic idea is that if some operation would block, it yields the Fiber, and other Fibers within the thread can continue to execute.

There are a number of ways to implement this. Here is a proof of concept to amend the existing `rb_io_wait_readable`/`rb_io_wait_writable`.

https://github.com/ruby/ruby/pull/1870

This design minimally affects the Ruby implementation and allows flexibility for selector implementation. With a small amount of work, we can support EventMachine (65 million downloads), NIO4r (21 million downloads). It would be trivial to back port.

This PR isn't complete but I am seeking feedback. If it's a good idea, I will do my best to see it through to completion, including support for EventMachine and NIO4r.

---Files--------------------------------
port_scanner_threadlet.rb (925 Bytes)


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

  parent reply	other threads:[~2018-07-04  8:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14736.20180504031225@ruby-lang.org>
2018-05-04  3:12 ` [ruby-core:86873] [Ruby trunk Feature#14736] Thread selector for flexible cooperative fiber based concurrency samuel
2018-05-05  2:39 ` [ruby-core:86881] " samuel
2018-05-05  2:43 ` [ruby-core:86882] " samuel
2018-05-05  2:51 ` [ruby-core:86886] " samuel
2018-06-12  3:57 ` [ruby-core:87477] " samuel
2018-06-13  0:58   ` [ruby-core:87483] " Eric Wong
2018-07-04  8:08 ` samuel [this message]
2018-07-04  8:17 ` [ruby-core:87778] " samuel
2018-07-04 16:39 ` [ruby-core:87785] " funny.falcon
2018-07-05  4:12 ` [ruby-core:87798] " samuel
2018-07-05  7:25 ` [ruby-core:87804] " funny.falcon
2018-07-05  7:48 ` [ruby-core:87807] " samuel
2018-07-05  8:33 ` [ruby-core:87808] " funny.falcon
2018-07-05  8:36 ` [ruby-core:87809] " samuel
2018-07-08  2:02 ` [ruby-core:87863] " samuel
2019-05-01 15:11 ` [ruby-core:92515] " eregontp
2019-05-01 15:15 ` [ruby-core:92516] " eregontp
2019-05-01 22:41 ` [ruby-core:92522] " samuel
2019-05-01 23:03 ` [ruby-core:92523] " samuel

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=redmine.journal-72799.20180704080831.9ff1207970ee5d43@ruby-lang.org \
    --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).