roc*_*egg 5 ruby garbage-collection memory-leaks
我正在看到一些奇怪的潜在红宝石2.2.3 gc相关问题,从单词列表生成前缀尝试.可疑代码在这里:
def insert(word)
return if word.nil? || word.empty?
node = self
counter = 0
l = word.length
#TODO _ why is this not being garbage collected?
word.bytes.each do |i|
counter += 1
node.children[i] ||= Node.new(i.chr, node, counter == l)
node = node.children[i]
node.terminal = true if counter == l
end
end
Run Code Online (Sandbox Code Playgroud)
它是从字符串列表中调用的 - 就这样
words.each_with_index do |word, i|
@root.insert(word)
Run Code Online (Sandbox Code Playgroud)
当我对此进行一些内存分析时,我看到ruby 2.2.3-railsexpress中的总mem用量为~68MB:
Measure Mode: memory
Thread ID: 70102347546980
Fiber ID: 70102348363420
Total: 68688.375000
Sort by: self_time
%self total self wait child calls name
20.03 13755.000 13755.000 0.000 0.000 293398 FastAutocomplete::Node#initialize
9.05 6218.875 6218.875 0.000 0.000 86036 String#bytes
6.26 66665.562 4298.438 0.000 62367.125 86040 *Array#each
1.50 1028.969 1028.969 0.000 0.000 230540 Hash#keys
0.98 677.219 676.438 0.000 0.781 1 Array#map
Run Code Online (Sandbox Code Playgroud)
当我使用2.1.7时,我只看到大约22MB的使用情况:
Measure Mode: memory
Thread ID: 70216772377340
Fiber ID: 70216782765400
Total: 22009.125000
Sort by: self_time
%self total self wait child calls name
62.49 13754.391 13754.391 0.000 0.000 293398 FastAutocomplete::Node#initialize
28.25 6218.641 6218.641 0.000 0.000 86036 String#bytes
4.67 1028.078 1028.078 0.000 0.000 230540 Hash#keys
3.07 676.797 676.203 0.000 0.594 1 Array#map
1.27 280.203 280.203 0.000 0.000 116093 Thread::Queue#enq
0.07 19.297 15.516 0.000 3.781 9 JSON::Ext::Generator::GeneratorMethods::Hash#to_json
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多东西,比如在整个创建过程中跟踪GC.stats,但是没有注意到任何特别有用的东西.我也尝试过使用string.each_char或string.split('').每个(即不同的迭代器).
关于为什么2.2.3使用3x内存的任何想法?这导致我们的一些服务器爆炸.
| 归档时间: |
|
| 查看次数: |
158 次 |
| 最近记录: |