about summary refs log tree commit homepage
path: root/lib/dtas/player.rb
diff options
authorEric Wong <normalperson@yhbt.net>2013-12-27 08:08:50 +0000
committerEric Wong <normalperson@yhbt.net>2013-12-27 08:08:50 +0000
commitdf634904b60f0aa17a99afd225c58a7605c9ee37 (patch)
tree7c47f8d870a8dc17345f29393f4158298b48e640 /lib/dtas/player.rb
parentdc89cfd111eff569bac3077b366c5ed8737d05a5 (diff)
Avoid an additional select syscall in the splice path by injecting
the target checks into the main loop.  We can do this because we
always process writers before readers.  This adds additional
userspace processing, but it avoids one potentially expensive (and
potentially task-switching) syscall in many cases; so it should be
worth it to avoid skipping with small buffer.

This should avoid buffer underuns with mixed-sized buffers when
using multiple sinks.

This could work for the read_write path, too, but I don't
use that enough and this change may still be buggy even
for splice users.
Diffstat (limited to 'lib/dtas/player.rb')
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index 56fbdac..04c03b0 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -300,6 +300,13 @@ class DTAS::Player # :nodoc:
+  def _optimize_write_prepare(targets)
+    targets.each do |dst|
+      dst.wait_writable_prepare
+      @srv.wait_ctl(dst, :wait_writable)
+    end
+  end
   # returns a wait_ctl arg for self
   def broadcast_iter(buf, targets)
     case rv = buf.broadcast(targets)
@@ -315,6 +322,7 @@ class DTAS::Player # :nodoc:
       # via DTAS::Sink#writable_iter
     else # :wait_readable or nil
+      _optimize_write_prepare(targets)