Ruby 中调试堆栈级别太深

发布于 2024-09-13 22:56:37 字数 992 浏览 6 评论 0原文

我的 ruby​​ 程序遇到了堆栈级别太深(SystemStackError)错误,以 datamapper 结束:

from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/collection.rb:510:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:616:in `map'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:616:in `expected'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:461:in `matches?'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/operation.rb:498:in `matches?'
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.15/lib/extlib/inflection.rb:103:in `any?'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/operation.rb:159:in `each'
from /usr/local/lib/ruby/1.8/set.rb:195:in `each'
 ... 5188 levels...

有没有办法调试它?喜欢探索隐藏的 5188 个关卡吗? Ruby-debug 无法帮助我,内置 ruby​​ 分析器因“[FATAL] 无法分配内存”而终止

I have ruby program that is running into a stack level too deep (SystemStackError) error, ending on datamapper:

from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/collection.rb:510:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:616:in `map'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:616:in `expected'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:461:in `matches?'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/operation.rb:498:in `matches?'
from /usr/local/lib/ruby/gems/1.8/gems/extlib-0.9.15/lib/extlib/inflection.rb:103:in `any?'
from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/operation.rb:159:in `each'
from /usr/local/lib/ruby/1.8/set.rb:195:in `each'
 ... 5188 levels...

Is there a way to debug it? Like looking into the hidden 5188 levels? Ruby-debug was unable to help me, and the builtin ruby profiler dies with "[FATAL] failed to allocate memory"

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

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

发布评论

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

评论(1

和影子一齐双人舞 2024-09-20 22:56:37

除了没有找到可以处理堆栈溢出的 ruby​​ profiler 之外,问题还在于滥用 Datamapper 的惰性

应用程序正在获取文本属性 (这是惰性的)在一个查询(也是惰性的)内,在另一个查询(这也是惰性的) )。尽管所有这些惰性通常会将 N+1 查询变成 O(k) 查询(实际上通常意味着 4 个查询),但这最终会产生堆栈溢出。

在 rake、rspec 和 netbeans 环境之外以简单的 ruby​​ 脚本执行溢出测试,让我更清楚地看到了罪魁祸首。

仍然希望红宝石分析器能够帮助我。

The problem, besides finding no ruby profiler that can deal with stack overflows, was abusing Datamapper lazyness

The application was getting a text property (which is lazy) inside a query (which is also lazy), inside another query (which is lazy as well). Even though all this lazyness usually turn a N+1 query into a O(k) query (which actually usually means 4 queries), this turned out to generate a stack overflow.

Executing the overflowing test as a simple ruby script, outside rake, rspec and netbeans environment, allowed me to see the culprit more clearly.

Still wished ruby profilers could have helped me with it.

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