From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-2.3 required=3.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A76441F8C2 for ; Mon, 22 Dec 2014 01:12:57 +0000 (UTC) Received: from localhost ([::1]:38720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2rYP-0001P7-1E for dtas-all@80x24.org; Sun, 21 Dec 2014 20:12:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2rYH-0001On-8s for dtas-all@nongnu.org; Sun, 21 Dec 2014 20:12:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2rYB-000353-4j for dtas-all@nongnu.org; Sun, 21 Dec 2014 20:12:49 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:57177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2rYA-00034l-V2 for dtas-all@nongnu.org; Sun, 21 Dec 2014 20:12:43 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 946851F8A1; Mon, 22 Dec 2014 01:12:42 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] reduce syscalls in recvmsg invocations Date: Mon, 22 Dec 2014 01:12:41 +0000 Message-Id: <1419210761-26539-1-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.1.2.571.ged78782.dirty X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 Cc: Eric Wong X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Favor IO.select over IO#wait since the latter makes another ioctl syscall (which we'll make anyways for IO#nread). Having BasicSocket#recvmsg and recvmsg_nonblock detect the buffer size requires extra syscalls, so pass explict maxmesglen, flags, and maxcontrollen args to elide auto-detection since we already have the buffered amount from IO#nread. This cuts more syscalls from the "dtas-tl cat" invocation with larger tracklists. --- lib/dtas/unix_accepted.rb | 2 +- lib/dtas/unix_client.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/dtas/unix_accepted.rb b/lib/dtas/unix_accepted.rb index 2c82d2a..3008afc 100644 --- a/lib/dtas/unix_accepted.rb +++ b/lib/dtas/unix_accepted.rb @@ -56,7 +56,7 @@ class DTAS::UNIXAccepted # :nodoc: begin begin - msg, _, _ = io.recvmsg_nonblock(nread) + msg, _, _ = io.recvmsg_nonblock(nread, 0, 0) rescue Errno::EAGAIN return :wait_readable rescue EOFError, SystemCallError diff --git a/lib/dtas/unix_client.rb b/lib/dtas/unix_client.rb index 40dedcc..7382ea6 100644 --- a/lib/dtas/unix_client.rb +++ b/lib/dtas/unix_client.rb @@ -38,9 +38,9 @@ class DTAS::UNIXClient # :nodoc: end def res_wait(timeout = nil) - @to_io.wait(timeout) + IO.select([@to_io], nil, nil, timeout) nr = @to_io.nread nr > 0 or raise EOFError, "unexpected EOF from server" - @to_io.recvmsg[0] + @to_io.recvmsg(nr, 0, 0)[0] end end -- EW