Skip to content

Commit

Permalink
Add latest_fork_time to INFO STATS
Browse files Browse the repository at this point in the history
Sometimes we want to know the last fork time, this can help
user to analyze the stability since right now fork is still
a costly operation and user can monitor forks by drawing graphs
based on these fork fields.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Sep 2, 2024
1 parent 089048d commit de56240
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,7 @@ void resetServerStats(void) {
server.stat_fork_time = 0;
server.stat_fork_rate = 0;
server.stat_total_forks = 0;
server.stat_last_fork_time = 0;
server.stat_rejected_conn = 0;
server.stat_sync_full = 0;
server.stat_sync_partial_ok = 0;
Expand Down Expand Up @@ -5710,6 +5711,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
"pubsub_patterns:%lu\r\n", dictSize(server.pubsub_patterns),
"pubsubshard_channels:%llu\r\n", kvstoreSize(server.pubsubshard_channels),
"latest_fork_usec:%lld\r\n", server.stat_fork_time,
"latest_fork_time:%lld\r\n", server.stat_last_fork_time,
"total_forks:%lld\r\n", server.stat_total_forks,
"migrate_cached_sockets:%ld\r\n", dictSize(server.migrate_cached_sockets),
"slave_expires_tracked_keys:%zu\r\n", getReplicaKeyWithExpireCount(),
Expand Down Expand Up @@ -6304,6 +6306,7 @@ int serverFork(int purpose) {
server.stat_fork_time = ustime() - start;
server.stat_fork_rate =
(double)zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024 * 1024 * 1024); /* GB per second. */
server.stat_last_fork_time = start;
latencyAddSampleIfNeeded("fork", server.stat_fork_time / 1000);

/* The child_pid and child_type are only for mutually exclusive children.
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,7 @@ struct valkeyServer {
long long stat_aof_rewrites; /* number of aof file rewrites performed */
long long stat_aofrw_consecutive_failures; /* The number of consecutive failures of aofrw */
long long stat_rdb_saves; /* number of rdb saves performed */
long long stat_last_fork_time; /* Last time to start a successful fork(). */
long long stat_fork_time; /* Time needed to perform latest fork() */
double stat_fork_rate; /* Fork rate in GB/sec. */
long long stat_total_forks; /* Total count of fork. */
Expand Down

0 comments on commit de56240

Please sign in to comment.