在 Jruby 中运行 nokogiri 与仅在 ruby​​ 中运行 nokogiri

发布于 2024-08-12 23:13:03 字数 545 浏览 5 评论 0原文

我发现 CPU 和内存消耗使用情况存在惊人的差异。当我在 Jruby 中运行以下 nokogiri 脚本时,似乎没有发生垃圾收集

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

它最终显示“内存不足”

,CPU 消耗超过 10,并且内存消耗百分比随着时间的推移而上升(从 2 开始到 20),直到 在 Ruby 中运行,CPU 消耗永远不会超过 2,内存消耗 % 恒定为 0.2!

为什么差异这么大,为什么内存消耗稳步增加直至崩溃。

在 Ruby 中运行它,CPU 使用率低得多,并且内存消耗持续非常低

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-08-19 23:13:03

我读你的剧本正确吗?您是否正在访问糟糕的 craigslist 网站,执行 10K HTTP get 请求? :)

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

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

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.

↘人皮目录ツ 2024-08-19 23:13:03

ruby对内存的控制比Jruby更好。
在我看来,只有当您需要使用 Java 库或者您有同一程序的多个实例同时在同一台机器上运行时,您才应该使用 Jruby,在这种情况下,JVM 缓存将发挥惊人的作用。

ruby has better control of the memory than Jruby.
In my opinion, you should only use Jruby if you need to use Java libraries or if you have several instances of the same program that will be running in the same machine at the same time, in that case JVM caching will do amazing things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文