[前][次][番号順一覧][スレッド一覧][生データ]

yarv-dev:973

From: sheepman <sheepman sheepman.sakura.ne.jp>
Date: Thu, 23 Feb 2006 22:15:13 +0900
Subject: [yarv-dev:973] open> SizedQueue is too slow

こんばんは、sheepman です。
僕の手元の環境だけかも知れませんが、以下のようなスクリプトを
走らせるとruby-1.9に比べて異常に遅いので調べてみました。

$ cat th01.rb
require 'thread'
n = 500
q = SizedQueue.new(1)

th = Thread.new do
  n.times{
    q.pop
  }
end

Thread.new do
  n.times{
    q.push(true)
  }
end

th.join

$ time ruby-2.0 -v th01.rb
ruby 2.0.0 (Base: Ruby 1.9.0 2006-02-14) [i686-linux]
YARVCore 0.4.0 Rev: 474 (2006-02-23) [opts: ]
ruby-2.0 -v th01.rb  0.01s user 0.00s system 0% cpu 10.075 total

$ time ruby-1.9 -v th01.rb
ruby 1.9.0 (2006-02-21) [i686-linux]
ruby-1.9 -v th01.rb  0.08s user 0.00s system 117% cpu 0.068 total

どうやら、yarv/lib/thread.rb が原因のようです。以下のように修正すると、大分速くなります。

$ diff -U 4 thread.rb\~ thread.rb
--- thread.rb~  2006-02-23 21:51:50.000000000 +0900
+++ thread.rb   2006-02-23 21:52:18.000000000 +0900
@@ -180,14 +180,14 @@
     while true
       @mutex.synchronize{
         if @que.empty?
           @waiting.push Thread.current
-          @mutex.unlock_and_stop
-          @mutex.lock
+          break
         else
           return @que.shift
         end
       }
+      Thread.pass
     end
   end

   #

$ time ruby-2.0 -I. th01.rb
ruby-2.0 -I. th01.rb  0.03s user 0.00s system 89% cpu 0.034 total

-- 
sheepman / TAMURA Takashi
sheepman sheepman.sakura.ne.jp http://sheepman.parfait.ne.jp/

-- 
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]

->     973 2006-02-23 22:15 [sheepman sheepman.sa] open> SizedQueue is too slow            
       974 2006-02-23 22:27 ┗[sheepman sheepman.sa]                                       
       975 2006-02-23 23:26  ┗[sheepman sheepman.sa]                                     
       983 2006-02-27 11:42   ┗[aamine loveruby.net ] fixed> Re: SizedQueue is too slow 
       984 2006-02-27 15:21    ┣[matz ruby-lang.org  ]                                 
       990 2006-02-27 22:07    ┗[sheepman sheepman.sa]                                 
       991 2006-02-27 22:09     ┣[ko1 atdot.net       ]                               
       993 2006-02-27 22:41     ┗[aamine loveruby.net ] Re: SizedQueue is too slow