|
| 1 | +--- |
| 2 | +title: "RDMA support" |
| 3 | +linkTitle: "RDMA support" |
| 4 | +description: Valkey Over RDMA support |
| 5 | +--- |
| 6 | + |
| 7 | +Valkey supports the RDMA connection type as a module that requires compilation |
| 8 | +as a shared library and dynamic loading on demand. |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +RDMA stands for Remote Direct Memory Access. It is a technology that allows computers in |
| 13 | +a network to exchange data directly in the main memory, bypassing the involvement of processors, |
| 14 | +caches, or operating systems on either computer. |
| 15 | +As a result, RDMA offers better performance compared to TCP. Test results indicate that |
| 16 | +Valkey Over RDMA achieves approximately 2 times higher QPS and lower latency. |
| 17 | + |
| 18 | +Please note that Valkey Over RDMA is currently supported only on Linux. |
| 19 | + |
| 20 | +## Running manually |
| 21 | + |
| 22 | +To manually run a Valkey server with RDMA mode: |
| 23 | + |
| 24 | + ./src/valkey-server --protected-mode no \ |
| 25 | + --loadmodule src/valkey-rdma.so bind=192.168.122.100 port=6379 |
| 26 | + |
| 27 | +It's possible to change bind address/port of RDMA by runtime command: |
| 28 | + |
| 29 | + 192.168.122.100:6379> CONFIG SET rdma-port 6380 |
| 30 | + |
| 31 | +It's also possible to have both RDMA and TCP available, and there is no |
| 32 | +conflict of TCP (6379) and RDMA (6379). Example: |
| 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 | +Note that the network interface (192.168.122.100 of this example) should support |
| 39 | +RDMA. To test a server supports RDMA or not: |
| 40 | + |
| 41 | + ~# rdma dev show (a new version iproute2 package) |
| 42 | +Or: |
| 43 | + |
| 44 | + ~# ibv_devices (ibverbs-utils package of Debian/Ubuntu) |
| 45 | + |
| 46 | + |
| 47 | +## Protocol |
| 48 | + |
| 49 | +Note that the protocol part defines the QP type RC (like TCP), |
| 50 | +communication commands, and payload exchange mechanism. |
| 51 | +This dependency is based solely on the RDMA (aka Infiniband) specification |
| 52 | +and is independent of both software (including the OS and user libraries) |
| 53 | +and hardware (including vendors and low-level transports). |
| 54 | + |
| 55 | +The Valkey Over RDMA protocol separates into control-plane |
| 56 | +(to exchange control message) and data-plane (to transfer the real payload for Valkey). |
| 57 | + |
| 58 | +### Control message |
| 59 | + |
| 60 | +For control message, use a fixed 32 bytes message which defines structures: |
| 61 | +```C |
| 62 | +typedef struct ValkeyRdmaFeature { |
| 63 | + /* defined as following Opcodes */ |
| 64 | + uint16_t opcode; |
| 65 | + /* select features */ |
| 66 | + uint16_t select; |
| 67 | + uint8_t rsvd[20]; |
| 68 | + /* feature bits */ |
| 69 | + uint64_t features; |
| 70 | +} ValkeyRdmaFeature; |
| 71 | + |
| 72 | +typedef struct ValkeyRdmaKeepalive { |
| 73 | + /* defined as following Opcodes */ |
| 74 | + uint16_t opcode; |
| 75 | + uint8_t rsvd[30]; |
| 76 | +} ValkeyRdmaKeepalive; |
| 77 | + |
| 78 | +typedef struct ValkeyRdmaMemory { |
| 79 | + /* defined as following Opcodes */ |
| 80 | + uint16_t opcode; |
| 81 | + uint8_t rsvd[14]; |
| 82 | + /* address of a transfer buffer which is used to receive remote streaming data, |
| 83 | + * aka 'RX buffer address'. The remote side should use this as 'TX buffer address' */ |
| 84 | + uint64_t addr; |
| 85 | + /* length of the 'RX buffer' */ |
| 86 | + uint32_t length; |
| 87 | + /* the RDMA remote key of 'RX buffer' */ |
| 88 | + uint32_t key; |
| 89 | +} ValkeyRdmaMemory; |
| 90 | + |
| 91 | +typedef union ValkeyRdmaCmd { |
| 92 | + ValkeyRdmaFeature feature; |
| 93 | + ValkeyRdmaKeepalive keepalive; |
| 94 | + ValkeyRdmaMemory memory; |
| 95 | +} ValkeyRdmaCmd; |
| 96 | +``` |
| 97 | + |
| 98 | +### Opcodes |
| 99 | +|Command| Value | Description | |
| 100 | +| :----: | :----: | :----: | |
| 101 | +| `GetServerFeature` | 0 | required, get the features offered by Valkey server | |
| 102 | +| `SetClientFeature` | 1 | required, negotiate features and set it to Valkey server | |
| 103 | +| `Keepalive` | 2 | required, detect unexpected orphan connection | |
| 104 | +| `RegisterXferMemory` | 3 | required, tell the 'RX transfer buffer' information to the remote side, and the remote side uses this as 'TX transfer buffer' | |
| 105 | + |
| 106 | +### Operations of RDMA |
| 107 | +- To send a control message by RDMA '**`ibv_post_send`**' with opcode '**`IBV_WR_SEND`**' with structure |
| 108 | + 'ValkeyRdmaCmd'. |
| 109 | +- To receive a control message by RDMA '**`ibv_post_recv`**', and the received buffer |
| 110 | + size should be size of 'ValkeyRdmaCmd'. |
| 111 | +- To transfer stream data by RDMA '**`ibv_post_send`**' with opcode '**`IBV_WR_RDMA_WRITE`**' (optional) and |
| 112 | + '**`IBV_WR_RDMA_WRITE_WITH_IMM`**' (required), to write data segments into a connection by |
| 113 | + RDMA [WRITE][WRITE][WRITE]...[WRITE WITH IMM], the length of total buffer is described by |
| 114 | + immediate data (unsigned int 32). |
| 115 | + |
| 116 | + |
| 117 | +### Maximum WQEs of RDMA |
| 118 | +Currently no specific restriction is defined in this protocol. Recommended WQEs is 1024. |
| 119 | +Flow control for WQE MAY be defined/implemented in the future. |
| 120 | + |
| 121 | + |
| 122 | +### The workflow of this protocol |
| 123 | +``` |
| 124 | + valkey-server |
| 125 | + listen RDMA port |
| 126 | + valkey-client |
| 127 | + -------------------RDMA connect--------------------> |
| 128 | + accept connection |
| 129 | + <--------------- Establish RDMA -------------------- |
| 130 | +
|
| 131 | + --------Get server feature [@IBV_WR_SEND] ---------> |
| 132 | +
|
| 133 | + --------Set client feature [@IBV_WR_SEND] ---------> |
| 134 | + setup RX buffer |
| 135 | + <---- Register transfer memory [@IBV_WR_SEND] ------ |
| 136 | +[@ibv_post_recv] |
| 137 | +setup TX buffer |
| 138 | + ----- Register transfer memory [@IBV_WR_SEND] -----> |
| 139 | + [@ibv_post_recv] |
| 140 | + setup TX buffer |
| 141 | + -- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] --> |
| 142 | + <- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] --- |
| 143 | + ....... |
| 144 | + -- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] --> |
| 145 | + <- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] --- |
| 146 | + ....... |
| 147 | +
|
| 148 | +
|
| 149 | +RX is full |
| 150 | + ----- Register transfer memory [@IBV_WR_SEND] -----> |
| 151 | + [@ibv_post_recv] |
| 152 | + setup TX buffer |
| 153 | + <- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] --- |
| 154 | + ....... |
| 155 | +
|
| 156 | + RX is full |
| 157 | + <---- Register transfer memory [@IBV_WR_SEND] ------ |
| 158 | +[@ibv_post_recv] |
| 159 | +setup TX buffer |
| 160 | + -- Valkey commands [@IBV_WR_RDMA_WRITE_WITH_IMM] --> |
| 161 | + <- Valkey response [@IBV_WR_RDMA_WRITE_WITH_IMM] --- |
| 162 | + ....... |
| 163 | +
|
| 164 | + -------------------RDMA disconnect-----------------> |
| 165 | + <------------------RDMA disconnect------------------ |
| 166 | +``` |
| 167 | + |
| 168 | +The Valkey Over RDMA protocol is designed to efficiently transfer stream data and |
| 169 | +bears similarities to several mechanisms introduced in academic papers, albeit with some differences: |
| 170 | + |
| 171 | +* [Socksdirect: datacenter sockets can be fast and compatible](https://dl.acm.org/doi/10.1145/3341302.3342071) |
| 172 | +* [LITE Kernel RDMA Support for Datacenter Applications](https://dl.acm.org/doi/abs/10.1145/3132747.3132762) |
| 173 | +* [FaRM: Fast Remote Memory](https://www.usenix.org/system/files/conference/nsdi14/nsdi14-paper-dragojevic.pdf) |
0 commit comments