Skip to content

Commit 44492c3

Browse files
pizhenweisigemptyFujiZzhuojiang123zhangyiming1201
committed
Introduce Valkey Over RDMA protocol
RDMA is the abbreviation of remote direct memory access. It is a technology that enables computers in a network to exchange data in the main memory without involving the processor, cache, or operating system of either computer. This means RDMA has a better performance than TCP, the test results show Valkey Over RDMA has a ~2.5X QPS and lower latency. In recent years, RDMA gets popular in the data center, especially RoCE(RDMA over Converged Ethernet) architecture has been widely used. Cloud Vendors also start to support RDMA instance in order to accelerate networking performance. End-user would enjoy the improvement easily. Introduce Valkey Over RDMA protocol as a new transport for Valkey. For now, we defined 4 commands: - GetServerFeature & SetClientFeature: the two commands are used to negotiate features for further extension. There is no feature definition in this version. Flow control and multi-buffer may be supported in the future, this needs feature negotiation. - Keepalive - RegisterXferMemory: the heart to transfer the real payload. The 'TX buffer' and 'RX buffer' are designed by RDMA remote memory with RDMA write/write with imm, it's similar to several mechanisms introduced by papers(but not same): - Socksdirect: datacenter sockets can be fast and compatible <https://dl.acm.org/doi/10.1145/3341302.3342071> - LITE Kernel RDMA Support for Datacenter Applications <https://dl.acm.org/doi/abs/10.1145/3132747.3132762> - FaRM: Fast Remote Memory <https://www.usenix.org/system/files/conference/nsdi14/nsdi14-paper-dragojevic.pdf> Link: valkey-io/valkey#477 Co-authored-by: Xinhao Kong <xinhao.kong@duke.edu> Co-authored-by: Huaping Zhou <zhouhuaping.san@bytedance.com> Co-authored-by: zhuo jiang <jiangzhuo.cs@bytedance.com> Co-authored-by: Yiming Zhang <zhangyiming1201@bytedance.com> Co-authored-by: Jianxi Ye <jianxi.ye@bytedance.com> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
1 parent f4ce160 commit 44492c3

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

topics/RDMA.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
---
2+
title: "RDMA support"
3+
linkTitle: "RDMA support"
4+
description: Valkey Over RDMA support
5+
---
6+
7+
Valkey supports the Remote Direct Memory Access (RDMA) connection type via a
8+
Valkey module that can be dynamically loaded on demand.
9+
10+
## Getting Started
11+
12+
[RDMA](https://en.wikipedia.org/wiki/Remote_direct_memory_access)
13+
enables direct data exchange between networked computers' main memory,
14+
bypassing processors and operating systems.
15+
16+
As a result, RDMA offers better performance compared to TCP/IP. Test results indicate that
17+
Valkey Over RDMA achieves approximately 2 times higher QPS and lower latency.
18+
19+
Please note that Valkey Over RDMA is currently supported only on Linux.
20+
21+
## Running manually
22+
23+
To run a Valkey server with RDMA mode:
24+
25+
~# ./src/valkey-server --protected-mode no \
26+
--loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379
27+
28+
Bind address/port of RDMA can be modified at runtime using the following command:
29+
30+
192.168.122.100:6379> CONFIG SET rdma-port 6380
31+
32+
Valkey can run both RDMA and TCP/IP concurrently on the same port:
33+
34+
~# ./src/valkey-server --protected-mode no \
35+
--loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379 \
36+
--port 6379
37+
38+
Or append 'loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379' in valkey.conf, then:
39+
40+
~# ./src/valkey-server valkey.conf
41+
42+
Note that the network interface (192.168.122.100 of this example) should support
43+
RDMA. To test a server supports RDMA or not:
44+
45+
~# rdma dev show (a new version iproute2 package)
46+
Or:
47+
48+
~# ibv_devices (ibverbs-utils package of Debian/Ubuntu)
49+
50+
51+
## Protocol
52+
53+
The protocol defines the Queue Pairs (QP) type reliable connection (RC),
54+
like TCP, communication commands, and payload exchange mechanism.
55+
This dependency is based solely on the RDMA (aka Infiniband) specification
56+
and is independent of both software (including the OS and user libraries)
57+
and hardware (including vendors and low-level transports).
58+
59+
Valkey Over RDMA has control-plane (control messages) and data-plane (payload transfer).
60+
61+
### Control message
62+
63+
Control messages use fixed 32-byte big-endian message structures:
64+
```C
65+
typedef struct ValkeyRdmaFeature {
66+
/* defined as following Opcodes */
67+
uint16_t opcode;
68+
/* select features */
69+
uint16_t select;
70+
uint8_t reserved[20];
71+
/* feature bits */
72+
uint64_t features;
73+
} ValkeyRdmaFeature;
74+
75+
typedef struct ValkeyRdmaKeepalive {
76+
/* defined as following Opcodes */
77+
uint16_t opcode;
78+
uint8_t reserved[30];
79+
} ValkeyRdmaKeepalive;
80+
81+
typedef struct ValkeyRdmaMemory {
82+
/* defined as following Opcodes */
83+
uint16_t opcode;
84+
uint8_t reserved[14];
85+
/* address of a transfer buffer which is used to receive remote streaming data,
86+
* aka 'RX buffer address'. The remote side should use this as 'TX buffer address' */
87+
uint64_t addr;
88+
/* length of the 'RX buffer' */
89+
uint32_t length;
90+
/* the RDMA remote key of 'RX buffer' */
91+
uint32_t key;
92+
} ValkeyRdmaMemory;
93+
94+
typedef union ValkeyRdmaCmd {
95+
ValkeyRdmaFeature feature;
96+
ValkeyRdmaKeepalive keepalive;
97+
ValkeyRdmaMemory memory;
98+
} ValkeyRdmaCmd;
99+
```
100+
101+
### Opcodes
102+
|Command| Value | Description |
103+
| :----: | :----: | :----: |
104+
| `GetServerFeature` | 0 | required, get the features offered by Valkey server |
105+
| `SetClientFeature` | 1 | required, negotiate features and set it to Valkey server |
106+
| `Keepalive` | 2 | required, detect unexpected orphan connection |
107+
| `RegisterXferMemory` | 3 | required, tell the 'RX transfer buffer' information to the remote side, and the remote side uses this as 'TX transfer buffer' |
108+
109+
Once any new feature and command are introduced into `Valkey Over RDMA`, the client should
110+
detect the new feature `VALKEY_RDMA_FEATURE_FOO` through the `GetServerFeature` command,
111+
and then use the `SetClientFeature` command to enable the feature `VALKEY_RDMA_FEATURE_FOO`.
112+
Once `VALKEY_RDMA_FEATURE_FOO` is negotiated successfully, the optional
113+
`ValkeyRdmaFoo` command will be supported within the connection.
114+
115+
### RDMA Operations
116+
- Send a control message by RDMA '**`ibv_post_send`**' with opcode '**`IBV_WR_SEND`**' with structure
117+
'ValkeyRdmaCmd'.
118+
- Receive a control message by RDMA '**`ibv_post_recv`**', and the received buffer
119+
size should be size of 'ValkeyRdmaCmd'.
120+
- Transfer stream data by RDMA '**`ibv_post_send`**' with opcode '**`IBV_WR_RDMA_WRITE`**' (optional) and
121+
'**`IBV_WR_RDMA_WRITE_WITH_IMM`**' (required), to write data segments into a connection by
122+
RDMA [WRITE][WRITE][WRITE]...[WRITE WITH IMM], the length of total buffer is described by
123+
immediate data (unsigned int 32). For example:
124+
a, [WRITE 128 bytes][WRITE 256 bytes][WRITE 128 bytes WITH IMM 512] writes 512 bytes to the
125+
remote side, the remote side is notified only once.
126+
b, [WRITE 128 bytes WITH IMM 128][WRITE 256 bytes WITH IMM 256][WRITE 128 bytes WITH IMM 128]
127+
writes 512 bytes to the remote side, the remote side is notified three times.
128+
Both example a and b write the same 512 bytes,
129+
example a has better performance, however b is easier to implement.
130+
131+
132+
### Maximum WQEs of RDMA
133+
No specific limit, 1024 recommended for WQEs.
134+
Flow control for WQE MAY be defined/implemented in the future.
135+
136+
137+
### The workflow of this protocol
138+
```
139+
valkey-server
140+
listen RDMA port
141+
valkey-client
142+
-------------------RDMA connect-------------------->
143+
accept connection
144+
<--------------- Establish RDMA --------------------
145+
146+
--------Get server feature [@IBV_WR_SEND] --------->
147+
148+
--------Set client feature [@IBV_WR_SEND] --------->
149+
setup RX buffer
150+
<---- Register transfer memory [@IBV_WR_SEND] ------
151+
[@ibv_post_recv]
152+
setup TX buffer
153+
----- Register transfer memory [@IBV_WR_SEND] ----->
154+
[@ibv_post_recv]
155+
setup TX buffer
156+
-- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] -->
157+
<- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] ---
158+
.......
159+
-- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] -->
160+
<- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] ---
161+
.......
162+
163+
164+
RX is full
165+
----- Register transfer memory [@IBV_WR_SEND] ----->
166+
[@ibv_post_recv]
167+
setup TX buffer
168+
<- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] ---
169+
.......
170+
171+
RX is full
172+
<---- Register transfer memory [@IBV_WR_SEND] ------
173+
[@ibv_post_recv]
174+
setup TX buffer
175+
-- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] -->
176+
<- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] ---
177+
.......
178+
179+
-------------------RDMA disconnect----------------->
180+
<------------------RDMA disconnect------------------
181+
```
182+
183+
The Valkey Over RDMA protocol is designed to efficiently transfer stream data and
184+
bears similarities to several mechanisms introduced in academic papers with some differences:
185+
186+
* [Socksdirect: datacenter sockets can be fast and compatible](https://dl.acm.org/doi/10.1145/3341302.3342071)
187+
* [LITE Kernel RDMA Support for Datacenter Applications](https://dl.acm.org/doi/abs/10.1145/3132747.3132762)
188+
* [FaRM: Fast Remote Memory](https://www.usenix.org/system/files/conference/nsdi14/nsdi14-paper-dragojevic.pdf)
189+
190+
191+
## How does Valkey use RDMA
192+
Valkey supports a connection abstraction framework that hides listen/connect/accept/shutdown/read/write,
193+
and so on. This allows the connection types to register into Valkey core during startup time.
194+
What's more, a connection type is either Valkey built-in (Ex, TCP/IP and Unix domain socket) or
195+
Valkey module (Ex, TLS).
196+
Enabling RDMA support needs to link additional libraries, rather than valkey-server's additional dependence
197+
on the shared libraries, build Valkey Over RDMA into Valkey module,
198+
Then a user starts valkey-server with RDMA module, valkey-server loads the additional shared libraries on demand.
199+
200+
201+
## Limitations
202+
* Valkey Over RDMA is experimental, it may be changed or be removed in any minor or major version.
203+
* TLS is not supported by Valkey Over RDMA. But it is workable in theory by a certain amount of work.
204+
* Valkey Over RDMA is supported on Linux only.
205+
* Not compatible with replication currently, TCP/TLS is needed for replication.
206+
* Depending on different hardwares, too many active QPs may lead performance drop.

topics/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Administration
5050
* [Persistence](persistence.md): Options for configuring durability using disk backups.
5151
* [Administration](admin.md): Various administration topics.
5252
* [Security](security.md): An overview of Valkey's security.
53+
* [RDMA](RDMA.md): An overview of RDMA support.
5354
* [Access Control Lists](acl.md): ACLs make it possible to allow users to run only selected commands and access only specific key patterns.
5455
* [Encryption](encryption.md): How to use TLS for communication.
5556
* [Signals Handling](signals.md): How Valkey handles signals.

wordlist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ ctx
157157
daemonize
158158
daemonized
159159
daemontools
160+
Datacenter
161+
datacenter
160162
dataset
161163
datastore
162164
dbid
@@ -346,6 +348,7 @@ incr
346348
incrby
347349
incrby_get_mget
348350
indexable
351+
Infiniband
349352
ing
350353
init
351354
int_vals
@@ -891,6 +894,7 @@ v[0-9\.]+
891894
Valkey's
892895
Valkey[A-Z].*
893896
Valkey.
897+
valkey-server's
894898
value-ptr
895899
ValueN
896900
Variadic
@@ -915,6 +919,8 @@ wherefrom
915919
whitespace
916920
whitespaces
917921
whos-using-redis
922+
WQE
923+
WQEs
918924
WSL2
919925
xack
920926
xadd

0 commit comments

Comments
 (0)