From: Daniel Martin Date: 2006-08-27T15:09:22+09:00 Subject: Re: [ANN] Mongrel 0.3.13.4 Pre-Release -- Ruby's LEAK Fixed (Death To Mutex!) ara.t.howard@noaa.gov writes: > in any case a careful script which allocated memory in a thread, > waits for all threads to finish allocation, checks memory, and then > kills all threads before checking again shows some suprising results > which you should read carefully: There's a problem with how this script measures its memory usage - it measures %MEM, which is proportional to RSS. However, RSS is just how much of the program's memory is *resident*; i.e. not swapped out. To look at how much total memory is used, the variable you want is VSZ, which isn't available in a "ps v" but is in a "ps u". I modified your script to look at the %MEM, VSZ, and RSS numbers from "ps u" and also to run GC.start a variable number of times. Here's what I found, for running GC.start 4 times for mutex and sync, on my system. VSZ is the middle of the three numbers; I really should prune away the other two measures, as they are just indicative of how actively my machine feels like swapping at that moment: using: Mutex n: 400 gctimes: 4 iter: 0 with 400 threads holding memory : 83.9 432136 262688 with 0 threads holding memory : 4.0 23792 12760 iter: 1 with 400 threads holding memory : 86.6 435044 271356 with 0 threads holding memory : 4.3 29808 13584 iter: 2 with 400 threads holding memory : 82.6 435060 258664 with 0 threads holding memory : 4.3 35872 13564 iter: 3 with 400 threads holding memory : 92.1 435240 288316 with 0 threads holding memory : 4.8 39052 15300 iter: 4 with 400 threads holding memory : 91.9 435012 287916 with 0 threads holding memory : 4.4 43252 13944 iter: 5 with 400 threads holding memory : 92.2 435060 288920 with 0 threads holding memory : 12.2 48440 38276 iter: 6 with 400 threads holding memory : 90.0 435000 282032 with 0 threads holding memory : 8.3 53516 26236 iter: 7 with 400 threads holding memory : 90.0 435012 281944 with 0 threads holding memory : 10.6 55500 33332 iter: 8 with 400 threads holding memory : 91.9 435108 287776 with 0 threads holding memory : 4.9 59632 15496 iter: 9 with 400 threads holding memory : 88.4 435024 276876 with 0 threads holding memory : 11.4 64828 35760 using: Sync n: 400 gctimes: 4 iter: 0 with 400 threads holding memory : 87.1 432216 272720 with 0 threads holding memory : 4.4 23980 13864 iter: 1 with 400 threads holding memory : 85.4 435276 267484 with 0 threads holding memory : 4.4 31196 13880 iter: 2 with 400 threads holding memory : 85.0 435400 266116 with 0 threads holding memory : 4.2 37564 13280 iter: 3 with 400 threads holding memory : 89.8 435408 281320 with 0 threads holding memory : 4.1 43568 12876 iter: 4 with 400 threads holding memory : 92.1 435400 288608 with 0 threads holding memory : 4.4 47796 13988 iter: 5 with 400 threads holding memory : 91.5 435348 286668 with 0 threads holding memory : 8.6 51804 26984 iter: 6 with 400 threads holding memory : 91.3 435312 285848 with 0 threads holding memory : 4.4 56664 13828 iter: 7 with 400 threads holding memory : 92.0 435360 288156 with 0 threads holding memory : 9.1 61024 28788 iter: 8 with 400 threads holding memory : 91.9 435316 287780 with 0 threads holding memory : 11.2 63508 35184 iter: 9 with 400 threads holding memory : 91.2 435364 285672 with 0 threads holding memory : 11.0 67260 34468 What this tells me is that there is a memory leak, but it appears that both sync and mutex suffer from it. It also appears to be, at this point, relatively minor. I haven't looked at modifying Zed Shaw's script to have it record its own numbers, so I can't verify what he saw. It may make a big difference that Zed's script allocates memory by building up a big array, whereas yours does so by making a big string - I could easily believe that there's something subtle hidden in the interaction of Array and Mutex, for example. -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.map{|i|i}[1] ) puts "s=%q(#{s})",s.map{|i|i}[1]