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:87483] Re: [Ruby trunk Feature#14736] Thread selector for flexible cooperative fiber based concurrency
Date: Wed, 13 Jun 2018 00:58:26 +0000	[thread overview]
Message-ID: <20180613005826.x3xu7ugngdgxqrui@dcvr> (raw)
In-Reply-To: <redmine.journal-72473.20180612035756.63ed6ac03fa55694@ruby-lang.org>

[-- Attachment #1: Type: text/plain, Size: 2368 bytes --]

samuel@oriontransfer.net wrote:
> I've been playing around with port scanners. Implemented in Go
> (goroutines), Python (asyncio) and Ruby (async).
>
> I wrote up the results here:
> https://github.com/socketry/async-await/tree/master/examples/port_scanner

Attached is the implementation for Threadlet/auto-fiber/wachamacallit
rebased against ruby trunk r63641:
   https://80x24.org/spew/20180613003524.9256-1-e@80x24.org/raw

On a busy Linux VM, Threadlet was close to your Go implementation
in speed (timing results were unstable, however) and Ruby async
was around 3x slower behind (even with timing instabilities).

I kept on getting errors with the Python3 version
("Event loop is closed") so I never let it finish

I needed to deal with EPIPE because the system I tested on had RDS (16385)
enabled in the kernel which was triggering EPIPE (I don't know Go or Python):

```
diff --git a/examples/port_scanner/port_scanner.go b/examples/port_scanner/port_scanner.go
index 45f2d1c..ad0f049 100755
--- a/examples/port_scanner/port_scanner.go
+++ b/examples/port_scanner/port_scanner.go
@@ -55,7 +55,7 @@ func checkPortOpen(ip string, port int, timeout time.Duration) {
 		} else if strings.Contains(err.Error(), "refused") {
 			// fmt.Println(port, "closed", err.Error())
 		} else {
-			panic(err)
+			fmt.Println(port, "err", err.Error())
 		}
 		return
 	}
diff --git a/examples/port_scanner/port_scanner.py b/examples/port_scanner/port_scanner.py
index 372f0b3..ca9d41a 100755
--- a/examples/port_scanner/port_scanner.py
+++ b/examples/port_scanner/port_scanner.py
@@ -22,6 +22,8 @@ class PortScanner:
                 # print("{} closed".format(port))
             except asyncio.TimeoutError:
                 print("{} timeout".format(port))
+            except SystemError:
+                print("{} error".format(port))
 
     def start(self, timeout=1.0):
         self.loop.run_until_complete(asyncio.gather(
diff --git a/examples/port_scanner/port_scanner.rb b/examples/port_scanner/port_scanner.rb
index 0e4160e..3ac0109 100755
--- a/examples/port_scanner/port_scanner.rb
+++ b/examples/port_scanner/port_scanner.rb
@@ -25,6 +25,8 @@ class PortScanner
     # puts "#{port} closed"
   rescue Async::TimeoutError
     puts "#{port} timeout"
+  rescue SystemCallError => e
+    puts "#{port} #{e.message}"
   end
 
   async def start(timeout = 1.0)
```

[-- Attachment #2: port_scanner_threadlet.rb --]
[-- Type: application/x-ruby, Size: 962 bytes --]

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2018-06-13  0:58 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   ` Eric Wong [this message]
2018-07-04  8:08 ` [ruby-core:87777] " samuel
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=20180613005826.x3xu7ugngdgxqrui@dcvr \
    --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).