From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6652B20953 for ; Thu, 16 Mar 2017 03:14:14 +0000 (UTC) From: Eric Wong To: raindrops-public@bogomips.org Subject: [PATCH 1/3] aggregate/pmq: avoid false sharing of lock buffers Date: Thu, 16 Mar 2017 03:14:10 +0000 Message-Id: <20170316031412.16713-2-e@80x24.org> In-Reply-To: <20170316031412.16713-1-e@80x24.org> References: <20170316031412.16713-1-e@80x24.org> List-Id: And rely on frozen string optimizations in Ruby while we're at it. --- lib/raindrops/aggregate/pmq.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb index a2dd45e..f543302 100644 --- a/lib/raindrops/aggregate/pmq.rb +++ b/lib/raindrops/aggregate/pmq.rb @@ -39,9 +39,9 @@ class Raindrops::Aggregate::PMQ # :stopdoc: # These constants are for Linux. This is designed for aggregating # TCP_INFO. - RDLOCK = [ Fcntl::F_RDLCK ].pack("s @256") - WRLOCK = [ Fcntl::F_WRLCK ].pack("s @256") - UNLOCK = [ Fcntl::F_UNLCK ].pack("s @256") + RDLOCK = [ Fcntl::F_RDLCK ].pack("s @256".freeze).freeze + WRLOCK = [ Fcntl::F_WRLCK ].pack("s @256".freeze).freeze + UNLOCK = [ Fcntl::F_UNLCK ].pack("s @256".freeze).freeze # :startdoc: # returns the number of dropped messages sent to a POSIX message @@ -185,10 +185,12 @@ def lock! io, type # :nodoc: def synchronize io, type # :nodoc: @mutex.synchronize do begin + type = type.dup lock! io, type yield io ensure - lock! io, UNLOCK + lock! io, type.replace(UNLOCK) + type.clear end end end -- EW