# 更多的 CPU 核心还是更快的核心？

**URL:** https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826
**Category:** Self-hosting
**Tags:** hosting
**Created:** [2020 年11 月 11 日 13:17 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826 "2020-11-11T13:17:33Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### 作者： ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### 发布日期： [2020 年11 月 11 日 13:17 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/1 "2020-11-11T13:17:33Z")

</div>

我们的社区流量会因现实世界事件而出现高峰，确切地说是冰球比赛，这导致在大约 2.5 到 3 小时内，某个专属主题会收到约 1000 条消息。正如在[另一个主题](https://meta.discourse.org/t/real-time-updating-of-topics-freezes-under-high-activity/166789)中所讨论的，我们难以应对这些流量高峰。

这促使我在有限的预算下探索其他托管方案，目标预算约为每月 50 欧元。自上次研究市场报价以来，市场已有所发展。

- 仅需 42 欧元，您就可以从 [Hetzner](https://www.hetzner.com/dedicated-rootserver/matrix-ax?country=fi) 获得一台配备 Ryzen 5 3600 CPU 的独立服务器。这是一款性能相当强劲的 6 核 CPU。巧合的是，我的笔记本电脑也配备了类似的 CPU，其单线程运算速度比典型的性能良好的 VPS 快约 40% 到 50%。
- 但在相同价格区间内，您也可以购买拥有大量核心但单核性能稍逊的 VPS。[Contabo](https://contabo.com/?show=vps) 提供 10 核配置，仅需 27 美元；而 Hetzner 则提供多达 16 核的配置，价格为 62 欧元。这些只是示例，市场上还有许多其他提供商。

这些报价让我感到困惑：对于 Discourse 而言，什么样的核心配置最理想，以最大化峰值输出？是 fewer 核心但性能更高，还是更多核心？

我尝试搜索过这个问题，但大多只找到了我以前的帖子 :)。我记得这在早期曾是一个偶尔被提及的话题，但最近并未被深入讨论。多年来代码发生了很大变化，因此软件的行为或通用建议是否也有所改变？

---

<div class="post-metadata">

### 作者： ![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)
#### 发布日期： [2020 年11 月 11 日 15:23 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/2 "2020-11-11T15:23:20Z")

</div>

你说得对，这些都是旧帖子，但趋势似乎是一致的：thinking:

> [@codinghorror](#):
>
> 在某个较低阈值（例如 2GB 内存、2 个核心，除非你拥有超大型数据库）之上，这些其实并不重要；对 Discourse 而言，真正重要的是_单线程性能_。

那为游戏之夜部署一个可扩展的实例如何？只需短暂停机，就可以轻松备份并扩容或缩容。我之前在 Jitsi 实例上也遇到过类似问题（顺便提一下，[这个组件很棒](https://meta.discourse.org/t/jitsi-video-conference-component/146046)）：大部分时间它都在闲置，但每周有几次……😄

---

<div class="post-metadata">

### 作者： ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### 发布日期： [2020 年11 月 11 日 15:25 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/3 "2020-11-11T15:25:14Z")

</div>

如果不清楚您当前面临的具体瓶颈，很难提供指导。

使用 [Discourse 的 Prometheus 导出器插件](https://meta.discourse.org/t/prometheus-exporter-plugin-for-discourse/72666) 可以准确显示众多组件中究竟是哪一个出了问题。

---

<div class="post-metadata">

### 作者： ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### 发布日期： [2020 年11 月 11 日 16:34 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/4 "2020-11-11T16:34:51Z")

</div>

尽管我在首帖中介绍了我们的案例，但本意是在通用层面上进行讨论。无论我是否已确定我们的根本原因，我都可能在中期未来进入托管市场。

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2020 年11 月 11 日 17:32 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/5 "2020-11-11T17:32:22Z")

</div>

对于 Discourse，您应优先考虑核心频率而非核心数量。如果两者都能兼顾，那当然更好（特别是在高负载场景下）。但在通常情况下，2 个高频核心整体表现会优于 4 个低频核心。

我们通常以构建时间作为衡量标准，[这里有一些示例](https://meta.discourse.org/t/how-much-is-discourse-affected-by-a-faster-cpu/58407)。不过，任何单线程基准测试也同样适用。

理想情况下，构建时间应控制在 4 分钟（240 秒）以内。

---

<div class="post-metadata">

### 作者： ![Mevo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mevo/32/187732_2.png) [@Mevo](https://meta.discourse.org/u/Mevo)
#### 发布日期： [2020 年11 月 11 日 20:34 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/6 "2020-11-11T20:34:39Z")

</div>

我并非该领域的专家，但我不确定 VPS 的“虚拟”核心与 CPU 的“物理”核心是否有任何可比性。若要粗略估算，你可以参考提供的 RAM 容量，并假设这些 VPS 运行在配备 256 MB RAM 的计算机上。Contabo 提供“10（虚拟）核心”的套餐仅配备 60 MB RAM。他们很可能在相当于你提到的 Hetzner 专用服务器（一台拥有 256 MB RAM 的服务器）的硬件上运行 4 个这样的 VPS。因此，我推测这"10（虚拟）核心”的性能大约仅为"6（物理）核心”的四分之一。如果他们在配备 128 MB RAM 的计算机上运行 2 个这样的 VPS（其 CPU 可能比 Hetzner 机器更好或更慢，谁说得准呢），那性能最多也就是一半。

（你实际上只能在同一提供商的不同 VPS 套餐之间比较“虚拟核心”。我甚至不确定在不同提供商的 VPS 之间进行比较是否有意义。）

如果你想要确切的答案，就必须订阅一个月并运行基准测试。或者说服他们为你运行测试，或者为你提供短期免费试用。如果你真正追求的是性能，这是针对 VPS 唯一能确切了解其性能的方法。或者选择专用服务器，在那里你能获得更准确的信息。

编辑：像 Contabo 这样的 VPS 提供商通常使用 KVM 进行虚拟化。经过搜索，确实可以显示比实际物理核心更多的“虚拟核心”。例如：

> 是的，你可以配置并运行比可用物理核心更多的虚拟 CPU。这是一个空闲的 Windows Server 2008（x86，德语）KVM 客户机，在 4 核单 CPU Intel X3210 机器上显示了 10 个 CPU。  
> （来源：[https://serverfault.com/questions/435231/can-kvm-cpu-assignment-count-differ-from-physical-hosts-cpu-count）](https://serverfault.com/questions/435231/can-kvm-cpu-assignment-count-differ-from-physical-hosts-cpu-count%EF%BC%89)

考虑到他们提供的 RAM 数量与“核心”数量之间的比例，他们这样做是有道理的。

---

<div class="post-metadata">

### 作者： ![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)
#### 发布日期： [2020 年11 月 11 日 21:58 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/7 "2020-11-11T21:58:25Z")

</div>

> [@ljpp](#):
>
> 只需 42 欧元，您就可以从 Hetzner 获得一台配备 Ryzen 5 3600 CPU 的专用服务器。

当我查看这个优惠并心想：嗯，这交易不错时，却发现内存不支持 ECC。于是快速在网上搜索了一下，结果出现了什么？正是 Jeff 的[这篇博客文章](https://blog.codinghorror.com/to-ecc-or-not-to-ecc/)。关于 CPU 的视频让我忍俊不禁……

---

<div class="post-metadata">

### 作者： ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### 发布日期： [2020 年11 月 12 日 12:20 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/8 "2020-11-12T12:20:39Z")

</div>

哇，我已经在 Hetzner 托管了，但价格更高，CPU 更慢，存储空间也比他们目前的 Ryzen 服务器少。这让切换变得非常有吸引力……谢谢你的提醒！

---

<div class="post-metadata">

### 作者： ![misterjtc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/misterjtc/32/196401_2.png) [@misterjtc](https://meta.discourse.org/u/misterjtc)
#### 发布日期： [2020 年11 月 12 日 14:57 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/9 "2020-11-12T14:57:18Z")

</div>

感谢分享博客链接，内容值得一读。

我也同意，视频胜过千言万语，而且……确实非常有趣。

---

<div class="post-metadata">

### 作者： ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### 发布日期： [2020 年12 月 16 日 11:16 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/11 "2020-12-16T11:16:57Z")

</div>

有人针对不同的 CPU 做过关于 L3 缓存大小的测试吗？

我见过一些提到 Ruby 对内存需求很高（[https://stackify.com/ruby-performance-tuning/）。这可能为](https://stackify.com/ruby-performance-tuning/%EF%BC%89%E3%80%82%E8%BF%99%E5%8F%AF%E8%83%BD%E4%B8%BA) CPU 缓存大小的潜在影响提供线索，因为 Discourse 处理的是大型数据集。

我正在挑选新服务器并选择合适的 CPU。我在犹豫是选择最高主频，还是也要考虑 L3 缓存的大小。

目前我正在考虑 [Intel® Xeon® E-2174G](https://ark.intel.com/content/www/us/en/ark/products/134864/intel-xeon-e-2174g-processor-8m-cache-up-to-4-70-ghz.html)，这款处理器拥有 4 个核心，主频 3.8GHz，缓存为 8MB。但还有更昂贵的选项，缓存分别为 12MB 或 16MB。它们物有所值吗？

谢谢！

---

<div class="post-metadata">

### 作者： ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### 发布日期： [2020 年12 月 17 日 06:17 UTC](https://meta.discourse.org/t/a-lot-of-cpu-cores-or-fast-cores/169826/12 "2020-12-17T06:17:44Z")

</div>

根据我的经验，这不会带来显著差异。
