Skip to content

Commit b083aa9

Browse files
Included Client Side Caching docs with examples (#32)
* Included CSC docs with examples * Added more context for CSC invalidation
1 parent c05af62 commit b083aa9

File tree

1 file changed

+103
-1
lines changed

1 file changed

+103
-1
lines changed

README.md

+103-1
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,106 @@ Throughput summary: 274843 requests per second
181181
Latency summary (msec):
182182
p50 p95 p99
183183
0.162 0.372 0.460
184-
```
184+
```
185+
186+
# Client side Caching benchmark
187+
188+
Client side caching was introduced in [version v1.0.0](https://github.com/redis-performance/redis-benchmark-go/releases/tag/v1.0.0) of this tool and requires the usage of the rueidis vanilla client.
189+
This means that for using CSC you need to use a minimum of 2 extra flags on your benchmark, namely `-rueidis -csc`.
190+
191+
Bellow you can find all flags that control CSC behaviour:
192+
193+
```
194+
-csc
195+
Enable client side caching
196+
-csc-per-client-bytes int
197+
client side cache size that bind to each TCP connection to a single redis instance (default 134217728)
198+
-csc-ttl duration
199+
Client side cache ttl for cached entries (default 1m0s)
200+
-rueidis
201+
Use rueidis as the vanilla underlying client.
202+
```
203+
204+
If you take the following benchmark command
205+
```
206+
$ ./redis-benchmark-go -rueidis -csc -n 2 -r 1 -c 1 -p 6379 GET key
207+
```
208+
209+
210+
The above example will send the following command to redis in case of cache miss:
211+
212+
```
213+
// CLIENT CACHING YES
214+
// MULTI
215+
// PTTL k
216+
// GET k
217+
// EXEC
218+
```
219+
If the key's TTL on the server is smaller than the client side TTL, the client side TTL will be capped.
220+
221+
On the second command execution for the same client, the command won't be issued to the server as visible bellow on the CSC Hits/sec column.
222+
223+
224+
```
225+
$ ./redis-benchmark-go -rueidis -csc -n 2 -r 1 -c 1 -p 6379 GET key
226+
IPs [127.0.0.1]
227+
Total clients: 1. Commands per client: 2 Total commands: 2
228+
Using random seed: 12345
229+
Test time Total Commands Total Errors Command Rate CSC Hits/sec CSC Invalidations/sec p50 lat. (msec)
230+
0s [100.0%] 2 0 [0.0%] 2 1 0 0.002
231+
#################################################
232+
Total Duration 0.000 Seconds
233+
Total Errors 0
234+
Throughput summary: 19218 requests per second
235+
9609 CSC Hits per second
236+
0 CSC Evicts per second
237+
Latency summary (msec):
238+
avg p50 p95 p99
239+
0.379 0.002 0.756 0.756
240+
241+
```
242+
243+
and as visible by the following server side monitoring during the above benchmark.
244+
245+
```
246+
$ redis-cli monitor
247+
OK
248+
1695911011.777347 [0 127.0.0.1:56574] "HELLO" "3"
249+
1695911011.777366 [0 127.0.0.1:56574] "CLIENT" "TRACKING" "ON" "OPTIN"
250+
1695911011.777738 [0 127.0.0.1:56574] "CLIENT" "CACHING" "YES"
251+
1695911011.777748 [0 127.0.0.1:56574] "MULTI"
252+
1695911011.777759 [0 127.0.0.1:56574] "PTTL" "key"
253+
1695911011.777768 [0 127.0.0.1:56574] "GET" "key"
254+
1695911011.777772 [0 127.0.0.1:56574] "EXEC"
255+
```
256+
257+
## CSC invalidations
258+
259+
When a key is modified by some client, or is evicted because it has an associated expire time,
260+
or evicted because of a maxmemory policy, all the clients with tracking enabled that may have the key cached,
261+
are notified with an invalidation message.
262+
263+
This can represent a large amount of invalidation messages per second going through redis in each second.
264+
On the sample benchmark bellow, with 50 clients, doing 5% WRITES and 95% READS on a keyspace length of 10000 Keys,
265+
we've observed more than 50K invalidation messages per second and only 20K CSC Hits per second even on this read-heavy scenario.
266+
267+
The goal of this CSC measurement capacibility is to precisely help you understand the do's and dont's on CSC and when it's best to use or avoid it.
268+
269+
```
270+
$ ./redis-benchmark-go -p 6379 -rueidis -r 10000 -csc -cmd "SET __key__ __data__" -cmd-ratio 0.05 -cmd "GET __key__" -cmd-ratio 0.95 --json-out-file results.json
271+
IPs [127.0.0.1]
272+
Total clients: 50. Commands per client: 200000 Total commands: 10000000
273+
Using random seed: 12345
274+
Test time Total Commands Total Errors Command Rate CSC Hits/sec CSC Invalidations/sec p50 lat. (msec)
275+
125s [100.0%] 10000000 0 [0.0%] 25931 9842 16777 0.611
276+
#################################################
277+
Total Duration 125.002 Seconds
278+
Total Errors 0
279+
Throughput summary: 79999 requests per second
280+
20651 CSC Hits per second
281+
54272 CSC Evicts per second
282+
Latency summary (msec):
283+
avg p50 p95 p99
284+
0.620 0.611 1.461 2.011
285+
2023/09/28 15:36:13 Saving JSON results file to results.json
286+
```

0 commit comments

Comments
 (0)