0

I found startling difference in CPU and memory consumption usage. It seems garbage collection is not happening when i run the following nokogiri script

require 'rubygems'
require 'nokogiri'
require 'open-uri'

def getHeader()
 doz = Nokogiri::HTML(open('http://losangeles.craigslist.org/wst/reb/1484772751.html'))
 puts doz.xpath("html[1]\/body[1]\/h2[1]")
end


(1..10000).each do |a|

getHeader()

end

when run in Jruby, CPU consumption is over 10, and memory consumption % rises with time(starts from 2 to 20), until it eventually says "not enough memory"

when run in Ruby, CPU consumption never exceeds 2, and memory consumption % constant at 0.2 !

Why such big differences, why is memory consumption steadily increasing until it crashes.

running it in Ruby, much much lower cpu usage, and constant very low memory consumption

4

2 回答 2

3

我读你的剧本对吗?您是否在访问糟糕的 craigslist 站点,执行 10K HTTP 获取请求?:)

无论如何,你的系统是什么,Nokogiri gem 的哪个版本,JRuby 的哪个版本?对脚本进行少量修改(仅打开一次 HTTP 请求,然后回退相同的数据),MRI 和 JRuby 的行为大致相同,JRuby 甚至快了 20 秒中的 2 秒。没有记忆问题。

于 2009-11-28T11:21:02.233 回答
0

ruby 对内存的控制比 Jruby 好。在我看来,如果你需要使用 Java 库,或者如果你有多个将同时在同一台机器上运行的同一程序的实例,那么你应该只使用 Jruby,在这种情况下,JVM 缓存会做出惊人的事情。

于 2012-06-05T22:03:02.767 回答