Skip to content
Browse files

INFO now contains the time (in usecs) needed to fork() in order to pe…

…rsist. The info is available in the stats section of INFO.
  • Loading branch information...
1 parent 3246385 commit 27c8f84c66e23fafc8964ed2d9e51d708e27ab3d @antirez committed May 29, 2011
Showing with 12 additions and 1 deletion.
  1. +4 −1 src/aof.c
  2. +3 −0 src/rdb.c
  3. +3 −0 src/redis.c
  4. +1 −0 src/redis.h
  5. +1 −0 src/util.c
View
5 src/aof.c
@@ -589,13 +589,15 @@ int rewriteAppendOnlyFile(char *filename) {
*/
int rewriteAppendOnlyFileBackground(void) {
pid_t childpid;
+ long long start;
if (server.bgrewritechildpid != -1) return REDIS_ERR;
if (server.vm_enabled) waitEmptyIOJobsQueue();
+ start = ustime();
if ((childpid = fork()) == 0) {
- /* Child */
char tmpfile[256];
+ /* Child */
if (server.vm_enabled) vmReopenSwapFile();
if (server.ipfd > 0) close(server.ipfd);
if (server.sofd > 0) close(server.sofd);
@@ -607,6 +609,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",
View
3 src/rdb.c
@@ -498,10 +498,12 @@ int rdbSave(char *filename) {
int rdbSaveBackground(char *filename) {
pid_t childpid;
+ long long start;
if (server.bgsavechildpid != -1) return REDIS_ERR;
if (server.vm_enabled) waitEmptyIOJobsQueue();
server.dirty_before_bgsave = server.dirty;
+ start = ustime();
if ((childpid = fork()) == 0) {
/* Child */
if (server.vm_enabled) vmReopenSwapFile();
@@ -514,6 +516,7 @@ int rdbSaveBackground(char *filename) {
}
} else {
/* Parent */
+ server.stat_fork_time = ustime()-start;
if (childpid == -1) {
redisLog(REDIS_WARNING,"Can't save in background: fork: %s",
strerror(errno));
View
3 src/redis.c
@@ -909,6 +909,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,
@@ -1207,6 +1208,7 @@ sds genRedisInfoString(void) {
"hash_max_zipmap_value:%zu\r\n"
"pubsub_channels:%ld\r\n"
"pubsub_patterns:%u\r\n"
+ "latest_fork_usec:%lld\r\n"
"vm_enabled:%d\r\n"
"role:%s\r\n"
,REDIS_VERSION,
@@ -1249,6 +1251,7 @@ sds genRedisInfoString(void) {
server.hash_max_zipmap_value,
dictSize(server.pubsub_channels),
listLength(server.pubsub_patterns),
+ server.stat_fork_time,
server.vm_enabled != 0,
server.masterhost == NULL ? "master" : "slave"
);
View
1 src/redis.h
@@ -401,6 +401,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;
View
1 src/util.c
@@ -5,6 +5,7 @@
#include <ctype.h>
#include <limits.h>
#include <math.h>
+#include <sys/time.h>
#include "util.h"

0 comments on commit 27c8f84

Please sign in to comment.
Something went wrong with that request. Please try again.