From d3efe04c4731bda4657b80f099f8bcaca3c26319 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 24 Mar 2014 10:00:08 +0100 Subject: [PATCH] Cache uname() output across INFO calls. Uname was profiled to be a slow syscall. It produces always the same output in the context of a single execution of Redis, so calling it at every INFO output generation does not make too much sense. The uname utsname structure was modified as a static variable. At the same time a static integer was added to check if we need to call uname the first time. --- src/redis.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/redis.c b/src/redis.c index c2a858fd..30816825 100644 --- a/src/redis.c +++ b/src/redis.c @@ -2359,7 +2359,8 @@ sds genRedisInfoString(char *section) { /* Server */ if (allsections || defsections || !strcasecmp(section,"server")) { - struct utsname name; + static int call_uname = 1; + static struct utsname name; char *mode; if (server.cluster_enabled) mode = "cluster"; @@ -2367,7 +2368,13 @@ sds genRedisInfoString(char *section) { else mode = "standalone"; if (sections++) info = sdscat(info,"\r\n"); - uname(&name); + + if (call_uname) { + /* Uname can be slow and is always the same output. Cache it. */ + uname(&name); + call_uname = 0; + } + info = sdscatprintf(info, "# Server\r\n" "redis_version:%s\r\n"