From 35a6044140deb1c70dc92c5d454745142faeeb37 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 30 Jun 2011 15:47:15 +0200 Subject: [PATCH] slow log configuration implemented --- redis.conf | 18 ++++++++++++++++++ src/config.c | 22 ++++++++++++++++++++++ src/redis.h | 2 +- src/slowlog.c | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/redis.conf b/redis.conf index 6d18e2f5..456ffa85 100644 --- a/redis.conf +++ b/redis.conf @@ -312,6 +312,24 @@ no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb +################################## SLOW LOG ################################### + +# The Redis Slow Log is a system to log queries that exceeded a specified +# execution time. The execution time does not include the I/O operations +# like talking with the client, sending the reply and so forth, +# but just the time needed to actually execute the command (this is the only +# stage of command execution where the thread is blocked and can not serve +# other requests in the meantime). +# +# You can configure the slow log with two parameters: one tells Redis +# what is the execution time, in microseconds, to exceed in order for the +# command to get logged, and the other parameter is the length of the +# slow log. When a new command is logged the oldest one is removed from the +# queue of logged commands. + +slowlog-log-slower-than 10000 +slowlog-log-len 1024 + ############################### ADVANCED CONFIG ############################### # Hashes are encoded in a special way (much more memory efficient) when they diff --git a/src/config.c b/src/config.c index e82fbde4..e36f588a 100644 --- a/src/config.c +++ b/src/config.c @@ -296,6 +296,12 @@ void loadServerConfig(char *filename) { } else if (!strcasecmp(argv[0],"cluster-config-file") && argc == 2) { zfree(server.cluster.configfile); server.cluster.configfile = zstrdup(argv[1]); + } else if (!strcasecmp(argv[0],"slowlog-log-slower-than") && + argc == 2) + { + server.slowlog_log_slower_than = strtoll(argv[1],NULL,10); + } else if (!strcasecmp(argv[0],"slowlog-max-len") && argc == 2) { + server.slowlog_max_len = strtoll(argv[1],NULL,10); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@ -466,6 +472,12 @@ void configSetCommand(redisClient *c) { } else if (!strcasecmp(c->argv[2]->ptr,"zset-max-ziplist-value")) { if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; server.zset_max_ziplist_value = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-log-slower-than")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR) goto badfmt; + server.slowlog_log_slower_than = ll; + } else if (!strcasecmp(c->argv[2]->ptr,"slowlog-max-len")) { + if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; + server.slowlog_max_len = (unsigned)ll; } else { addReplyErrorFormat(c,"Unsupported CONFIG parameter: %s", (char*)c->argv[2]->ptr); @@ -637,6 +649,16 @@ void configGetCommand(redisClient *c) { addReplyBulkLongLong(c,server.zset_max_ziplist_value); matches++; } + if (stringmatch(pattern,"slowlog-log-slower-than",0)) { + addReplyBulkCString(c,"slowlog-log-slower-than"); + addReplyBulkLongLong(c,server.slowlog_log_slower_than); + matches++; + } + if (stringmatch(pattern,"slowlog-max-len",0)) { + addReplyBulkCString(c,"slowlog-max-len"); + addReplyBulkLongLong(c,server.slowlog_max_len); + matches++; + } setDeferredMultiBulkLength(c,replylen,matches*2); } diff --git a/src/redis.h b/src/redis.h index e74144f2..523cb311 100644 --- a/src/redis.h +++ b/src/redis.h @@ -529,7 +529,7 @@ struct redisServer { long long stat_fork_time; /* time needed to perform latets fork() */ list *slowlog; long long slowlog_log_slower_than; - unsigned int slowlog_max_len; + unsigned long slowlog_max_len; /* Configuration */ int verbosity; int maxidletime; diff --git a/src/slowlog.c b/src/slowlog.c index ecaf6508..a257a17b 100644 --- a/src/slowlog.c +++ b/src/slowlog.c @@ -54,6 +54,7 @@ void slowlogInit(void) { * This function will make sure to trim the slow log accordingly to the * configured max length. */ void slowlogPushEntryIfNeeded(robj **argv, int argc, long long duration) { + if (server.slowlog_log_slower_than < 0) return; /* Slowlog disabled */ if (duration > server.slowlog_log_slower_than) listAddNodeHead(server.slowlog,slowlogCreateEntry(argv,argc,duration)); -- 2.47.2