Commit 838ba44
Reply Copy Avoidance (#2078)
### Overview
This PR introduces the ability to avoid copying the content of string
object into replies (i.e. bulk string replies) and to allow I/O threads
refer directly to obj->ptr in writev iov.
### Key Changes
* Added capability to reply construction allowing to interleave regular
replies with copy avoid replies in client reply buffers
* Extended write-to-client handlers to support copy avoid replies
* Added copy avoidance of string bulk replies when copy avoidance
indicated by I/O threads
* Minor changes in cluster slots stats in order to support
`network-bytes-out` for copy avoid replies
* Copy avoidance is beneficial for performance despite object size only
starting certain number of threads. So it will be enabled only starting
certain number of threads. Internal configuration
``min-io-threads-copy-avoid`` introduced to manage this number of
threads
**Note**: When copy avoidance disabled content and handling of client
reply buffers remains as before this PR
### Implementation Details
#### ``client`` and ``clientReplyBlock`` structs:
1. ``buf_encoded`` flag has been added to ``clientReplyBlock`` struct
and to ``client`` struct for static ``c->buf`` to indicate if reply
buffer is in copy avoidance mode (i.e. include headers and payloads) or
not (i.e. plain replies only).
2. ``io_last_written_buf``, ``io_last_written_bufpos``,
``io_last_written_data_len`` fields added ``client`` struct to to keep
track of write state between ``writevToClient`` invocations
#### Reply construction:
1. Original ```_addReplyToBuffer``` and ```_addReplyProtoToList``` have
been renamed to ```_addReplyPayloadToBuffer``` and
```_addReplyPayloadToList``` and extended to support different types of
payloads - regular replies and copy avoid replies.
3. New ```_addReplyToBuffer``` and ```_addReplyProtoToList``` calls now
```_addReplyPayloadToBuffer``` and ```_addReplyPayloadToList``` and used
for adding **regular** replies to client reply buffers.
4. Newly introduced ```_addBulkOffloadToBuffer``` and
```_addBulkOffloadToList``` are used for adding **copy avoid** replies
to client reply buffers.
#### Write-to-client infrastructure:
The ```writevToClient``` and ```_postWriteToClient``` has been
significantly changed to support copy avoidance capability.
#### Debug configuration:
1. ``min-io-threads-avoid-copy-reply`` - Minimum number of IO threads
for copy avoidance
2. ``min-string-size-avoid-copy-reply`` - Minimum bulk string size for
copy avoidance when IO threads disabled
3. ``min-string-size-avoid-copy-reply-threaded`` - Minimum bulk string
size for copy avoidance when IO threads enabled
### Testing
1. Existing unit and integration tests passed. Copy avoidance enabled on
tests with ``--io-threads`` flag
2. Added unit tests for copy avoidance functionality
### Performance Tests
Note: pay attention `io-threads 1` config means only main thread with no
additional io-threads, `io-threads 2` means main thread plus 1 I/O
thread, `io-threads 9` means main thread plus 8 I/O threads.
#### 512 byte object size
Tests are conducted on memory optimized instances using:
* 3,000,000 keys
* 512 bytes object size
* 1000 clients
|io-threads (including main thread) |Plain Reply |Copy Avoidance |
|--- |--- |--- |
|7 |1,160,000 |1,160,000 |
|8 |1,150,000 |1,280,000 |
|9 |1,150,000 |1,330,000 |
|10 |N/A |1,380,000 |
|11 |N/A |1,420,000 |
#### Various object size, small number of threads
|iothreads |Data size |Keys |Clients |Instance type |Unstable branch
|Copy Avoidance On |
|--- |--- |--- |--- |--- |--- |--- |
|1 |512 byte |3,000,000 |1,000 |memory optimized |195,000 |195,000 |
|2 |512 byte |3,000,000 |1,000 |memory optimized |245,000 |245,000 |
|3 |512 byte |3,000,000 |1,000 |memory optimized |455,000 |459,000 |
|4 |512 byte |3,000,000 |1,000 |memory optimized |685,000 |685,000 |
| | | | | | | |
|1 |1K |3,000,000 |1,000 |memory optimized |185,000 |185,000 |
|2 |1K |3,000,000 |1,000 |memory optimized |235,000 |235,000 |
|3 |1K |3,000,000 |1,000 |memory optimized |450,000 |450,000 |
| | | | | | | |
|1 |4K |1,000,000 |1,000 |network optimized |182,000 |187,000 |
|2 |4K |1,000,000 |1,000 |network optimized |240,000 |238,000 |
| | | | | | | |
|1 |16K |1,000,000 |500 |network optimized |100,000 |120,000 |
|2 |16K |1,000,000 |500 |network optimized |140,000 |140,000 |
|3 |16K |1,000,000 |500 |network optimized |275,000 |260,000 |
| | | | | | | |
|1 |32K |500,000 |500 |network optimized |57,000 |90,000 |
|2 |32K |500,000 |500 |network optimized |110,000 |110,000 |
|3 |32K |500,000 |500 |network optimized |215,000 |215,000 |
| | | | | | | |
|1 |64K |100,000 |500 |network optimized |30,000 |57,000 |
|2 |64K |100,000 |500 |network optimized |69,000 |61,000 |
|3 |64K |100,000 |500 |network optimized |120,000 |120,000 |
|4 |64K |100,000 |500 |network optimized |115,000 - 175,000 |175,000 |
|5 |64K |100,000 |500 |network optimized |115,000 - 165,000 |230,000 |
---------
Signed-off-by: Alexander Shabanov <[email protected]>
Signed-off-by: xbasel <[email protected]>
Signed-off-by: Madelyn Olson <[email protected]>
Co-authored-by: Alexander Shabanov <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]>1 parent 988297d commit 838ba44
File tree
23 files changed
+912
-142
lines changed- src
- unit
- tests
- integration
- support
- unit
- cluster
23 files changed
+912
-142
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
139 | 143 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 181 | + | |
190 | 182 | | |
191 | | - | |
192 | | - | |
| 183 | + | |
| 184 | + | |
193 | 185 | | |
194 | 186 | | |
195 | 187 | | |
196 | 188 | | |
197 | | - | |
198 | 189 | | |
199 | 190 | | |
200 | 191 | | |
| |||
222 | 213 | | |
223 | 214 | | |
224 | 215 | | |
225 | | - | |
226 | | - | |
227 | | - | |
| 216 | + | |
228 | 217 | | |
229 | 218 | | |
230 | 219 | | |
| |||
251 | 240 | | |
252 | 241 | | |
253 | 242 | | |
254 | | - | |
255 | | - | |
| 243 | + | |
256 | 244 | | |
257 | 245 | | |
258 | 246 | | |
| |||
346 | 334 | | |
347 | 335 | | |
348 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3262 | 3262 | | |
3263 | 3263 | | |
3264 | 3264 | | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
3265 | 3268 | | |
3266 | 3269 | | |
3267 | 3270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
451 | 454 | | |
452 | 455 | | |
| 456 | + | |
| 457 | + | |
453 | 458 | | |
454 | 459 | | |
455 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
| |||
0 commit comments