Skip to content

Commit 70106f0

Browse files
authored
Support RDMA for valkey-cli and benchmark (#2059)
Add '--rdma' for both valkey-cli and valkey-benchmark to enable RDMA. Valkey has already replaced dependency `hiredis` with `libvalkey` (#2032), and libvalkey also supports RDMA. --------- Signed-off-by: zhenwei pi <zhenwei.pi@linux.dev> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
1 parent 22c2191 commit 70106f0

File tree

8 files changed

+163
-120
lines changed

8 files changed

+163
-120
lines changed

cmake/Modules/ValkeySetup.cmake

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ macro (valkey_build_and_install_bin target sources ld_flags libs link_name)
8989
target_link_libraries(${target} OpenSSL::SSL valkey::valkey_tls)
9090
endif ()
9191

92+
if (USE_RDMA)
93+
# Add required libraries needed for RDMA
94+
# Bug in libvalkey 0.1.0: The order is important and we need to link
95+
# valkey::valkey after valkey::valkey_rdma. This will be fixed upstream.
96+
# TODO: Next time we lift libvalkey, remove valkey::valkey from
97+
# the next line.
98+
target_link_libraries(${target} valkey::valkey_rdma valkey::valkey)
99+
endif ()
100+
92101
if (IS_FREEBSD)
93102
target_link_libraries(${target} execinfo)
94103
endif ()
@@ -101,30 +110,6 @@ macro (valkey_build_and_install_bin target sources ld_flags libs link_name)
101110
valkey_create_symlink(${target} ${link_name})
102111
endmacro ()
103112

104-
# Helper function that defines, builds and installs `target` module.
105-
macro (valkey_build_and_install_module target sources ld_flags libs)
106-
add_library(${target} SHARED ${sources})
107-
108-
if (USE_JEMALLOC)
109-
# Using jemalloc
110-
target_link_libraries(${target} jemalloc)
111-
endif ()
112-
113-
# Place this line last to ensure that ${ld_flags} is placed last on the linker line
114-
target_link_libraries(${target} ${libs} ${ld_flags})
115-
if (USE_TLS)
116-
# Add required libraries needed for TLS
117-
target_link_libraries(${target} OpenSSL::SSL valkey::valkey_tls)
118-
endif ()
119-
120-
if (IS_FREEBSD)
121-
target_link_libraries(${target} execinfo)
122-
endif ()
123-
124-
# Install cli tool and create a redis symbolic link
125-
valkey_install_bin(${target})
126-
endmacro ()
127-
128113
# Determine if we are building in Release or Debug mode
129114
if (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DebugFull)
130115
set(VALKEY_DEBUG_BUILD 1)

deps/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ if (USE_TLS) # Module or no module
1414
message(STATUS "Building valkey_tls")
1515
set(ENABLE_TLS
1616
ON
17-
CACHE BOOL "Should we test SSL connections")
17+
CACHE BOOL "If TLS support should be compiled or not")
18+
endif ()
19+
if (USE_RDMA) # Module or no module
20+
message(STATUS "Building valkey_rdma")
21+
set(ENABLE_RDMA
22+
ON
23+
CACHE BOOL "If RDMA support should be compiled or not")
1824
endif ()
1925
# Let libvalkey use sds and dict provided by valkey.
2026
set(DICT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src)
@@ -29,3 +35,4 @@ add_subdirectory(hdr_histogram)
2935
unset(BUILD_SHARED_LIBS CACHE)
3036
unset(DISABLE_TESTS CACHE)
3137
unset(ENABLE_TLS CACHE)
38+
unset(ENABLE_RDMA CACHE)

deps/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ifneq (,$(filter $(BUILD_TLS),yes module))
5252
LIBVALKEY_MAKE_FLAGS += USE_TLS=1
5353
endif
5454

55+
ifneq (,$(filter $(BUILD_RDMA),yes module))
56+
LIBVALKEY_MAKE_FLAGS += USE_RDMA=1
57+
endif
58+
5559
libvalkey: .make-prerequisites
5660
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
5761
cd libvalkey && $(MAKE) static $(LIBVALKEY_MAKE_FLAGS)

src/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,15 @@ endif
340340

341341
ifeq ($(BUILD_RDMA),yes)
342342
FINAL_CFLAGS+=-DUSE_RDMA=$(BUILD_YES) -DBUILD_RDMA_MODULE=$(BUILD_NO)
343-
FINAL_LIBS += $(RDMA_LIBS)
343+
FINAL_LIBS += ../deps/libvalkey/lib/libvalkey_rdma.a $(RDMA_LIBS)
344344
endif
345345

346346
RDMA_MODULE=
347347
RDMA_MODULE_NAME:=valkey-rdma$(PROG_SUFFIX).so
348348
RDMA_MODULE_CFLAGS:=$(FINAL_CFLAGS)
349349
ifeq ($(BUILD_RDMA),module)
350350
FINAL_CFLAGS+=-DUSE_RDMA=$(BUILD_MODULE)
351+
RDMA_CLIENT_LIBS = ../deps/libvalkey/lib/libvalkey_rdma.a $(RDMA_LIBS)
351352
RDMA_MODULE=$(RDMA_MODULE_NAME)
352353
RDMA_MODULE_CFLAGS+=-DUSE_RDMA=$(BUILD_MODULE) -DBUILD_RDMA_MODULE=$(BUILD_MODULE) $(RDMA_LIBS)
353354
endif
@@ -522,11 +523,11 @@ $(RDMA_MODULE_NAME): $(SERVER_NAME)
522523

523524
# valkey-cli
524525
$(ENGINE_CLI_NAME): $(ENGINE_CLI_OBJ)
525-
$(SERVER_LD) -o $@ $^ ../deps/libvalkey/lib/libvalkey.a ../deps/linenoise/linenoise.o ../deps/fpconv/libfpconv.a $(FINAL_LIBS) $(TLS_CLIENT_LIBS)
526+
$(SERVER_LD) -o $@ $^ ../deps/libvalkey/lib/libvalkey.a ../deps/linenoise/linenoise.o ../deps/fpconv/libfpconv.a $(FINAL_LIBS) $(TLS_CLIENT_LIBS) $(RDMA_CLIENT_LIBS)
526527

527528
# valkey-benchmark
528529
$(ENGINE_BENCHMARK_NAME): $(ENGINE_BENCHMARK_OBJ)
529-
$(SERVER_LD) -o $@ $^ ../deps/libvalkey/lib/libvalkey.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS) $(TLS_CLIENT_LIBS)
530+
$(SERVER_LD) -o $@ $^ ../deps/libvalkey/lib/libvalkey.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS) $(TLS_CLIENT_LIBS) $(RDMA_CLIENT_LIBS)
530531

531532
DEP = $(ENGINE_SERVER_OBJ:%.o=%.d) $(ENGINE_CLI_OBJ:%.o=%.d) $(ENGINE_BENCHMARK_OBJ:%.o=%.d)
532533
-include $(DEP)

src/cli_common.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
#include "cli_common.h"
3333
#include "version.h"
3434

35+
#include <assert.h>
3536
#include <stdio.h>
3637
#include <stdlib.h>
3738
#include <fcntl.h>
3839
#include <errno.h>
39-
#include <valkey/valkey.h>
4040
#include "sds.h"
4141
#include <unistd.h>
4242
#include <string.h>
@@ -46,6 +46,9 @@
4646
#include <openssl/err.h>
4747
#include <valkey/tls.h>
4848
#endif
49+
#ifdef USE_RDMA
50+
#include <valkey/rdma.h>
51+
#endif
4952

5053
#define UNUSED(V) ((void)V)
5154

@@ -427,25 +430,29 @@ sds cliVersion(void) {
427430
}
428431

429432
/* This is a wrapper to call valkeyConnect or valkeyConnectWithTimeout. */
430-
valkeyContext *valkeyConnectWrapper(const char *ip, int port, const struct timeval tv, int nonblock) {
433+
valkeyContext *valkeyConnectWrapper(enum valkeyConnectionType ct, const char *ip_or_path, int port, const struct timeval tv, int nonblock) {
431434
valkeyOptions options = {0};
432-
VALKEY_OPTIONS_SET_TCP(&options, ip, port);
433435

434-
if (tv.tv_sec || tv.tv_usec) {
435-
options.connect_timeout = &tv;
436-
}
436+
switch (ct) {
437+
case VALKEY_CONN_TCP:
438+
VALKEY_OPTIONS_SET_TCP(&options, ip_or_path, port);
439+
break;
437440

438-
if (nonblock) {
439-
options.options |= VALKEY_OPT_NONBLOCK;
440-
}
441+
case VALKEY_CONN_UNIX:
442+
VALKEY_OPTIONS_SET_UNIX(&options, ip_or_path);
443+
break;
441444

442-
return valkeyConnectWithOptions(&options);
443-
}
445+
case VALKEY_CONN_RDMA:
446+
#ifdef USE_RDMA
447+
VALKEY_OPTIONS_SET_RDMA(&options, ip_or_path, port);
448+
break;
449+
#else
450+
assert(0); /* requesting RDMA connection without RDMA support??? */
451+
#endif
444452

445-
/* This is a wrapper to call valkeyConnectUnix or valkeyConnectUnixWithTimeout. */
446-
valkeyContext *valkeyConnectUnixWrapper(const char *path, const struct timeval tv, int nonblock) {
447-
valkeyOptions options = {0};
448-
VALKEY_OPTIONS_SET_UNIX(&options, path);
453+
default:
454+
assert(0); /* this should not happen */
455+
}
449456

450457
if (tv.tv_sec || tv.tv_usec) {
451458
options.connect_timeout = &tv;

src/cli_common.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ sds escapeJsonString(sds s, const char *p, size_t len);
5353

5454
sds cliVersion(void);
5555

56-
valkeyContext *valkeyConnectWrapper(const char *ip, int port, const struct timeval tv, int nonblock);
57-
valkeyContext *valkeyConnectUnixWrapper(const char *path, const struct timeval tv, int nonblock);
56+
valkeyContext *valkeyConnectWrapper(enum valkeyConnectionType ct, const char *ip_or_path, int port, const struct timeval tv, int nonblock);
5857

5958
#endif /* __CLICOMMON_H */

0 commit comments

Comments
 (0)