Skip to content

Commit

Permalink
Deploy SAIO to Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
eecheng87 committed Mar 14, 2022
1 parent 79ac719 commit a958d69
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ NGX_NAME := nginx-1.20.0
NGX_PATH := downloads/$(NGX_NAME)
NGX := nginx

REDIS_SOURCE := https://github.com/redis/redis/archive/refs/tags/7.0-rc2.tar.gz
REDIS_NAME := redis-7.0-rc2
REDIS_ZIP_NAME := 7.0-rc2
REDIS_PATH := downloads/$(REDIS_NAME)
REDIS := redis

LIBDUMMY_PATH := $(shell find $(shell pwd) -type f -name "libdummy.so") | sed 's_/_\\/_g'
PWD := $(shell pwd)
OUT := downloads
Expand Down Expand Up @@ -54,6 +60,16 @@ $(NGX):
cd $(NGX_PATH) && make -j$(nproc) && make install
cp -f configs/nginx.conf local/conf/nginx.conf

$(REDIS):
@echo "download redis..."
wget $(REDIS_SOURCE)
mkdir -p $(REDIS_PATH)
tar -zxvf $(REDIS_ZIP_NAME).tar.gz -C $(OUT)
rm $(REDIS_ZIP_NAME).tar.gz
scripts/redis.sh $(REDIS_PATH)
cd $(OUT) && patch -p1 < ../patches/redis_network.patch && patch -p1 < ../patches/redis_network.patch
cd $(REDIS_PATH) && make -j$(nproc)

test-nginx-perf:
./$(NGX_PATH)/objs/nginx

Expand All @@ -66,10 +82,19 @@ test-lighttpd-perf:
test-esca-lighttpd-perf:
LD_PRELOAD=wrapper/preload.so ./$(LIGHTY_PATH)/src/lighttpd -D -f $(LIGHTY_PATH)/src/lighttpd.conf #& \

test-redis-perf:
./$(REDIS_PATH)/src/redis-server

test-esca-redis-perf:
LD_PRELOAD=wrapper/preload.so ./$(REDIS_PATH)/src/redis-server


ifeq ($(strip $(TARGET)),ngx)
TARGET = ngx
else ifeq ($(strip $(TARGET)),lighty)
TARGET = lighty
else ifeq ($(strip $(TARGET)),redis)
TARGET = redis
endif

config:
Expand Down
3 changes: 2 additions & 1 deletion module/include/aarch64_syscall.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define __ESCA_sendfile 71
#define __ESCA_shutdown 210
#define __ESCA_close 57
#define __ESCA_close 57
#define __ESCA_write 64
3 changes: 2 additions & 1 deletion module/include/x86_syscall.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define __ESCA_sendfile 40
#define __ESCA_shutdown 48
#define __ESCA_close 3
#define __ESCA_close 3
#define __ESCA_write 1
18 changes: 18 additions & 0 deletions patches/redis_network.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- old/redis-7.0-rc2/src/networking.c 2022-02-28 21:35:46.000000000 +0800
+++ new/redis-7.0-rc2/src/networking.c 2022-03-14 18:36:07.198857861 +0800
@@ -1974,6 +1974,7 @@
int processed = listLength(server.clients_pending_write);

listRewind(server.clients_pending_write,&li);
+batch_start();
while((ln = listNext(&li))) {
client *c = listNodeValue(ln);
c->flags &= ~CLIENT_PENDING_WRITE;
@@ -2008,6 +2009,7 @@
}
}
}
+batch_flush();
return processed;
}

11 changes: 11 additions & 0 deletions patches/redis_server.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- old/redis-7.0-rc2/src/server.c 2022-02-28 21:35:46.000000000 +0800
+++ new/redis-7.0-rc2/src/server.c 2022-03-14 20:18:31.540987391 +0800
@@ -6983,7 +6983,7 @@

redisSetCpuAffinity(server.server_cpulist);
setOOMScoreAdj(-1);
-
+ init_worker(0);
aeMain(server.el);
aeDeleteEventLoop(server.el);
return 0;
8 changes: 8 additions & 0 deletions scripts/redis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

libpath=$(find $(pwd) -type f -name "libdummy.so" | sed 's_/_\\/_g')
webpath=$(readlink --canonicalize web | sed 's_/_\\/_g')
redispath=$1

# modify redis
sed -i 's/FINAL_LIBS=-lm/FINAL_LIBS=-lm ${libpath}/' ${redispath}/src/Makefile
27 changes: 27 additions & 0 deletions wrapper/redis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ssize_t write(int fd, const void* buf, size_t count)
{
#if 1
if (!in_segment) {
return real_write(fd, buf, count);
}
#endif
int idx = this_worker_id * RATIO + (fd % RATIO);

batch_num++;

int i = table[idx]->tail_table;
int j = table[idx]->tail_entry;

table[idx]->user_tables[i][j].sysnum = __ESCA_write;
table[idx]->user_tables[i][j].nargs = 3;
table[idx]->user_tables[i][j].args[0] = fd;
table[idx]->user_tables[i][j].args[1] = buf;
table[idx]->user_tables[i][j].args[2] = count;

update_index(idx);

esca_smp_store_release(&table[idx]->user_tables[i][j].rstatus, BENTRY_BUSY);

/* assume success */
return count;
}

0 comments on commit a958d69

Please sign in to comment.