在Jruby vs.ruby中运行nokogiri [英] running nokogiri in Jruby vs. just ruby

查看:92
本文介绍了在Jruby vs.ruby中运行nokogiri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现CPU和内存消耗的使用率惊人地不同.当我运行以下nokogiri脚本时,似乎没有发生垃圾收集

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

在Jruby中运行时,CPU消耗超过10,并且内存消耗百分比随时间增加(从2到20),直到最终显示内存不足"

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"

在Ruby中运行时,CPU消耗永远不会超过2,并且内存消耗%恒定为 0.2!

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.

在Ruby中运行它,CPU使用率大大降低,并且内存消耗非常低

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

推荐答案

我在看你的脚本吗?您是否在访问可怜的craigslist网站,执行10K HTTP get请求? :)

Am I reading your script right? Are you hitting poor craigslist site, performing 10K HTTP get requests? :)

无论如何,您的系统是什么,Nokogiri gem的哪个版本,JRuby的哪个版本?对该脚本进行少量修改(仅打开一次HTTP请求,然后倒回相同的数据),MRI和JRuby的行为几乎相同,JRuby的速度甚至比20秒快2秒.没有内存问题.

At any rate, what's your system, which version of Nokogiri gem, which JRuby version? With small modification to the script (opening the HTTP request only once and then rewinding the same data), both MRI and JRuby behave about the same, JRuby even 2 secs out of 20 total faster. No memory problems.

这篇关于在Jruby vs.ruby中运行nokogiri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆