【问题标题】:Rails: Worker failing and increasing memory usageRails:工人失败并增加内存使用量
【发布时间】:2017-04-25 19:15:16
【问题描述】:

在我的 Rails 应用程序中使用 SidekiqAlgoliasearch 时遇到了一个奇怪的问题。

每当我启动 sidekiq 时,它都会自动执行我使用 Algoliasearch 配置的所有操作:

# A post model

include AlgoliaSearch
algoliasearch if: :published?, enqueue: :trigger_sidekiq_worker do
    attributes :title, :subtitle, :content, :cached_votes_score, :cached_votes_total

    # the `searchableAttributes` (formerly known as attributesToIndex) setting defines the attributes
    # you want to search in: here `title`, `subtitle` & `description`.
    # You need to list them by order of importance. `description` is tagged as
    # `unordered` to avoid taking the position of a match into account in that attribute.
    searchableAttributes ['title', 'subtitle', 'unordered(content)']

    # the `customRanking` setting defines the ranking criteria use to compare two matching
    # records in case their text-relevance is equal. It should reflect your record popularity.
    customRanking ['desc(cached_votes_score)', 'desc(cached_votes_total)']
end

private

def self.trigger_sidekiq_worker(record, remove)
    ::Algolia::Blog::PostsWorker.perform_async(record.id, remove)
end

日志:

$ bundle exec sidekiq


         m,
         `$b
    .ss,  $$:         .,d$
    `$$P,d$P'    .,md$P"'
     ,$$$$$bmmd$$$P^'
   .d$$$$$$$$$$P'
   $$^' `"^$$$'       ____  _     _      _    _
   $:     ,$$:       / ___|(_) __| | ___| | _(_) __ _
   `b     :$$        \___ \| |/ _` |/ _ \ |/ / |/ _` |
          $$:         ___) | | (_| |  __/   <| | (_| |
          $$         |____/|_|\__,_|\___|_|\_\_|\__, |
        .d$$                                       |_|

Signal TTIN not supported
Signal TSTP not supported
Signal USR1 not supported
Signal USR2 not supported
2017-04-25T18:50:30.134Z 5596 TID-c0loo INFO: Running in ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
2017-04-25T18:50:30.134Z 5596 TID-c0loo INFO: See LICENSE and the LGPL-3.0 for licensing details.
2017-04-25T18:50:30.135Z 5596 TID-c0loo INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2017-04-25T18:50:30.136Z 5596 TID-c0loo INFO: Booting Sidekiq 5.0.0 with redis options {:url=>nil}
2017-04-25T18:50:30.138Z 5596 TID-c0loo INFO: Starting processing, hit Ctrl-C to stop
2017-04-25T18:50:30.207Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3 INFO: start
2017-04-25T18:50:30.539Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3 INFO: fail: 0.333 sec
2017-04-25T18:50:30.540Z 5596 TID-1nla70 WARN: {"context":"Job raised exception","job":{"class":"Algolia::Blog::PostsWorker","args":[1,false],"retry":true,"queue":"default","jid":"262b2f8613a197637d05caf3","created_at":1493146072.768356,"enqueued_at":1493146072.768356,"error_message":"Couldn't find Blog::Post with 'id'=1","error_class":"ActiveRecord::RecordNotFound","failed_at":1493146230.538659,"retry_count":0},"jobstr":"{\"class\":\"Algolia::Blog::PostsWorker\",\"args\":[1,false],\"retry\":true,\"queue\":\"default\",\"jid\":\"262b2f8613a197637d05caf3\",\"created_at\":1493146072.768356,\"enqueued_at\":1493146072.768356}"}
2017-04-25T18:50:30.541Z 5596 TID-1nla70 WARN: ActiveRecord::RecordNotFound: Couldn't find Blog::Post with 'id'=1

我不知道这种行为是否是有意的,因为 algolia 似乎只是试图索引 id 为 1 的记录。据我了解,它应该只在创建、删除或更新记录后才索引。

工人失败后重新开始,所以我积累了很多内存。在某些情况下,即使我的所有类和命名空间都已正确命名,我也会收到 LoadError

我不知道问题出在 Algolia 还是 Sidekiq。

【问题讨论】:

    标签: ruby-on-rails backgroundworker sidekiq algolia ruby-on-rails-5.1


    【解决方案1】:

    我的猜测是,它的队列中有一个作业来索引一个不再存在的对象。

    队列应该正确处理它,我不知道为什么它没有。

    您可以尝试清除 Sidekiq 队列吗? 要清除所有队列,请运行:

    Sidekiq::Queue.all.each &:clear
    

    在控制台中,然后重试。

    【讨论】:

    • 我注意到,每当我启动 Sidekiq 时,algoliasearch-rails gem(我将它与 Sidekiq 一起使用)都会尝试索引 ID 为 1 的记录。我认为这是导致问题的原因 - 我在 GitHub here 上打开了一个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多