Redis 是否可以从其 RDB 备份进程拥有多个核心中获益?

Could Redis benefit from having more than one core for its RDB backup process?

我有一个包含多个节点的 Redis 集群,想知道集群中的每个 Redis 节点是否会受益于在 GCP VM 上拥有多个 vCPU。

我知道每个 Redis 节点都是单线程的,因为它基于事件循环的设计。但是,official doc 中也提到,Redis 在将 RDB 快照持久化到磁盘时会分叉一个子进程。如果为每个节点配置 >1 CPU,分叉的子进程是否能够利用单独的核心?

为了回答您的问题,CPU 的数量可能会影响分叉的子进程,但 child process 更像是一个消耗内存的进程。

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits.

In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages.

但是,为了最大化 CPU 使用率,您可以在同一个盒子中启动多个 Redis 实例,并将它们视为不同的服务器。在某些时候,一个盒子可能还不够,所以如果你想使用多个 CPUs 你可以开始考虑一些更早分片的方法。

CPU 成为您使用 Redis 的瓶颈的情况并不常见,因为 Redis 通常受内存或网络限制。

您可能还想查看 Redis hardware requirements link,Redis 已经列出了每个功能的推荐硬件设置。