# PostAlerter job נתקע/OOMs כפי שקורה לאחרונה

**URL:** https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183
**Category:** Bug
**Created:** [30 ביוני,‏ 2023,‏ 5:38pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183 "2023-06-30T17:38:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [30 ביוני,‏ 2023,‏ 5:38pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/1 "2023-06-30T17:38:39Z")

</div>

Ever since [FEATURE: new watched\_precedence\_over\_muted setting (#22252) · discourse/discourse@9cf981f · GitHub](https://github.com/discourse/discourse/commit/9cf981f1f15d3a22929003f0ca59ac2fdd28d7d4) (presumably!) we’re having Sidekiq queues fill up/OOM with stuck PostAlert jobs:

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/d/2/2d22a45a128bd08af42375f4de43e8a42c11a7ea.jpeg)

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/d/5/ad50cabb876191a9f46757ec52450aaca4ba695d.png)

Given this commit has already had a similar regression ([FIX: error when CategoryList tried to find relevant topics by KrisKotlarek · Pull Request #22339 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/22339)) it’s fairly suspect - we’ll try downgrading to a commit before the aforementioned one now though and will report back with the results.

---

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [30 ביוני,‏ 2023,‏ 11:13pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/2 "2023-06-30T23:13:37Z")

</div>

> [@blattersturm](#):
>
> we’ll try downgrading to a commit before the aforementioned one now though and will report back with the results.

Moving downward to `4f7f9ef87cbcd574144f657dd43b7e705d98ff8e` indeed solved the stuck PostAlert sidekiq workers and the OOM concerns: the few PostAlert jobs that do get queued now complete within a matter of seconds, not minutes.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2 ביולי,‏ 2023,‏ 4:59pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/3 "2023-07-02T16:59:50Z")

</div>

Ping @kris.kotlarek

---

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [3 ביולי,‏ 2023,‏ 10:48pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/5 "2023-07-03T22:48:36Z")

</div>

I just saw [FIX: improve performance of post alerter job (#22378) · discourse/discourse@7a204e7 · GitHub](https://github.com/discourse/discourse/commit/7a204e754c17d1e8229bb782c17f450813c201ec) be pushed - will try this out later if this is meant to be a fix for this issue.

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [3 ביולי,‏ 2023,‏ 11:02pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/6 "2023-07-03T23:02:04Z")

</div>

Hey, yes, this hopefully will solve this issue. I tested this solution on 3 forums, and a new query was always much faster and didn’t clog servers.  
Thank you for reporting this issue, and please let me know if you still experience problems.

---

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [5 ביולי,‏ 2023,‏ 8:08pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/7 "2023-07-05T20:08:03Z")

</div>

> [@kris.kotlarek](#):
>
> this hopefully will solve this issue

Sadly, even with these changes, we’re still seeing PostAlert jobs take way longer than before and hang the Sidekiq workers entirely while processing. ☹

(we have 10M+ user rows and some categories muted by default, so there’s a _lot_ of mutes set up!)

Reverting the three commits that recently touched this job and restarting the container, meanwhile, has the jobs complete fine.

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [6 ביולי,‏ 2023,‏ 4:57am UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/8 "2023-07-06T04:57:08Z")

</div>

Thank you, I will have another look

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [13 ביולי,‏ 2023,‏ 1:38am UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/9 "2023-07-13T01:38:32Z")

</div>

I just merged another try to improve performance of this job:

[https://github.com/discourse/discourse/pull/22487](https://github.com/discourse/discourse/pull/22487)

I tested in on few instances and it was fine, but they were smaller than yours.

If it is still failing with this commit, could you provide me `EXPLAIN ANALYSE` report? Script to generate it:

```ruby
topic = Topic.last
user_option_sql_fragment =
  if SiteSetting.watched_precedence_over_muted
    <<~SQL
    INTERSECT
    SELECT user_id FROM user_options WHERE user_options.watched_precedence_over_muted IS false
    SQL
  else
    <<~SQL
    EXCEPT
    SELECT user_id FROM user_options WHERE user_options.watched_precedence_over_muted IS true
    SQL
  end
user_ids_sql = <<~SQL
  (
    SELECT user_id FROM category_users WHERE category_id = #{topic.category_id.to_i} AND notification_level = #{CategoryUser.notification_levels[:muted]}
    UNION
    SELECT user_id FROM tag_users tu JOIN topic_tags tt ON tt.tag_id = tu.tag_id AND tt.topic_id = #{topic.id} WHERE tu.notification_level = #{TagUser.notification_levels[:muted]}
    EXCEPT
    SELECT user_id FROM topic_users tus WHERE tus.topic_id = #{topic.id} AND tus.notification_level = #{TopicUser.notification_levels[:watching]}
  )
  #{user_option_sql_fragment}
SQL
sql = User.where("id IN (#{user_ids_sql})").to_sql

sql_with_index = <<SQL
EXPLAIN ANALYZE #{sql};
SQL
result = ActiveRecord::Base.connection.execute("#{sql_with_index}")
puts sql_with_index
result.each do |r|
  puts r.values
end

```

It would help me to find missing index or which part of this query is so slow.

---

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [13 ביולי,‏ 2023,‏ 7:17pm UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/10 "2023-07-13T19:17:37Z")

</div>

This change seems to have returned PostAlert jobs to their normal duration and _not_ hanging the Sidekiq instances. Yay!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [17 ביולי,‏ 2023,‏ 11:00am UTC](https://meta.discourse.org/t/postalerter-job-hangs-ooms-as-of-late/270183/11 "2023-07-17T11:00:37Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
