Skip to content

Commit dd4bd50

Browse files
authored
Introduce Valkey Over RDMA transport (experimental) (valkey-io#477)
Adds an option to build RDMA support as a module: make BUILD_RDMA=module To start valkey-server with RDMA, use a command line like the following: ./src/valkey-server --loadmodule src/valkey-rdma.so \ port=6379 bind=xx.xx.xx.xx * Implement server side of connection module only, this means we can *NOT* compile RDMA support as built-in. * Add necessary information in README.md * Support 'CONFIG SET/GET', for example, 'CONFIG Set rdma.port 6380', then check this by 'rdma res show cm_id' and valkey-cli (with RDMA support, but not implemented in this patch). * The full listeners show like: listener0:name=tcp,bind=*,bind=-::*,port=6379 listener1:name=unix,bind=/var/run/valkey.sock listener2:name=rdma,bind=xx.xx.xx.xx,bind=yy.yy.yy.yy,port=6379 listener3:name=tls,bind=*,bind=-::*,port=16379 Because the lack of RDMA support from TCL, use a simple C program to test Valkey Over RDMA (under tests/rdma/). This is a quite raw version with basic library dependence: libpthread, libibverbs, librdmacm. Run using the script: ./runtest-rdma [ OPTIONS ] To run RDMA in GitHub actions, a kernel module RXE for emulated soft RDMA, needs to be installed. The kernel module source code is fetched a repo containing only the RXE kernel driver from the Linux kernel, but stored in an separate repo to avoid cloning the whole Linux kernel repo. ---- Since 2021/06, I created a [PR](redis/redis#9161) for *Redis Over RDMA* proposal. Then I did some work to [fully abstract connection and make TLS dynamically loadable](redis/redis#9320), a new connection type could be built into Redis statically, or a separated shared library(loaded by Redis on startup) since Redis 7.2.0. Base on the new connection framework, I created a new [PR](redis/redis#11182), some guys(@xiezhq-hermann @zhangyiming1201 @JSpewock @uvletter @FujiZ) noticed, played and tested this PR. However, because of the lack of time and knowledge from the maintainers, this PR has been pending about 2 years. Related doc: [Introduce *Valkey Over RDMA* specification](valkey-io/valkey-doc#123). (same as Redis, and this should be same) Changes in this PR: - implement *Valkey Over RDMA*. (compact the Valkey style) Finally, if this feature is considered to merge, I volunteer to maintain it. --------- Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
1 parent c1bbdc7 commit dd4bd50

File tree

10 files changed

+3342
-1
lines changed

10 files changed

+3342
-1
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ jobs:
4444
- name: module api test
4545
run: CFLAGS='-Werror' ./runtest-moduleapi --verbose --dump-logs
4646

47+
test-rdma:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
51+
- name: make
52+
run: |
53+
sudo apt-get install librdmacm-dev libibverbs-dev
54+
make BUILD_RDMA=module
55+
- name: clone-rxe-kmod
56+
run: |
57+
mkdir -p tests/rdma/rxe
58+
git clone https://github.com/pizhenwei/rxe.git tests/rdma/rxe
59+
make -C tests/rdma/rxe
60+
- name: clear-kernel-log
61+
run: sudo dmesg -c > /dev/null
62+
- name: test
63+
run: sudo ./runtest-rdma --install-rxe
64+
- name: show-kernel-log
65+
run: sudo dmesg -c
66+
4767
build-debian-old:
4868
runs-on: ubuntu-latest
4969
container: debian:buster

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ redis.code-workspace
4747
.swp
4848
nodes*.conf
4949
tests/cluster/tmp/*
50+
tests/rdma/rdma-test

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ libssl-dev on Debian/Ubuntu) and run:
3131

3232
% make BUILD_TLS=yes
3333

34+
To build with experimental RDMA support you'll need RDMA development libraries
35+
(e.g. librdmacm-dev and libibverbs-dev on Debian/Ubuntu). For now, Valkey only
36+
supports RDMA as connection module mode. Run:
37+
38+
% make BUILD_RDMA=module
39+
3440
To build with systemd support, you'll need systemd development libraries (such
3541
as libsystemd-dev on Debian/Ubuntu or systemd-devel on CentOS) and run:
3642

@@ -155,6 +161,38 @@ Running Valkey with TLS:
155161
Please consult the [TLS.md](TLS.md) file for more information on
156162
how to use Valkey with TLS.
157163

164+
Running Valkey with RDMA:
165+
------------------
166+
167+
Note that Valkey Over RDMA is an experimental feature.
168+
It may be changed or removed in any minor or major version.
169+
Currently, it is only supported on Linux.
170+
171+
To manually run a Valkey server with RDMA mode:
172+
173+
% ./src/valkey-server --protected-mode no \
174+
--loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379
175+
176+
It's possible to change bind address/port of RDMA by runtime command:
177+
178+
192.168.122.100:6379> CONFIG SET rdma.port 6380
179+
180+
It's also possible to have both RDMA and TCP available, and there is no
181+
conflict of TCP(6379) and RDMA(6379), Ex:
182+
183+
% ./src/valkey-server --protected-mode no \
184+
--loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379 \
185+
--port 6379
186+
187+
Note that the network card (192.168.122.100 of this example) should support
188+
RDMA. To test a server supports RDMA or not:
189+
190+
% rdma res show (a new version iproute2 package)
191+
Or:
192+
193+
% ibv_devices
194+
195+
158196
Playing with Valkey
159197
------------------
160198

runtest-rdma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./tests/rdma/run.py $*

src/Makefile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,28 @@ ifeq ($(BUILD_TLS),module)
337337
TLS_MODULE_CFLAGS+=-DUSE_OPENSSL=$(BUILD_MODULE) $(OPENSSL_CFLAGS) -DBUILD_TLS_MODULE=$(BUILD_MODULE)
338338
endif
339339

340+
BUILD_RDMA:=no
341+
RDMA_MODULE=
342+
RDMA_MODULE_NAME:=valkey-rdma$(PROG_SUFFIX).so
343+
RDMA_MODULE_CFLAGS:=$(FINAL_CFLAGS)
344+
ifeq ($(BUILD_RDMA),module)
345+
FINAL_CFLAGS+=-DUSE_RDMA=$(BUILD_MODULE)
346+
RDMA_PKGCONFIG := $(shell $(PKG_CONFIG) --exists librdmacm libibverbs && echo $$?)
347+
ifeq ($(RDMA_PKGCONFIG),0)
348+
RDMA_LIBS=$(shell $(PKG_CONFIG) --libs librdmacm libibverbs)
349+
else
350+
RDMA_LIBS=-lrdmacm -libverbs
351+
endif
352+
RDMA_MODULE=$(RDMA_MODULE_NAME)
353+
RDMA_MODULE_CFLAGS+=-DUSE_RDMA=$(BUILD_YES) -DBUILD_RDMA_MODULE $(RDMA_LIBS)
354+
else
355+
ifeq ($(BUILD_RDMA),no)
356+
# disable RDMA, do nothing
357+
else
358+
$(error "RDMA is only supported as module (BUILD_RDMA=module), or disabled (BUILD_RDMA=no)")
359+
endif
360+
endif
361+
340362
ifndef V
341363
define MAKE_INSTALL
342364
@printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$(1)$(ENDCOLOR) 1>&2
@@ -414,7 +436,7 @@ ENGINE_TEST_OBJ:=$(sort $(patsubst unit/%.c,unit/%.o,$(ENGINE_TEST_FILES)))
414436
ENGINE_UNIT_TESTS:=$(ENGINE_NAME)-unit-tests$(PROG_SUFFIX)
415437
ALL_SOURCES=$(sort $(patsubst %.o,%.c,$(ENGINE_SERVER_OBJ) $(ENGINE_CLI_OBJ) $(ENGINE_BENCHMARK_OBJ)))
416438

417-
all: $(SERVER_NAME) $(ENGINE_SENTINEL_NAME) $(ENGINE_CLI_NAME) $(ENGINE_BENCHMARK_NAME) $(ENGINE_CHECK_RDB_NAME) $(ENGINE_CHECK_AOF_NAME) $(TLS_MODULE)
439+
all: $(SERVER_NAME) $(ENGINE_SENTINEL_NAME) $(ENGINE_CLI_NAME) $(ENGINE_BENCHMARK_NAME) $(ENGINE_CHECK_RDB_NAME) $(ENGINE_CHECK_AOF_NAME) $(TLS_MODULE) $(RDMA_MODULE)
418440
@echo ""
419441
@echo "Hint: It's a good idea to run 'make test' ;)"
420442
@echo ""
@@ -437,6 +459,7 @@ persist-settings: distclean
437459
echo OPT=$(OPT) >> .make-settings
438460
echo MALLOC=$(MALLOC) >> .make-settings
439461
echo BUILD_TLS=$(BUILD_TLS) >> .make-settings
462+
echo BUILD_RDMA=$(BUILD_RDMA) >> .make-settings
440463
echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings
441464
echo CFLAGS=$(CFLAGS) >> .make-settings
442465
echo LDFLAGS=$(LDFLAGS) >> .make-settings
@@ -489,6 +512,10 @@ $(ENGINE_CHECK_AOF_NAME): $(SERVER_NAME)
489512
$(TLS_MODULE_NAME): $(SERVER_NAME)
490513
$(QUIET_CC)$(CC) -o $@ tls.c -shared -fPIC $(TLS_MODULE_CFLAGS) $(TLS_CLIENT_LIBS)
491514

515+
# valkey-rdma.so
516+
$(RDMA_MODULE_NAME): $(REDIS_SERVER_NAME)
517+
$(QUIET_CC)$(CC) -o $@ rdma.c -shared -fPIC $(RDMA_MODULE_CFLAGS)
518+
492519
# valkey-cli
493520
$(ENGINE_CLI_NAME): $(ENGINE_CLI_OBJ)
494521
$(SERVER_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) $(TLS_CLIENT_LIBS)

0 commit comments

Comments
 (0)