为什么Redis保存部分数据集?

时间:2019-02-27 07:14:20

标签: c redis

版本:Redis 5.0.3

redis.conf中,有一个选项可以设置快照时间。如果将一个值更改为转储时看到Redis的性能,则将此周期设置为每5秒一次。我运行了两个应用程序;一个是redis-server,另一个是redis-benchmark。 在观看日志时,发现了一些有趣的东西,如下所示。

7269:C 27 Feb 2019 14:48:39.463 * RDB: 4535 MB of memory used by copy-on-write
7257:M 27 Feb 2019 14:48:39.939 * Background saving terminated with success
7257:M 27 Feb 2019 14:48:45.085 * 10 changes in 5 seconds. Saving...
7257:M 27 Feb 2019 14:48:45.187 * Background saving started by pid 7270
7270:C 27 Feb 2019 14:49:00.313 * DB saved on disk
7270:C 27 Feb 2019 14:49:00.401 * RDB: 4535 MB of memory used by copy-on-write
7257:M 27 Feb 2019 14:49:00.882 * Background saving terminated with success
7257:M 27 Feb 2019 14:49:06.011 * 10 changes in 5 seconds. Saving...
7257:M 27 Feb 2019 14:49:06.114 * Background saving started by pid 7271
7271:C 27 Feb 2019 14:49:21.086 * DB saved on disk
7271:C 27 Feb 2019 14:49:21.173 * RDB: 4534 MB of memory used by copy-on-write
7257:M 27 Feb 2019 14:49:21.706 * Background saving terminated with success
7257:M 27 Feb 2019 14:49:27.048 * 10 changes in 5 seconds. Saving...
7257:M 27 Feb 2019 14:49:27.155 * Background saving started by pid 7273
7273:C 27 Feb 2019 14:49:42.295 * DB saved on disk
7273:C 27 Feb 2019 14:49:42.382 * RDB: 4529 MB of memory used by copy-on-write
7257:M 27 Feb 2019 14:49:42.846 * Background saving terminated with success
7257:M 27 Feb 2019 14:49:48.023 * 10 changes in 5 seconds. Saving...
7257:M 27 Feb 2019 14:49:48.126 * Background saving started by pid 7274
7274:C 27 Feb 2019 14:50:05.251 * DB saved on disk
7274:C 27 Feb 2019 14:50:05.367 * RDB: 15 MB of memory used by copy-on-write
7257:M 27 Feb 2019 14:50:05.583 * Background saving terminated with success

如您所见,转储的数据与其他数据几乎相同,最后一个数据甚至很小。我不明白的是为什么尺寸相同,为什么最后一个尺寸较小。 (当redis正在转储时,客户端请求set操作,而最后一次转储可能意味着set操作的结束和get操作的开始。)

要找出原因,我查找了代码,但仍然不知道为什么数字显示如上。

如果在redis软件包中看到rdb.c,则可以找到这种源代码。

int rdbSave(char *filename, rdbSaveInfo *rsi) {
    ...
    snprintf(tmpfile, 256, "temp-%d.rdb", (int) getpid());
    fp = fopen(tmpfile, "w");
    ...
    rdbSaveRio(...);
}

根据我的理解,每次redis转储内存中的数据时,它都应该覆盖以前保存的数据,并且此数据应该比以前更大。但是,基于日志,大小不会线性增加,甚至在最后一次转储时大小也会减小。

我是否缺少Redis功能的一部分?

编辑

根据评论,我肯定误解了日志。但是,我仍然对性能有疑问。发生快照时,如果有私有脏内存,系统会将它们保存到磁盘中。在这一点上,基于Redis转储机制,尽管系统看到由set操作引起的私有脏内存,并且仅将此数字记录在日志中,但它会保存内存中的所有数据。这意味着每次发生转储时,磁盘的大小都会扩大,我非常确定这会导致性能下降。但是,当我看到基准测试的结果时,尽管磁盘大小增加了,我仍然可以看到同样的性能下降。我想知道为什么它显示出相同的丢弃率以及内部情况。

graph

在上图中,蓝线表示吞吐量,您可以看到它在快照发生时下降,并且您还可以注意到,即使第二个删除阶段比第一个阶段保存更大的磁盘大小,删除率仍为相同。因此,我的问题是性能是否仅受私有内存节省的影响?

0 个答案:

没有答案