# עומס הדיון שלנו בגלל פלאגין מותאם אישית. אנא עזרו לי

**URL:** https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696
**Category:** Self-hosting
**Tags:** hosting
**Created:** [20 באוגוסט,‏ 2022,‏ 9:49am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696 "2022-08-20T09:49:57Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 7:36am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/21 "2022-08-22T07:36:20Z")

</div>

Oh Robert,  
We migrate to a new vps with 4 core(Ryzen 9 5950x),  
Cpu usage is still almost 100%. I really don’t know what is wrong.

 ![屏幕快照 2022-08-22 16.32.34](https://global.discourse-cdn.com/meta/original/4X/9/3/2/932fd72d82ca7e0fbecae9888ce2c1244b837408.png)  
 ![屏幕快照 2022-08-22 16.32.48](https://global.discourse-cdn.com/meta/original/4X/6/0/9/609d30b786be0a6079cb93c6f6e085007c024ba7.png)  
 ![屏幕快照 2022-08-22 16.33.03](https://global.discourse-cdn.com/meta/original/4X/a/6/a/a6a033509c50a18b63ffff380e1d5532d893c1b4.png)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 7:48am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/22 "2022-08-22T07:48:06Z")

</div>

I thought you were going to move to an 8 core Scaleway server?

What is the claimed bandwidth of this server? I wonder if low bandwidth could cause slow connections/disconnections to become a bottleneck?

Scaleway have VPS with bandwidths of hundreds of megabits per second, not 30.

30 seems extremely low to me.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 7:54am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/23 "2022-08-22T07:54:25Z")

</div>

This is the spec.

```plaintext
4096MB DDR3 ECC RAM
4 CPU vCores (3.4+ GHz E3-1231 v3/1241 v3/1240 v5)
200GB Raid 10 HDD Storage
5TB bandwidth @ 1Gb/s (speed limited to 5Mb/s after allocation used)
1 IPv4, /64 IPv6
20Gb/s TCP DDoS Protection, 200Gb/s upgrade available
Seattle, Washington, US
Virtualizor Control Panel
Unmanaged

```

Because of time delay, we finally chose this cloud service provider. They did the optimization of the network for visitors from our country.

By the way, output of htop is

 ![屏幕快照 2022-08-22 16.46.43](https://global.discourse-cdn.com/meta/original/4X/6/e/c/6ecef6bc2ef92c758d657a00f2049a49b55bc893.png)  
100% CPU usage is abnormal. 😨  
Everything is fine except load and cpu usage.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:02am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/24 "2022-08-22T08:02:00Z")

</div>

Anything strange in access logs?

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:06am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/25 "2022-08-22T08:06:59Z")

</div>

Oh now it seems like it is calming down now.

 ![屏幕快照 2022-08-22 16.59.42](https://global.discourse-cdn.com/meta/original/4X/0/7/d/07d71f49b1f1065b5e22cc7060e08cab794c198a.png)  
We guess restoring from a backup causes a spike in cpu usage.  
Anyway, thank you very much Robert!

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:10am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/26 "2022-08-22T08:10:53Z")

</div>

Oh yes that would do it!

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:11am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/27 "2022-08-22T08:11:58Z")

</div>

> [@Alienazk](#):
>
> `200GB Raid 10 HDD Storage`

Hum, you should aim for ssd

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:13am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/28 "2022-08-22T08:13:13Z")

</div>

Good catch Benjamin!

Scaleway and others have NVMe SSDs. Much better!

CPU could be waiting on disk.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:36am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/29 "2022-08-22T08:36:24Z")

</div>

oh sorry I just pasted a wrong spec.  
The spec is

```plaintext
4096MB DDR4 ECC RAM
4 CPU vCores (3.4GHz AMD Ryzen 5950X)
100GB Raid NVMe SSD Storage
5TB bandwidth @ 10Gb/s (speed limited to 5Mb/s after allocation used)
1 IPv4, /64 IPv6
20Gb/s TCP DDoS Protection, 200Gb/s upgrade available
Seattle, Washington, US
Virtualizor Control Panel
Unmanaged

```

It is NVMe. 😳

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:44am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/30 "2022-08-22T08:44:07Z")

</div>

I think it is possible the plugins we installed have increased the load.  
The plugin made such a change to the user model that when we go to discovery route, we always calculate the points of user model in topic model for many times

```plaintext
add_to_class(:user, :total_earned_points) do
    self.user_points.sum(:reward_points)
  end

  add_to_class(:user, :available_points) do
    self.total_earned_points - self.user_rewards.sum(:points)
  end

  add_to_class(:user, :rewards) do
    DiscourseRewards::Reward.where(created_by_id: self.id)
  end

  add_to_serializer(:basic_user, :total_earned_points) do
    user&.total_earned_points
  end

  add_to_serializer(:basic_user, :available_points) do
    user&.available_points
  end

  add_to_serializer(:current_user, :total_earned_points) do
    scope.user.total_earned_points
  end

  add_to_serializer(:current_user, :available_points) do
    scope.user.available_points
  end

  add_to_serializer(:current_user, :user_rewards) do
    scope.user.user_rewards
  end

  add_to_serializer(:current_user, :rewards) do
    scope.user.rewards
  end

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:45am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/31 "2022-08-22T08:45:42Z")

</div>

I thought you’d said you’d removed all plugins and it was behaving the same?

> [@Alienazk](#):
>
> `DiscourseRewards::Reward.where(created_by_id: self.id)`

Does this have an index?

> [@Alienazk](#):
>
> `self.total_earned_points - self.user_rewards.sum(:points)`

How many rows is user\_rewards table? Interesting it is not distinguishing by user … (but I assume it must be somehow beneath this level).

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:54am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/32 "2022-08-22T08:54:53Z")

</div>

Oh I am afraid it doesn’t set an index.  
The model is shown below.

```plaintext
module DiscourseRewards
  class Reward < ActiveRecord::Base
    self.table_name = 'discourse_rewards_rewards'

    has_many :user_rewards
    belongs_to :created_by, class_name: 'User'

    default_scope { where(deleted_at: nil) }
  end
end

```

```plaintext
module DiscourseRewards
  class UserPoint < ActiveRecord::Base
    self.table_name = 'discourse_rewards_user_points'

    belongs_to :user
    belongs_to :user_badge
    belongs_to :user_points_category

    def self.user_total_points(user)
      UserPoint.where(user_id: user.id).sum(:reward_points)
    end
  end
end

```

```plaintext
module DiscourseRewards
  class UserReward < ActiveRecord::Base
    self.table_name = 'discourse_rewards_user_rewards'

    belongs_to :user
    belongs_to :reward

    enum status: [:applied, :granted]
  end
end

```

I disable all plugin on [safe mode](https://meta.discourse.org/t/53504?silent=true). However you know, the database didn’t change. 🥲

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:56am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/33 "2022-08-22T08:56:15Z")

</div>

Something to take up with the author I suspect.

Looks like it might not be scaling for your high number of users?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 8:57am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/34 "2022-08-22T08:57:40Z")

</div>

> [@Alienazk](#):
>
> I disable all plugin on [safe mode](https://meta.discourse.org/t/how-to-use-discourse-safe-mode/53504). However you know, the database didn’t change. 🥲

You may need to rebuild without the plugin. It would be a good comparison and maybe confirm if the issues are caused by the plugin or not.

The presence of tables won’t matter if the queries aren’t running.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:04am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/35 "2022-08-22T09:04:32Z")

</div>

> [@merefield](#):
>
> How many rows is user\_rewards table? Interesting it is not distinguishing by user …

discourse\_rewards\_user\_points | 233525 | 27 MB | 5152 kB | 32 MB  
discourse\_rewards\_user\_rewards | 61 | 16 kB | 16 kB | 32 kB  
discourse\_rewards\_user\_points\_categories | 9 | 16 kB | 16 kB | 32 kB  
discourse\_rewards\_rewards | 4 | 16 kB | 16 kB | 32 kB

discourse\_rewards\_user\_points table is huge.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:05am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/36 "2022-08-22T09:05:25Z")

</div>

Completely remove it (from build, no need to destroy the tables), see what happens.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:06am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/37 "2022-08-22T09:06:01Z")

</div>

Thank you, I 'll try it right now.

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:17am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/38 "2022-08-22T09:17:45Z")

</div>

Oh Robert, I rebuild without the plugin, response time for pages of discovery route is reduced to less than 200ms from 2-3s before. 😨

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:18am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/39 "2022-08-22T09:18:46Z")

</div>

Well there you have it. I would discuss optimisation with the author, or if you have the skills, PR?

---

<div class="post-metadata">

### Author: ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)
#### Post date: [22 באוגוסט,‏ 2022,‏ 9:22am UTC](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696/40 "2022-08-22T09:22:11Z")

</div>

I am asking for our friend who is familiar with database for help.  
But he is working on JAVA. I think it will takes some time.

[Previous page](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696.md?page=1)

[Next page](https://meta.discourse.org/t/our-discourse-overload-because-of-a-custom-plugin-please-help-me/236696.md?page=3)
