-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce commandlog heavytraffic
to record big response packet.
#336
Changes from all commits
6548769
e4eb38b
b273214
a3ee175
e1ab7d9
e928f27
a791ac0
204dfba
55f1a52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"GET": { | ||
"summary": "Returns the fat log's entries.", | ||
"complexity": "O(N) where N is the number of entries returned", | ||
"group": "server", | ||
"since": "8.0.0", | ||
"arity": -2, | ||
"container": "FATLOG", | ||
"function": "slowlogCommand", | ||
"history": [], | ||
"command_flags": [ | ||
"ADMIN", | ||
"LOADING", | ||
"STALE" | ||
], | ||
"command_tips": [ | ||
"REQUEST_POLICY:ALL_NODES", | ||
"NONDETERMINISTIC_OUTPUT" | ||
], | ||
"reply_schema": { | ||
"type": "array", | ||
"description": "Entries from the slow log in chronological order.", | ||
"uniqueItems": true, | ||
"items": { | ||
"type": "array", | ||
"minItems": 6, | ||
"maxItems": 6, | ||
"items": [ | ||
{ | ||
"type": "integer", | ||
"description": "Fat log entry ID." | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "The unix timestamp at which the logged command was processed.", | ||
"minimum": 0 | ||
}, | ||
{ | ||
"type": "integer", | ||
"description": "The size of the response to the query in bytes.", | ||
"minimum": 0 | ||
}, | ||
{ | ||
"type": "array", | ||
"description": "The arguments of the command.", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "Client IP address and port." | ||
}, | ||
{ | ||
"type": "string", | ||
"description": "Client name if set via the CLIENT SETNAME command." | ||
} | ||
] | ||
} | ||
}, | ||
"arguments": [ | ||
{ | ||
"name": "count", | ||
"type": "integer", | ||
"optional": true | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"HELP": { | ||
"summary": "Returns helpful text about the different subcommands", | ||
"complexity": "O(1)", | ||
"group": "server", | ||
"since": "8.0.0", | ||
"arity": 2, | ||
"container": "FATLOG", | ||
"function": "slowlogCommand", | ||
"command_flags": [ | ||
"LOADING", | ||
"STALE" | ||
], | ||
"reply_schema": { | ||
"type": "array", | ||
"description": "Helpful text about subcommands.", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"LEN": { | ||
"summary": "Returns the number of entries in the fat log.", | ||
"complexity": "O(1)", | ||
"group": "server", | ||
"since": "8.0.0", | ||
"arity": 2, | ||
"container": "FATLOG", | ||
"function": "slowlogCommand", | ||
"command_flags": [ | ||
"ADMIN", | ||
"LOADING", | ||
"STALE" | ||
], | ||
"command_tips": [ | ||
"REQUEST_POLICY:ALL_NODES", | ||
"RESPONSE_POLICY:AGG_SUM", | ||
"NONDETERMINISTIC_OUTPUT" | ||
], | ||
"reply_schema": { | ||
"type": "integer", | ||
"description": "Number of entries in the fat log.", | ||
"minimum": 0 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"RESET": { | ||
"summary": "Clears all entries from the fat log.", | ||
"complexity": "O(N) where N is the number of entries in the fatlog", | ||
"group": "server", | ||
"since": "8.0.0", | ||
"arity": 2, | ||
"container": "FATLOG", | ||
"function": "slowlogCommand", | ||
"command_flags": [ | ||
"ADMIN", | ||
"LOADING", | ||
"STALE" | ||
], | ||
"command_tips": [ | ||
"REQUEST_POLICY:ALL_NODES", | ||
"RESPONSE_POLICY:ALL_SUCCEEDED" | ||
], | ||
"reply_schema": { | ||
"const": "OK" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"FATLOG": { | ||
"summary": "A container for fat log commands.", | ||
"complexity": "Depends on subcommand.", | ||
"group": "server", | ||
"since": "8.0.0", | ||
"arity": -2 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3173,6 +3173,7 @@ standardConfig static_configs[] = { | |
createULongConfig("active-defrag-max-scan-fields", NULL, MODIFIABLE_CONFIG, 1, LONG_MAX, server.active_defrag_max_scan_fields, 1000, INTEGER_CONFIG, NULL, NULL), /* Default: keys with more than 1000 fields will be processed separately */ | ||
createULongConfig("slowlog-max-len", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.slowlog_max_len, 128, INTEGER_CONFIG, NULL, NULL), | ||
createULongConfig("acllog-max-len", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.acllog_max_len, 128, INTEGER_CONFIG, NULL, NULL), | ||
createULongConfig("fatlog-max-len", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.fatlog_max_len, 128, INTEGER_CONFIG, NULL, NULL), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add these 2 new config parameter in valkey.conf and describe details, pls reference the Slow Log section. |
||
|
||
/* Long Long configs */ | ||
createLongLongConfig("busy-reply-threshold", "lua-time-limit", MODIFIABLE_CONFIG, 0, LONG_MAX, server.busy_reply_threshold, 5000, INTEGER_CONFIG, NULL, NULL), /* milliseconds */ | ||
|
@@ -3183,6 +3184,7 @@ standardConfig static_configs[] = { | |
createLongLongConfig("proto-max-bulk-len", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, 1024 * 1024, LONG_MAX, server.proto_max_bulk_len, 512ll * 1024 * 1024, MEMORY_CONFIG, NULL, NULL), /* Bulk request max size */ | ||
createLongLongConfig("stream-node-max-entries", NULL, MODIFIABLE_CONFIG, 0, LLONG_MAX, server.stream_node_max_entries, 100, INTEGER_CONFIG, NULL, NULL), | ||
createLongLongConfig("repl-backlog-size", NULL, MODIFIABLE_CONFIG, 1, LLONG_MAX, server.repl_backlog_size, 1024 * 1024, MEMORY_CONFIG, NULL, updateReplBacklogSize), /* Default: 1mb */ | ||
createLongLongConfig("fatlog-log-bigger-than", NULL, MODIFIABLE_CONFIG, -1, LLONG_MAX, server.fatlog_log_bigger_than, 1024 * 1024, MEMORY_CONFIG, NULL, NULL), | ||
|
||
/* Unsigned Long Long configs */ | ||
createULongLongConfig("maxmemory", NULL, MODIFIABLE_CONFIG, 0, ULLONG_MAX, server.maxmemory, 0, MEMORY_CONFIG, NULL, updateMaxmemory), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,7 @@ client *createClient(connection *conn) { | |
c->qb_pos = 0; | ||
c->querybuf = NULL; | ||
c->querybuf_peak = 0; | ||
c->cmd_query_length = 0; | ||
c->reqtype = 0; | ||
c->argc = 0; | ||
c->argv = NULL; | ||
|
@@ -186,6 +187,7 @@ client *createClient(connection *conn) { | |
c->reply = listCreate(); | ||
c->deferred_reply_errors = NULL; | ||
c->reply_bytes = 0; | ||
c->cmd_reply_length = 0; | ||
c->obuf_soft_limit_reached_time = 0; | ||
listSetFreeMethod(c->reply, freeClientReplyValue); | ||
listSetDupMethod(c->reply, dupClientReplyValue); | ||
|
@@ -442,6 +444,9 @@ void _addReplyToBufferOrList(client *c, const char *s, size_t len) { | |
* buffer offset (see function comment) */ | ||
reqresSaveClientReplyOffset(c); | ||
|
||
/* Record reply length. */ | ||
c->cmd_reply_length += len; | ||
|
||
/* If we're processing a push message into the current client (i.e. executing PUBLISH | ||
* to a channel which we are subscribed to, then we wanna postpone that message to be added | ||
* after the command's reply (specifically important during multi-exec). the exception is | ||
|
@@ -794,6 +799,9 @@ void setDeferredReply(client *c, void *node, const char *s, size_t length) { | |
if (node == NULL) return; | ||
serverAssert(!listNodeValue(ln)); | ||
|
||
/* Record reply length. */ | ||
c->cmd_reply_length += length; | ||
|
||
/* Normally we fill this dummy NULL node, added by addReplyDeferredLen(), | ||
* with a new buffer structure containing the protocol needed to specify | ||
* the length of the array following. However sometimes there might be room | ||
|
@@ -2081,6 +2089,7 @@ void resetClient(client *c) { | |
serverCommandProc *prevcmd = c->cmd ? c->cmd->proc : NULL; | ||
|
||
freeClientArgv(c); | ||
c->cmd_query_length = 0; | ||
c->cur_script = NULL; | ||
c->reqtype = 0; | ||
c->multibulklen = 0; | ||
|
@@ -2253,6 +2262,9 @@ int processInlineBuffer(client *c) { | |
/* Move querybuffer position to the next query in the buffer. */ | ||
c->qb_pos += querylen + linefeed_chars; | ||
|
||
/* Record query length for fatlog. */ | ||
c->cmd_query_length = querylen; | ||
|
||
/* Setup argv array on client structure */ | ||
if (argc) { | ||
if (c->argv) zfree(c->argv); | ||
|
@@ -2321,6 +2333,8 @@ int processMultibulkBuffer(client *c) { | |
int ok; | ||
long long ll; | ||
|
||
size_t qb_pos_start = c->qb_pos; | ||
|
||
if (c->multibulklen == 0) { | ||
/* The client should have been reset */ | ||
serverAssertWithInfo(c, NULL, c->argc == 0); | ||
|
@@ -2465,6 +2479,9 @@ int processMultibulkBuffer(client *c) { | |
} | ||
} | ||
|
||
/* Record query length for fatlog. */ | ||
c->cmd_query_length += c->qb_pos - qb_pos_start; | ||
Comment on lines
+2482
to
+2483
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing this commit. The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During the latest core meeting (July 15th 2024), we concluded to move forward with the currently upheld @CharlesChen888 |
||
|
||
/* We're done when c->multibulk == 0 */ | ||
if (c->multibulklen == 0) return C_OK; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I understand the rational behind a new command, a fat command is logically different from a slow command, I would also like us to more seriously consider just adding one new field to the slowlog, the output/input bytes, and then having both get logged to the same place. It's not a perfect fit, but then users can just look in "one" place for bad behavior. It also allows the two logs to perhaps explain each other, since a large output can cause a slow command. We could extend
SLOWLOG GET [count] [TYPE FAT|SLOW]
to only show entries of the specific type.I'm thinking about it more from a simpler way to explain it to end users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does make things easier than adding a new series of commands, if we can ignore that changes in format of command reply may cause backwards compatibility problem.
But a big packet in query or response does not necessarily mean it will be slow. I'm not sure if we should do this.