# Discourse安装越来越慢

**URL:** <https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501>\
**Category:** Self-hosting\
**Tags:** server-resources\
**Created:** [2023年四月4日 07:59 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501 "2023-04-04T07:59:49Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 22:05 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/21 "2023-04-04T22:05:32Z")

</div>

```plaintext
root@tymin:/var/discourse# swapon
NAME TYPE SIZE USED PRIO
/dev/dm-0 partition 1.9G 1G -1
root@tymin:/var/discourse# df -T
文件系统 类型 1K-blocks Used Available Use% Mounted on
udev devtmpfs 2008928 0 2008928 0% /dev
tmpfs tmpfs 404176 41336 362840 11% /run
/dev/mapper/VolGroup-root ext4 59629100 50018424 6991008 88% /
tmpfs tmpfs 2020876 0 2020876 0% /dev/shm
tmpfs tmpfs 5120 0 5120 0% /run/lock
tmpfs tmpfs 2020876 0 2020876 0% /sys/fs/cgroup
/dev/sda1 ext2 240972 226212 2319 99% /boot
tmpfs tmpfs 404172 0 404172 0% /run/user/1001
tmpfs tmpfs 404172 0 404172 0% /run/user/1000
/dev/loop0 btrfs 10485760 4250700 4424308 49% /chroot/compile
overlay overlay 59629100 50018424 6991008 88% /var/lib/docker/overlay2/4e9863e34f958e15f57c752fda2057b88f2aa03afaca82e0651f3aa23e56f795/merged

```

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2023年四月4日 22:06 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/22 "2023-04-04T22:06:22Z")

</div>

你们的论坛能获得多少流量？你们的论坛看起来太小了，不应该遇到这种问题。

这是官方安装吗？你们的论坛运行在什么样的 VPS 上？

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 22:12 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/23 "2023-04-04T22:12:55Z")

</div>

> [@RGJ](#):
>
> 您有多少流量？

管理页面显示过去 30 天有 50,000 次页面浏览量。

> [@RGJ](#):
>
> 这是一个[官方安装](https://meta.discourse.org/t/142537)吗？

我想是的？我遵循了当时能找到的所有说明。  
我没有对安装做太多自定义。

> [@RGJ](#):
>
> 您的论坛运行在什么类型的 VPS 上？

不确定。它来自 [cari.net](http://cari.net) 的一个 2 核 4GB 虚拟服务器。

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2023年四月4日 22:17 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/24 "2023-04-04T22:17:47Z")

</div>

您的论坛运行的 nginx 版本是 1.10.3，已超过 6 年未更新，这很不寻常。

除此之外，这可能是我见过的性能最差的 Discourse 安装之一。我并非想推销我们自己的[托管服务](https://www.communiteq.com/)，但您是否考虑过更换主机？像您论坛这样规模和流量的论坛，即使在非常小的服务器上运行也应该表现良好。

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2023年四月4日 22:21 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/25 "2023-04-04T22:21:15Z")

</div>

我相信你分享的 miniprofiler 信息有很多值得学习的地方。目前只有一件事很突出：你是否拥有数量庞大的草稿帖子？  
/my/activity/drafts

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 22:48 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/26 "2023-04-04T22:48:06Z")

</div>

> [@Ed\_S](#):
>
> 你是否有大量的草稿帖子？  
> /my/activity/drafts

我好像有 3 个草稿。

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 22:52 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/27 "2023-04-04T22:52:15Z")

</div>

> [@RGJ](#):
>
> 您的论坛运行在 6 年多前的 nginx 1.10.3 上，所以这里有些奇怪。

它运行的是 debian 9。🙂

nginx 似乎工作正常，我的网站的其余部分 ([https://fredrik.hubbe.net/](https://fredrik.hubbe.net/)) 并不慢。

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 22:55 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/28 "2023-04-04T22:55:01Z")

</div>

> [@RGJ](#):
>
> 除此之外，这一定是我见过的性能最差的 Discourse 安装之一。

但以什么标准衡量呢？  
是 Discourse 本身占用了大量内存、IO 或 CPU 吗？（如果是，为什么？我实际上并没有对它做什么……）  
还是系统运行缓慢？如果是这样，我可以和 [cari.net](http://cari.net) 谈谈。

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 23:15 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/29 "2023-04-04T23:15:26Z")

</div>

我可能今晚晚些时候会尝试重启一下，看看是否有帮助。  
已经有大约两年了，我想是时候了吧？

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 23:40 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/30 "2023-04-04T23:40:19Z")

</div>

等一下：

```plaintext
$ expr 0 `ps auxwww | tail +2 | awk '{ print " + " $6}'`
787952

```

如果所有进程的常驻内存总和小于 800MB，那么剩下的内存都去哪儿了？

/proc/meminfo 似乎也没有什么帮助：

```plaintext
root@tymin:/# cat /proc/meminfo 
MemTotal: 4041756 kB
MemFree: 122852 kB
MemAvailable: 53388 kB
Buffers: 15300 kB
Cached: 87636 kB
SwapCached: 125192 kB
Active: 314348 kB
Inactive: 300988 kB
Active(anon): 270652 kB
Inactive(anon): 276288 kB
Active(file): 43696 kB
Inactive(file): 24700 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 1949692 kB
SwapFree: 921348 kB
Dirty: 144 kB
Writeback: 0 kB
AnonPages: 484704 kB
Mapped: 72596 kB
Shmem: 34520 kB
Slab: 319792 kB
SReclaimable: 26836 kB
SUnreclaim: 292956 kB
KernelStack: 6272 kB
PageTables: 19484 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 3970568 kB
Committed_AS: 4146996 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 4001728 kB
DirectMap2M: 192512 kB

```

也许我比我想象的更需要重启…… 2 年的内核内存泄漏？

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月4日 23:47 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/31 "2023-04-04T23:47:07Z")

</div>

重启后，我现在有 2GB 的可用内存。  
看看能持续多久。 🙂

---

<div class="post-metadata">

**Author:** ![xiaokong23357](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xiaokong23357/32/321957_2.png) [@xiaokong23357](https://meta.discourse.org/u/xiaokong23357)\
**Post date:** [2023年四月4日 23:55 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/32 "2023-04-04T23:55:13Z")

</div>

在使用 Discourse 一段时间后，您会发现硬盘空间占用很大。

这主要是由于 Docker Image 的问题，升级越多，占用的空间就越多。

运行以下命令：

./launcher cleanup

可以帮助您清理 Discourse 占用的空间。

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [2023年四月5日 01:03 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/33 "2023-04-05T01:03:25Z")

</div>

这有助于减少磁盘空间使用量，但不幸的是，在这种情况下：

> [@Hubbe](#):
>
> ````plaintext
> hubbe@tymin:~$ vmstat 5 5
> procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----\n r b swpd free buff cache si so bi bo in cs us sy id wa st\n 1 4 1004748 85768 13948 114648 37 32 145 101 0 0 2 3 93 1 0\n 0 6 1033260 108584 10212 101668 1566 6661 4368 6807 497 1990 11 27 0 61 0\n12 7 1050808 99524 10708 94852 1932 4551 4854 4625 660 2263 24 32 2 42 0\n 5 8 1078776 125060 9136 92948 2079 6963 5541 7030 771 2040 17 32 0 51 0\n 4 3 1004784 168216 10164 103420 2631 1457 4970 1467 617 2136 34 38 1 27 0\n```
> 
> ````

正在发生大量的交换，这会严重影响性能。

所有东西都在等待磁盘 I/O，这是一个非常糟糕的状态。

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [2023年四月5日 06:03 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/34 "2023-04-05T06:03:59Z")

</div>

> [@Hubbe](#):
>
> nginx 似乎工作正常

问题不在于它是否工作正常，对我来说，这表明有些东西可能已过时或不是标准安装。

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月5日 06:36 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/35 "2023-04-05T06:36:59Z")

</div>

到目前为止，重启似乎奏效了。  
但仍然不确定_为什么_。

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2023年四月5日 06:56 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/36 "2023-04-05T06:56:35Z")

</div>

很高兴看到重启似乎有帮助！

> [@Hubbe](#):
>
> /proc/meminfo 似乎也没有太大帮助：

事实证明它可能很有信息量。我将分享我的，一个规模小得多的系统。

但这里有一个想法，一个可能影响性能的内核设置，你是否启用了透明大页。我没有：

```plaintext
# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

```

请参阅 [MKJ 的主观 Discourse 部署配置](https://meta.discourse.org/t/mkjs-opinionated-discourse-deployment-configuration/193355) 获取建议！

这是我的 meminfo，在一个运行良好的小得多系统上：

```plaintext
# cat /proc/meminfo
MemTotal: 1009140 kB
MemFree: 91888 kB
MemAvailable: 88692 kB
Buffers: 7644 kB
Cached: 137040 kB
SwapCached: 144884 kB
Active: 418972 kB
Inactive: 380324 kB
Active(anon): 345300 kB
Inactive(anon): 345852 kB
Active(file): 73672 kB
Inactive(file): 34472 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 2097144 kB
SwapFree: 1049764 kB
Dirty: 400 kB
Writeback: 0 kB
AnonPages: 620688 kB
Mapped: 67192 kB
Shmem: 36536 kB
Slab: 67768 kB
SReclaimable: 27832 kB
SUnreclaim: 39936 kB
KernelStack: 3804 kB
PageTables: 14968 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 2601712 kB
Committed_AS: 3784772 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 460652 kB
DirectMap2M: 587776 kB

```

---

<div class="post-metadata">

**Author:** ![Hubbe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hubbe/32/212629_2.png) [@Hubbe](https://meta.discourse.org/u/Hubbe)\
**Post date:** [2023年四月15日 20:31 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/37 "2023-04-15T20:31:41Z")

</div>

好的，我将对此事进行总结。  
重启奏效了，而且效果一直持续。  
我不知道是什么导致了内存泄漏，除非情况发生变化，否则我可能每年都需要再次重启一次，不过我可以接受。

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年五月15日 20:32 UTC](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501/38 "2023-05-15T20:32:14Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[上一頁](https://meta.discourse.org/t/discourse-installation-has-been-getting-slower-and-slower-and-slower/260501.md?page=1)
