Skip to content

Commit 0cc0bf7

Browse files
authored
make net_input_bytes_curr_cmd more readable (#1756)
The metric `net_input_bytes_curr_cmd` is now computed by aggregating its components separately. Signed-off-by: zhaozhao.zz <[email protected]>
1 parent f31cf18 commit 0cc0bf7

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/networking.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,30 +2855,30 @@ void processMultibulkBuffer(client *c) {
28552855
*
28562856
* Calculation: For multi bulk buffer, we accumulate four factors, namely;
28572857
*
2858-
* 1) multibulklen_slen + 1
2858+
* 1) multibulklen_slen + 3
28592859
* Cumulative string length (and not the value of) of multibulklen,
2860-
* including +1 from RESP first byte.
2861-
* 2) bulklen_slen + c->argc
2860+
* including the first "*" byte and last "\r\n" 2 bytes from RESP.
2861+
* 2) bulklen_slen + 3
28622862
* Cumulative string length (and not the value of) of bulklen,
2863-
* including +1 from RESP first byte per argument count.
2863+
* including +3 from RESP first "$" byte and last "\r\n" 2 bytes per argument count.
28642864
* 3) c->argv_len_sum
28652865
* Cumulative string length of all argument vectors.
2866-
* 4) c->argc * 4 + 2
2867-
* Cumulative string length of all white-spaces, for which there exists a total of
2868-
* 4 bytes per argument, plus 2 bytes from the leading '\r\n' from multibulklen.
2866+
* 4) c->argc * 2
2867+
* Cumulative string length of the arguments' white-spaces, for which there exists a total of
2868+
* "\r\n" 2 bytes per argument.
28692869
*
28702870
* For example;
28712871
* Command) SET key value
28722872
* RESP) *3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n
28732873
*
2874-
* 1) String length of "*3" is 2, obtained from (multibulklen_slen + 1).
2875-
* 2) String length of "$3" "$3" "$5" is 6, obtained from (bulklen_slen + c->argc).
2874+
* 1) String length of "*3\r\n" is 4, obtained from (multibulklen_slen + 3).
2875+
* 2) String length of "$3\r\n" "$3\r\n" "$5\r\n" is 12, obtained from (bulklen_slen + 3).
28762876
* 3) String length of "SET" "key" "value" is 11, obtained from (c->argv_len_sum).
2877-
* 4) String length of all white-spaces "\r\n" is 14, obtained from (c->argc * 4 + 2).
2877+
* 4) String length of the 3 arguments' white-spaces "\r\n" is 6, obtained from (c->argc * 2).
28782878
*
28792879
* The 1st component is calculated within the below line.
28802880
* */
2881-
c->net_input_bytes_curr_cmd += (multibulklen_slen + 1);
2881+
c->net_input_bytes_curr_cmd += (multibulklen_slen + 3);
28822882
}
28832883

28842884
serverAssertWithInfo(c, NULL, c->multibulklen > 0);
@@ -2943,9 +2943,8 @@ void processMultibulkBuffer(client *c) {
29432943
}
29442944
}
29452945
c->bulklen = ll;
2946-
/* Per-slot network bytes-in calculation, 2nd component.
2947-
* c->argc portion is deferred, as it may not have been fully populated at this point. */
2948-
c->net_input_bytes_curr_cmd += bulklen_slen;
2946+
/* Per-slot network bytes-in calculation, 2nd component. */
2947+
c->net_input_bytes_curr_cmd += (bulklen_slen + 3);
29492948
}
29502949

29512950
/* Read bulk argument */
@@ -2983,9 +2982,8 @@ void processMultibulkBuffer(client *c) {
29832982

29842983
/* We're done when c->multibulk == 0 */
29852984
if (c->multibulklen == 0) {
2986-
/* Per-slot network bytes-in calculation, 3rd and 4th components.
2987-
* Here, the deferred c->argc from 2nd component is added, resulting in c->argc * 5 instead of * 4. */
2988-
c->net_input_bytes_curr_cmd += (c->argv_len_sum + (c->argc * 5 + 2));
2985+
/* Per-slot network bytes-in calculation, 3rd and 4th components. */
2986+
c->net_input_bytes_curr_cmd += (c->argv_len_sum + (c->argc * 2));
29892987
c->read_flags |= READ_FLAGS_PARSING_COMPLETED;
29902988
}
29912989
}

0 commit comments

Comments
 (0)