# 我的自托管没有其他网站那么快

**URL:** https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [2024 年5 月 13 日 04:10 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717 "2024-05-13T04:10:14Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [2024 年5 月 13 日 04:10 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/1 "2024-05-13T04:10:14Z")

</div>

我的自托管站点不像其他网站那样“快”。我注意到其他网站几乎是即时的/非常快的，而我的站点在未登录时更快。它并非慢到无法使用，但以我的配置来看，我认为它应该更快。  
12 核 CPU，40GB 内存。出于隐私原因，我无法分享域名。  
对于我应该检查什么或如何优化我的 app.yml，任何建议都将不胜感激。  
它主要包含图片/视频，是这个原因吗？

```plaintext
db_shared_buffers: "34096MB"
db_work_mem: "90MB" (已取消注释)
UNICORN_WORKERS: 25

```

通过 Cloudflare 代理（用于 DDoS 防护，专业版）

---

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [2024 年5 月 13 日 05:25 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/2 "2024-05-13T05:25:29Z")

</div>

很多图片和视频可能是问题所在，这些是直接上传到 discourse 网站还是托管在其他平台？

如果你能在其他平台托管视频并在 discourse 网站上发布链接，可能会有帮助。

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [2024 年5 月 13 日 05:27 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/3 "2024-05-13T05:27:30Z")

</div>

直接上传到平台……嗯，也许

---

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [2024 年5 月 13 日 05:30 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/4 "2024-05-13T05:30:58Z")

</div>

Discourse 支持的集成平台很少，包括 Brightcove、YouTube 和 Vimeo：

> [@Handling uploaded videos](https://meta.discourse.org/t/handling-uploaded-videos/79917/8?u=architect):
>
> Discourse does integrate with various video providers, notably: [brightcove via this plugin](https://github.com/discourse/discourse-brightcove) and youtube and vimeo. So if video is your Jazz we recommend you store them on one of those providers and use oneboxes.

---

<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: [2024 年5 月 13 日 07:33 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/5 "2024-05-13T07:33:47Z")

</div>

是的，供参考，我在以下配置下获得了近乎“即时”的页面转换：

- 4GB 内存，3 核
- 2 个 Unicorns（审查后可能可以增加！）
- `db_shared_buffers: "256MB"`
- 无 CDN

但通过 YouTube 提供任何视频。

其他一切基本都是默认设置。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024 年5 月 13 日 09:15 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/6 "2024-05-13T09:15:39Z")

</div>

共享缓冲区应约为 10 GB。是我糊涂了还是你有 34 GB 的共享缓冲区？

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [2024 年5 月 13 日 12:50 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/7 "2024-05-13T12:50:00Z")

</div>

你可以改成6个独角兽，根据我读到的。3个核心，每个核心2个制服，所以是6个:) 但我明白你的意思。

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [2024 年5 月 13 日 12:50 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/8 "2024-05-13T12:50:23Z")

</div>

是的 ☹ 我以为这会以某种方式加快速度。我可以将其更改为 10GB。

---

<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: [2024 年5 月 13 日 12:51 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/9 "2024-05-13T12:51:14Z")

</div>

是的，我注释掉了那个设置并重新构建了 👍

这是我之前使用小型 VPS 时遗留下来的。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024 年5 月 13 日 13:47 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/10 "2024-05-13T13:47:51Z")

</div>

建议使用 25% 的内存。如果您为 postgres 分配几乎所有内存，那么 Web 服务器将没有内存可用。这可能是您的问题所在。

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [2024 年5 月 13 日 16:07 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/11 "2024-05-13T16:07:48Z")

</div>

我明白了，希望有更多关于如何优化它的文档等等，并非所有时候引导式的东西都有效率，我已在新服务器上设置好，并更改为您建议的设置，我还通过 Cloudflare tunnel 设置了它，从长远来看这是个好主意吗？现在一切加载都很快！我很高兴

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2024 年5 月 14 日 08:59 UTC](https://meta.discourse.org/t/my-self-host-isnt-as-fast-as-other-sites/307717/12 "2024-05-14T08:59:02Z")

</div>

app.yml 文件中有注释。discourse-setup 会创建合理的值。这些默认值可能适用于每月数百万的页面浏览量。
