Skip to content

Commit 86e487f

Browse files
enjoy-binbinzuiderkwast
authored andcommitted
Fix client tracking memory overhead calculation (#2360)
This should be + instread of *, otherwise it does not make any sense. Otherwise we would have to calculate 20 more bytes for each prefix rax node in 64 bits build. Signed-off-by: Binbin <[email protected]>
1 parent 070f008 commit 86e487f

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

src/networking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4642,7 +4642,7 @@ size_t getClientMemoryUsage(client *c, size_t *output_buffer_mem_usage) {
46424642
/* Add memory overhead of the tracking prefixes, this is an underestimation so we don't need to traverse the entire
46434643
* rax */
46444644
if (c->pubsub_data && c->pubsub_data->client_tracking_prefixes)
4645-
mem += c->pubsub_data->client_tracking_prefixes->numnodes * (sizeof(raxNode) * sizeof(raxNode *));
4645+
mem += c->pubsub_data->client_tracking_prefixes->numnodes * (sizeof(raxNode) + sizeof(raxNode *));
46464646

46474647
return mem;
46484648
}

tests/test_helper.tcl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,30 @@ proc CI {index field} {
264264
getInfoProperty [R $index cluster info] $field
265265
}
266266

267+
# Provide easy access to CLIENT INFO properties from CLIENT INFO string.
268+
proc get_field_in_client_info {info field} {
269+
set info [string trim $info]
270+
foreach item [split $info " "] {
271+
set kv [split $item "="]
272+
set k [lindex $kv 0]
273+
if {[string match $field $k]} {
274+
return [lindex $kv 1]
275+
}
276+
}
277+
return ""
278+
}
279+
280+
# Provide easy access to CLIENT INFO properties from CLIENT LIST string.
281+
proc get_field_in_client_list {id client_list filed} {
282+
set list [split $client_list "\r\n"]
283+
foreach info $list {
284+
if {[string match "id=$id *" $info] } {
285+
return [get_field_in_client_info $info $filed]
286+
}
287+
}
288+
return ""
289+
}
290+
267291
# Test wrapped into run_solo are sent back from the client to the
268292
# test server, so that the test server will send them again to
269293
# clients once the clients are idle.

tests/unit/introspection.tcl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,6 @@ start_server {tags {"introspection"}} {
139139
assert_error "ERR *greater than 0*" {r client list maxage -1}
140140
}
141141

142-
proc get_field_in_client_info {info field} {
143-
set info [string trim $info]
144-
foreach item [split $info " "] {
145-
set kv [split $item "="]
146-
set k [lindex $kv 0]
147-
if {[string match $field $k]} {
148-
return [lindex $kv 1]
149-
}
150-
}
151-
return ""
152-
}
153-
154-
proc get_field_in_client_list {id client_list filed} {
155-
set list [split $client_list "\r\n"]
156-
foreach info $list {
157-
if {[string match "id=$id *" $info] } {
158-
return [get_field_in_client_info $info $filed]
159-
}
160-
}
161-
return ""
162-
}
163-
164142
proc get_client_tot_in_out_cmds {id} {
165143
set info_list [r client list]
166144
set in [get_field_in_client_list $id $info_list "tot-net-in"]

tests/unit/tracking.tcl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ start_server {tags {"tracking network logreqres:skip"}} {
3838
}
3939
}
4040

41+
test {Client tracking prefixes memory overhead} {
42+
r CLIENT TRACKING off
43+
set tot_mem_before [get_field_in_client_info [r client info] "tot-mem"]
44+
45+
# We add multiple $i to prefix to avoid prefix conflicts, so in this
46+
# args we will have about 20000 rax nodes.
47+
set args {}
48+
for {set i 0} {$i < 10240} {incr i} {
49+
lappend args PREFIX
50+
lappend args PREFIX-$i-$i-$i-$i-$i-$i-$i
51+
}
52+
r CLIENT TRACKING on BCAST {*}$args
53+
54+
set arch_bits [s arch_bits]
55+
set tot_mem_after [get_field_in_client_info [r client info] "tot-mem"]
56+
set diff [expr $tot_mem_after - $tot_mem_before]
57+
58+
# In 64 bits, before we would consume about 20000 * (4 * 8), that is 640000.
59+
# And now we are 20000 * (4 + 8), that is 240000.
60+
if {$arch_bits == 64} {
61+
assert_lessthan $diff 300000
62+
} elseif {$arch_bits == 32} {
63+
assert_lessthan $diff 200000
64+
}
65+
66+
r CLIENT TRACKING off
67+
}
68+
4169
test {Clients are able to enable tracking and redirect it} {
4270
r CLIENT TRACKING on REDIRECT $redir_id
4371
} {*OK}

0 commit comments

Comments
 (0)