From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] benchmark: add benchmarks for sleepy GC
Date: Wed, 2 May 2018 04:57:14 +0000 [thread overview]
Message-ID: <20180502045714.GA5427@whir> (raw)
In-Reply-To: <20180501080844.22751-1-e@80x24.org>
Most of these show a significant improvement in average
memory use and insignificant or no changes in CPU usage
with the /dev/urandom on my Linux systems.
cf. https://bugs.ruby-lang.org/issues/14723
---
benchmark/bm_vm3_gc_io_select.rb | 30 +++++++++++++++++++++++++
benchmark/bm_vm3_gc_io_wait.rb | 21 +++++++++++++++++
benchmark/bm_vm3_gc_join_timeout.rb | 11 +++++++++
benchmark/bm_vm3_gc_remote_free_spmc.rb | 15 +++++++++++++
benchmark/bm_vm3_gc_szqueue.rb | 14 ++++++++++++
5 files changed, 91 insertions(+)
create mode 100644 benchmark/bm_vm3_gc_io_select.rb
create mode 100644 benchmark/bm_vm3_gc_io_wait.rb
create mode 100644 benchmark/bm_vm3_gc_join_timeout.rb
create mode 100644 benchmark/bm_vm3_gc_remote_free_spmc.rb
create mode 100644 benchmark/bm_vm3_gc_szqueue.rb
diff --git a/benchmark/bm_vm3_gc_io_select.rb b/benchmark/bm_vm3_gc_io_select.rb
new file mode 100644
index 00000000000..a89c15da8bc
--- /dev/null
+++ b/benchmark/bm_vm3_gc_io_select.rb
@@ -0,0 +1,30 @@
+begin
+ urandom = File.open('/dev/urandom', 'rb')
+ require 'io/nonblock'
+rescue LoadError, SystemCallError => e
+ abort "#{e.message} (#{e.class})"
+end
+r, w = IO.pipe
+
+th = Thread.new do
+ # do something slow which won't contend for GVL:
+ IO.copy_stream(urandom, w, 100_000_000)
+ w.close
+end
+
+# we do NOT want to trigger rb_wait_for_single_fd in readpartial
+r.nonblock = false
+
+# We want to read faster than the writer so we can have idle time:
+readers = 9.times.map { r.dup }
+readers << r
+begin
+ ready = IO.select(readers)
+ ready[0].each do |r|
+ r.readpartial(16384)
+ end
+rescue EOFError
+ break
+end while true
+th.join
+readers.each(&:close)
diff --git a/benchmark/bm_vm3_gc_io_wait.rb b/benchmark/bm_vm3_gc_io_wait.rb
new file mode 100644
index 00000000000..bd795d1f536
--- /dev/null
+++ b/benchmark/bm_vm3_gc_io_wait.rb
@@ -0,0 +1,21 @@
+begin
+ require 'io/nonblock'
+ urandom = File.open('/dev/urandom', 'rb')
+rescue LoadError, SystemCallError => e
+ abort "#{e.message} (#{e.class})"
+end
+
+r, w = IO.pipe
+th = Thread.new do
+ # do something slow which won't contend for GVL:
+ IO.copy_stream(urandom, w, 100_000_000)
+ w.close
+end
+
+# ensure we hit rb_wait_for_single_fd in IO#read:
+r.nonblock = true
+
+# reader should be faster and than writer thread
+true while r.read(16384)
+r.close
+th.join
diff --git a/benchmark/bm_vm3_gc_join_timeout.rb b/benchmark/bm_vm3_gc_join_timeout.rb
new file mode 100644
index 00000000000..d24602afcd5
--- /dev/null
+++ b/benchmark/bm_vm3_gc_join_timeout.rb
@@ -0,0 +1,11 @@
+begin
+ urandom = File.open('/dev/urandom')
+rescue SystemCallError => e
+ abort "#{e.message} (#{e.class})"
+end
+
+# do something slow which won't contend for GVL:
+th = Thread.new { 10000.times { urandom.read(16384) } }
+
+# n.b. timeout currently to benefit from sleepy GC
+true until th.join(0.01)
diff --git a/benchmark/bm_vm3_gc_remote_free_spmc.rb b/benchmark/bm_vm3_gc_remote_free_spmc.rb
new file mode 100644
index 00000000000..2f537f4fe0b
--- /dev/null
+++ b/benchmark/bm_vm3_gc_remote_free_spmc.rb
@@ -0,0 +1,15 @@
+# test free(3) from String#clear in a different thread
+# than the one which malloc-ed it (via String#*)
+# spmc: single producer, multiple consumer
+require 'thread'
+q = SizedQueue.new(128)
+nr = 100_000
+nt = 4
+th = Thread.new do
+ (nt * nr).times { q.push(' ' * 16384) }
+end
+thrs = nt.times.map do
+ Thread.new { nr.times { q.pop.clear } }
+end
+thrs.each(&:join)
+th.join
diff --git a/benchmark/bm_vm3_gc_szqueue.rb b/benchmark/bm_vm3_gc_szqueue.rb
new file mode 100644
index 00000000000..4479f99a3b4
--- /dev/null
+++ b/benchmark/bm_vm3_gc_szqueue.rb
@@ -0,0 +1,14 @@
+begin
+ require 'thread'
+ urandom = File.open('/dev/urandom')
+rescue LoadError, SystemCallError => e
+ abort "#{e.message} (#{e.class})"
+end
+q = SizedQueue.new(64)
+nr = 100_000
+th = Thread.new do
+ # Something slow with minimum GVL impact:
+ nr.times { q.push(urandom.read(16384)) }
+end
+nr.times { q.pop }
+th.join
--
EW
prev parent reply other threads:[~2018-05-02 4:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-01 8:08 [WIP v2 0/4] sleepy GC Eric Wong
2018-05-01 8:08 ` [WIP v2 1/4] thread.c (timeout_prepare): common function Eric Wong
2018-05-01 8:08 ` [WIP v2 2/4] gc: rb_wait_for_single_fd performs GC if idle (Linux) Eric Wong
2018-05-01 8:08 ` [WIP v2 3/4] thread.c (do_select): perform GC if idle Eric Wong
2018-05-01 8:08 ` [WIP v2 4/4] thread.c: native_sleep callers may perform GC Eric Wong
2018-05-02 4:42 ` [PATCH 5/4] thread_sync.c (mutex_lock): add missing else Eric Wong
2018-05-02 4:52 ` [PATCH 6/4] gc.c: allow disabling sleepy GC Eric Wong
2018-05-02 4:57 ` Eric Wong [this message]
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180502045714.GA5427@whir \
--to=e@80x24.org \
--cc=spew@80x24.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).