Searchkick 内存泄漏

发布于 2025-01-11 08:14:57 字数 468 浏览 3 评论 0原文

对应用程序运行 rake searchkick:reindex CLASS=Product 会导致 Rake 进程泄漏内存;大约 15-20 分钟后,它就足以冻结具有 16GB RAM 的 Debian 系统。有 ~3800 个“产品”记录。

我设法在 Rake 任务中使用以下代码解决了这个问题:

connection = ActiveRecord::Base.connection
res = connection.execute('select max(id) from products')
id = res.getvalue(0,0)
1.upto(id) do |i|
  p = Product.find_by_id(i)
  next unless p

  p.reindex
end

这也更快一些。

任何人都可以建议一种方法来调查此内存泄漏吗?在考虑开票之前更详细地了解一下会很有用。

Running rake searchkick:reindex CLASS=Product for an application causes the Rake process to leak memory; after about 15-20 minutes it's bad enough to freeze a Debian system with 16GB of RAM. There are ~3800 "Product" records.

I managed to work around this problem with the following code in a Rake task:

connection = ActiveRecord::Base.connection
res = connection.execute('select max(id) from products')
id = res.getvalue(0,0)
1.upto(id) do |i|
  p = Product.find_by_id(i)
  next unless p

  p.reindex
end

This is also a little quicker.

Can anyone suggest a means to investigate this memory leak? It would be useful to do so in more detail before considering opening a ticket.

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

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

发布评论

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

评论(1

梦归所梦 2025-01-18 08:14:57

这会导致生成索引时出现问题: 文本字段未针对需要每个文档字段数据的操作进行优化

该问题可以通过在上面的代码中添加以下内容来解决:

Product.reindex(import: false)
# Rest of code goes here...

This causes a problem with generating indexes: Text fields are not optimised for operations that require per-document field data

That problem can be fixed by adding the following to the code above:

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