# 预期的 Redis 连接数

**URL:** <https://meta.discourse.org/t/expected-number-of-redis-connections/227000>\
**Category:** Self-hosting\
**Tags:** hosting\
**Created:** [2022年五月14日 02:02 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000 "2022-05-14T02:02:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dotnetnate](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dotnetnate/32/198858_2.png) [@dotnetnate](https://meta.discourse.org/u/dotnetnate)\
**Post date:** [2022年五月14日 02:02 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000/1 "2022-05-14T02:02:43Z")

</div>

我们在 Azure 上运行了多个 Discourse 实例，并为此使用共享的 Redis 服务。对于大约 20 个实例，我看到连接到 Redis 的峰值是 350 个连接，并且它在 330-340 之间波动，平均每个实例约 17 个连接。考虑到 Redis 在 CPU 和内存方面都未得到充分利用，这会严重影响 SKU 的连接限制。

这个比例是预期的吗？

---

<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:** [2022年五月14日 11:06 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000/2 "2022-05-14T11:06:00Z")

</div>

> [@dotnetnate](#):
>
> 我们在 Azure 上运行了多个 Discourse 实例，并为此使用了一个共享的 Redis 服务。

不推荐这样做。我被告知不止一次，某些使用的 Redis 功能会在站点之间泄露。但我不知道如何找到相关主题。

---

<div class="post-metadata">

**Author:** ![dotnetnate](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dotnetnate/32/198858_2.png) [@dotnetnate](https://meta.discourse.org/u/dotnetnate)\
**Post date:** [2022年五月14日 13:19 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000/3 "2022-05-14T13:19:34Z")

</div>

我遇到了一个与此相反的说法，即在使用多站点时（尽管这些只是单独的部署），使用单个 Redis 实例是可以的。Redis 本身不会“泄漏”——这是应用程序才会做的事情。

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2022年五月14日 13:26 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000/4 "2022-05-14T13:26:41Z")

</div>

> [@dotnetnate](#):
>
> 这些只是单独的部署

您必须为每个 Discourse 部署使用一个单独的 Redis。

> [@Multiple discourse on a single redis host](https://meta.discourse.org/t/multiple-discourse-on-a-single-redis-host/219318/2?u=david):
>
> Each Discourse needs its own totally separate redis server because message-bus uses [Redis Pub/Sub](https://redis.io/topics/pubsub), which is shared between all databases on a Redis server. If you run Discourse in a multisite configuration, then we automatically add a site-specific prefix to all keys and pub-sub channels. That same prefixing is not available for standard ‘single site’ installations.

---

<div class="post-metadata">

**Author:** ![dotnetnate](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dotnetnate/32/198858_2.png) [@dotnetnate](https://meta.discourse.org/u/dotnetnate)\
**Post date:** [2022年五月14日 13:41 UTC](https://meta.discourse.org/t/expected-number-of-redis-connections/227000/5 "2022-05-14T13:41:41Z")

</div>

谢谢。是的，我通常会默认让应用程序这样做以避免此类问题——看来那会是一个更安全的默认设置，但事实就是如此。
