From 615e414c5d9add3c0445d28b6d7ca62905dc8cd8 Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 29 May 2011 15:17:29 +0200 Subject: [PATCH] INFO now contains the time (in usecs) needed to fork() in order to persist. The info is available in the stats section of INFO. --- src/aof.c | 5 ++++- src/rdb.c | 3 +++ src/redis.c | 7 +++++-- src/redis.h | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/aof.c b/src/aof.c index ef72a2b1..cd409a0b 100644 --- a/src/aof.c +++ b/src/aof.c @@ -565,16 +565,18 @@ werr: */ int rewriteAppendOnlyFileBackground(void) { pid_t childpid; + long long start; if (server.bgrewritechildpid != -1) return REDIS_ERR; if (server.ds_enabled != 0) { redisLog(REDIS_WARNING,"BGREWRITEAOF called with diskstore enabled: AOF is not supported when diskstore is enabled. Operation not performed."); return REDIS_ERR; } + start = ustime(); if ((childpid = fork()) == 0) { - /* Child */ char tmpfile[256]; + /* Child */ if (server.ipfd > 0) close(server.ipfd); if (server.sofd > 0) close(server.sofd); snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid()); @@ -585,6 +587,7 @@ int rewriteAppendOnlyFileBackground(void) { } } else { /* Parent */ + server.stat_fork_time = ustime()-start; if (childpid == -1) { redisLog(REDIS_WARNING, "Can't rewrite append only file in background: fork: %s", diff --git a/src/rdb.c b/src/rdb.c index eeafc053..0d4940d2 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -482,6 +482,7 @@ werr: int rdbSaveBackground(char *filename) { pid_t childpid; + long long start; if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t) -1) return REDIS_ERR; @@ -493,6 +494,7 @@ int rdbSaveBackground(char *filename) { return dsRdbSaveBackground(filename); } + start = ustime(); if ((childpid = fork()) == 0) { int retval; @@ -503,6 +505,7 @@ int rdbSaveBackground(char *filename) { _exit((retval == REDIS_OK) ? 0 : 1); } else { /* Parent */ + server.stat_fork_time = ustime()-start; if (childpid == -1) { redisLog(REDIS_WARNING,"Can't save in background: fork: %s", strerror(errno)); diff --git a/src/redis.c b/src/redis.c index f64a2d34..a494e1f7 100644 --- a/src/redis.c +++ b/src/redis.c @@ -964,6 +964,7 @@ void initServer() { server.stat_keyspace_misses = 0; server.stat_keyspace_hits = 0; server.stat_peak_memory = 0; + server.stat_fork_time = 0; server.unixtime = time(NULL); aeCreateTimeEvent(server.el, 1, serverCron, NULL, NULL); if (server.ipfd > 0 && aeCreateFileEvent(server.el,server.ipfd,AE_READABLE, @@ -1439,7 +1440,8 @@ sds genRedisInfoString(char *section) { "keyspace_hits:%lld\r\n" "keyspace_misses:%lld\r\n" "pubsub_channels:%ld\r\n" - "pubsub_patterns:%u\r\n", + "pubsub_patterns:%u\r\n" + "latest_fork_usec:%lld\r\n", server.stat_numconnections, server.stat_numcommands, server.stat_expiredkeys, @@ -1447,7 +1449,8 @@ sds genRedisInfoString(char *section) { server.stat_keyspace_hits, server.stat_keyspace_misses, dictSize(server.pubsub_channels), - listLength(server.pubsub_patterns)); + listLength(server.pubsub_patterns), + server.stat_fork_time); } /* Replication */ diff --git a/src/redis.h b/src/redis.h index f249d237..089a3042 100644 --- a/src/redis.h +++ b/src/redis.h @@ -547,6 +547,7 @@ struct redisServer { long long stat_keyspace_hits; /* number of successful lookups of keys */ long long stat_keyspace_misses; /* number of failed lookups of keys */ size_t stat_peak_memory; /* max used memory record */ + long long stat_fork_time; /* time needed to perform latets fork() */ /* Configuration */ int verbosity; int maxidletime; -- 2.45.2