Skip to content
Browse files

added option to copy the reply instead of using copy-on-write, as a c…

…opy-on-write friendly alternative. Added DEBUG FORK to perform tests with COW and different access patterns
  • Loading branch information...
1 parent cbce517 commit d4c57c477038e5bfc96548a820ffa8a71277902c @antirez antirez committed Aug 5, 2010
Showing with 31 additions and 1 deletion.
  1. +7 −0 redis.conf
  2. +4 −0 src/config.c
  3. +7 −0 src/debug.c
  4. +11 −1 src/networking.c
  5. +1 −0 src/redis.c
  6. +1 −0 src/redis.h
View
7 redis.conf
@@ -321,6 +321,13 @@ hash-max-zipmap-value 512
# want to free memory asap when possible.
activerehashing yes
+# Copying replies to client output buffers is slower but may lead to less
+# pages duplicated for copy-on-write due to saving childs being active.
+# Currently it's just an experiment...
+
+copyreply yes
+#copyreply no
+
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
View
4 src/config.c
@@ -141,6 +141,10 @@ void loadServerConfig(char *filename) {
if ((server.activerehashing = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
+ } else if (!strcasecmp(argv[0],"copyreply") && argc == 2) {
+ if ((server.copyreply = yesnotoi(argv[1])) == -1) {
+ err = "argument must be 'yes' or 'no'"; goto loaderr;
+ }
} else if (!strcasecmp(argv[0],"daemonize") && argc == 2) {
if ((server.daemonize = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
View
7 src/debug.c
@@ -286,6 +286,13 @@ void debugCommand(redisClient *c) {
d = sdscatlen(d,"\r\n",2);
addReplySds(c,d);
+ } else if (!strcasecmp(c->argv[1]->ptr,"fork") && c->argc == 2) {
+ if (fork() == 0) {
+ /* The child will wait forever... */
+ while(1) sleep(1);
+ } else {
+ addReply(c,shared.ok);
+ }
} else {
addReplySds(c,sdsnew(
"-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT <key>|SWAPIN <key>|SWAPOUT <key>|RELOAD]\r\n"));
View
12 src/networking.c
@@ -60,7 +60,17 @@ void addReply(redisClient *c, robj *obj) {
aeCreateFileEvent(server.el, c->fd, AE_WRITABLE,
sendReplyToClient, c) == AE_ERR) return;
- if (server.vm_enabled && obj->storage != REDIS_VM_MEMORY) {
+ if (server.copyreply) {
+ robj *copy;
+
+ if (obj->encoding == REDIS_ENCODING_RAW) {
+ copy = dupStringObject(obj);
+ } else {
+ copy = getDecodedObject(obj);
+ }
+ listAddNodeTail(c->reply,copy);
+ return;
+ } else if (server.vm_enabled && obj->storage != REDIS_VM_MEMORY) {
obj = dupStringObject(obj);
obj->refcount = 0; /* getDecodedObject() will increment the refcount */
}
View
1 src/redis.c
@@ -729,6 +729,7 @@ void initServerConfig() {
server.requirepass = NULL;
server.rdbcompression = 1;
server.activerehashing = 1;
+ server.copyreply = 0;
server.maxclients = 0;
server.blpop_blocked_clients = 0;
server.maxmemory = 0;
View
1 src/redis.h
@@ -371,6 +371,7 @@ struct redisServer {
char *requirepass;
int rdbcompression;
int activerehashing;
+ int copyreply; /* Copy objects in addReply to avoid COW business? */
/* Replication related */
int isslave;
char *masterauth;

0 comments on commit d4c57c4

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