2017-10-18 61 views

回答

2

SLOWLOG为墙上时钟感提供时间,而不是CPU。当命令超过配置的执行时间阈值时,条目将被添加到日志中。如果CPU处于饥饿状态,并且正常或快速操作需要较长时间才能完成并超过阈值,则确实会将其添加到日志中。

+0

谢谢。因此,要明确一点,如果我们有一台CPU不足的机器,我们可以期待比使用free-er CPU的机器更多的慢日志条目。 –

+0

是的,这是正确的。 –

1

Redis使用实时而不是CPU。

通过互联网搜索后,我发现有关redis slowlog的有趣链接](http://blog.wjin.org/posts/redis-slowlog.html),这让我有一个想法来搜索Redis的源代码。

根据事实证明,在slowlog数据是由this function
void slowlogPushEntryIfNeeded(client *c, robj **argv, int argc, long long duration);呼叫添加的源代码。

搜索后,只在server.c文件中调用此功能。

所以持续时间被记录在那里,它是从[此代码段]产生(https://github.com/antirez/redis/blob/bb3b5ddd1968d2715acc37b63124ccf461276160/src/server.c#L2207

start = ustime(); 
c->cmd->proc(c); 
duration = ustime()-start; 

而ustime产生与following source code

/* Return the UNIX time in microseconds */ 
long long ustime(void) { 
    struct timeval tv; 
    long long ust; 

    gettimeofday(&tv, NULL); 
    ust = ((long long)tv.tv_sec)*1000000; 
    ust += tv.tv_usec; 
    return ust; 
} 

所以gettimeofday是负责持续时间的生产,它显示的是实际的时间而不是CPU。

+0

不错的答案,但我已经给了另一个答案的正确答案。 –