Skip to content

Adds isolated netstats for replication.#10062

Merged
oranagra merged 10 commits intoredis:unstablefrom
DarrenJiang13:separate-repl-netstats
May 31, 2022
Merged

Adds isolated netstats for replication.#10062
oranagra merged 10 commits intoredis:unstablefrom
DarrenJiang13:separate-repl-netstats

Conversation

@DarrenJiang13
Copy link
Contributor

@DarrenJiang13 DarrenJiang13 commented Jan 6, 2022

Hi guys,

I find that the amount of server.stat_net_output_bytes/server.stat_net_input_bytes is actually the sum of replication flow and users' data flow.
It may cause confusions like this, "Why does my server get such a large output_bytes while I am doing nothing? ".

After discussions and revisions, now here is the change about what this PR brings (final version before merge):

  • 2 server variables to count the network bytes during replication, including fullsync and propagate bytes.
    • server.stat_net_repl_output_bytes/server.stat_net_repl_input_bytes
  • 3 info fields to print the input and output of repl bytes and instantaneous value of total repl bytes.
    • total_net_repl_input_bytes / total_net_repl_output_bytes
    • instantaneous_repl_total_kbps
  • 1 new API rioCheckType() to check the type of rio. So we can use this to distinguish between diskless and diskbased replication
  • 2 new counting items to keep network statistics consistent between master and slave
    • rdb portion during diskless replica. in rdbLoadProgressCallback()
    • first line of the full sync payload. in readSyncBulkPayload()

Here is the result

Steps

  1. start a new master node 30001
  2. using redis-benchmark to write to 30001
    ./src/redis-benchmark -t set -r 10000000 -d 1 -n 100000000 -p 30001
  3. after a while, start a new slave node 30002, run slaveof 127.0.0.1 30001
  4. run info stats to check the flow count of the master and slave

Result

  • for disk-based replication

    • master
    # Stats
    total_net_input_bytes:21534385
    total_net_output_bytes:24777743
    total_net_repl_input_bytes:0
    total_net_repl_output_bytes:22270070
    
    • slave
    # Stats
    total_net_input_bytes:22270213
    total_net_output_bytes:4020
    total_net_repl_input_bytes:22270070
    total_net_repl_output_bytes:0
    
  • for diskless loading (by setting repl-diskless-load to swapdb in redis.conf)

    • master
     # Stats
    total_net_input_bytes:8984484
    total_net_output_bytes:26999927
    total_net_repl_input_bytes:0
    total_net_repl_output_bytes:25945330
    
    • slave
    # Stats
    total_net_input_bytes:25945448
    total_net_output_bytes:2769
    total_net_repl_input_bytes:25945330
    total_net_repl_output_bytes:0
    

@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented Jan 6, 2022

Oh I think I'd better count flows for base/incr sync too.

@oranagra
Copy link
Member

oranagra commented Jan 6, 2022

I recently built some grafana dashboard that plots such graphs.
i monitored the increase over time of these counters:

  • total_net_output_byte
  • total_net_input_bytes
  • master_repl_offset

The instantaneous metrics are nice if you just look at a single INFO output with redis-cli, so you have a point here.
However, your PR handles the RDB portion of the replication, but missing the live command stream if i'm not mistaken.

p.s. i don't think i like to change the meaning of the existing fields (backwards compatibility), so they should keep including the replication data too, and users will have to deduct on their own

@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch 4 times, most recently from 8a2ffaf to 0207914 Compare January 10, 2022 03:04
@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented Jan 10, 2022

Hi @oranagra , I just made some updates, now This PR:

  1. adds 4 variables:
    server.stat_net_output_bytes_sync_fullresync/server.stat_net_input_bytes_sync_fullresync: for fullresync flow count
    server.stat_net_output_bytes_sync_cmds/server.stat_net_input_bytes_sync_cmds: for living command stream
  2. adds 8 info stats
total_net_input_bytes_sync_fullresync:0
total_net_output_bytes_sync_fullresync:0
total_net_input_bytes_sync_cmds:0
total_net_output_bytes_sync_cmds:0
instantaneous_input_sync_fullresync_kbps:0.00
instantaneous_output_sync_fullresync_kbps:0.00
instantaneous_input_sync_cmds_kbps:0
instantaneous_output_sync_cmds_kbps:0.00
  1. now server.stat_net_output_bytes/server.stat_net_input_bytes would keep the same meaning as before. If users would like to know the pure user's data flow count, they could deduct on their own.

@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented Jan 10, 2022

Also here is a test example with a 2-node redis(1 master and 1 slave).

Steps:

  1. start a new master node 30001
  2. using redis-benchmark to write to 30001
    ./src/redis-benchmark -t set -r 10000000 -d 1 -n 100000000 -p 30001
  3. after a while, start a new slave node 30002, run slaveof 127.0.0.1 30001
  4. run info stats to check the flow count of the master and slave

Results:

  • 30001 (master)
127.0.0.1:30001> info stats
# Stats
...
total_net_input_bytes:107794784
total_net_output_bytes:79574499
total_net_input_bytes_sync_fullresync:0
total_net_output_bytes_sync_fullresync:30543150
total_net_input_bytes_sync_cmds:0
total_net_output_bytes_sync_cmds:36493614
instantaneous_input_kbps:0.03
instantaneous_output_kbps:0.00
instantaneous_input_sync_fullresync_kbps:0.00
instantaneous_output_sync_fullresync_kbps:0.00
instantaneous_input_sync_cmds_kbps:0.00
instantaneous_output_sync_cmds_kbps:0.00
...
  • 30002(slave)
...
127.0.0.1:30002> info stats
# Stats
...
total_net_input_bytes:67037001
total_net_output_bytes:54822
total_net_input_bytes_sync_fullresync:30543150
total_net_output_bytes_sync_fullresync:0
total_net_input_bytes_sync_cmds:36493614
total_net_output_bytes_sync_cmds:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.05
instantaneous_input_sync_fullresync_kbps:0.00
instantaneous_output_sync_fullresync_kbps:0.00
instantaneous_input_sync_cmds_kbps:0.00
instantaneous_output_sync_cmds_kbps:0.00
...

@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch 2 times, most recently from 4fc6455 to 89fe913 Compare January 10, 2022 09:37
@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented Jan 10, 2022

Also I think one thing about the second commit could be discussed here.
To keep the total_net_output_bytes_sync_fullresync of master as same as total_net_input_bytes_sync_fullresync of slave during replication, I also count some missed net stats:

  1. count \n command at presync stage;
  2. connSyncReadLine() would lose 1 byte for a line of string ended with \r\n, so I add 1 extra byte for nread when count this.

Not sure if these two things are elegant here, just to keep consistency.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay.. i've been busy with redis 7.0, now finally free to look into this..

src/server.h Outdated
Comment on lines 153 to 156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm quite certain we don't want instantaneous metrics for all of these.
not for full-sync vs command-stream, and not even sure we need a separate replication input vs replication output.
i.e. these INFO fields are mainly for redis-cli users, not machines, and if they see high output traffic, and they know it's a master, they can deduct the replication bytes.
similarly if they see high input traffic on a replica, they'll deduct the replication bytes from that.

Copy link
Contributor Author

@DarrenJiang13 DarrenJiang13 May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only use single variable like net_repl_bytes, I think it might be ambiguous for structure like 'master->replica->replica'.
The middle redis node could both be a replica and master at the meantime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but for the "instantaneous" metrics, i'm not sure it's that important.
they're meant for quick manual check via redis-cli, since a proper metrics system will take the raw counters and plot their changes over time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see you removed all 4 instantaneous metrics you added. i think maybe we can keep one.
i.e. one that's about replication (sum of input and output)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra I think it's better to track and display the instantaneous replication input and output separately, we built read-write split structure as @DarrenJiang13 said: master->replica->replica, the middle replica has both input and output replication flow, and it's important to tell users how many input/output flow comes from themselves and others are replication flow.

So we need instantaneous_input_kbps - instantaneous_repl_input_kbps and instantaneous_output_kbps - instantaneous_repl_output_kbps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soloestoy the way i see it (please tell me if you see it differently) these instantaneous metrics are just for human eyes.
real monitoring systems, take a snapshot of the INFO every second, and can measure the increase of the raw metrics (non-instantaneous) over time.
so for instance if you have a grafana dashboard showing redis metrics, it'll still be able to show the difference between input and output, and it'll also be accurate, since it doesn't depend on these (inaccurate) "instantaneous" metrics (corresponding to 1.6 seconds or so).

so considering that these metrics are just for a person taking one snapshot of INFO via redis-cli to examine it in the console, do we really need another metric for this case?

@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch 2 times, most recently from c6fa714 to e37c68c Compare May 12, 2022 06:04
@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch from e37c68c to 158c286 Compare May 12, 2022 08:28
@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch from 2ade40a to 0801f5f Compare May 12, 2022 08:36
@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented May 12, 2022

Thank you for the review. @oranagra
And here is the code after revision.

  1. Now I only keep stat_net_repl_input_bytes / stat_net_repl_output_bytes for replication stats.
  2. stat_net_input_bytes/ stat_repl_output_bytes would only include repl bytes in info command.
  3. fix nwritten type from int to ssize_t.

output of info stats is like

  • master
# Stats
total_connections_received:53
total_commands_processed:213568
instantaneous_ops_per_sec:1
total_net_input_bytes:9183348
total_net_output_bytes:5301699
total_net_repl_input_bytes:0
total_net_repl_output_bytes:4226010
instantaneous_input_kbps:0.05
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
rejected_connections:0
  • replica
total_connections_received:1
total_commands_processed:5
instantaneous_ops_per_sec:0
total_net_input_bytes:4226153
total_net_output_bytes:4347
total_net_repl_input_bytes:4226010
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.01
instantaneous_output_kbps:0.05
instantaneous_input_repl_kbps:0.01
instantaneous_output_repl_kbps:0.00
rejected_connections:0

@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch from 58d99a0 to e2593a6 Compare May 16, 2022 02:17
@DarrenJiang13 DarrenJiang13 force-pushed the separate-repl-netstats branch from e2593a6 to bf970db Compare May 16, 2022 02:18
@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented May 16, 2022

Updated. @oranagra
Now info output is like:

  • for disk-based replication

    • master
    # Stats
    total_net_input_bytes:21534385
    total_net_output_bytes:24777743
    total_net_repl_input_bytes:0
    total_net_repl_output_bytes:22270070
    
    • slave
    # Stats
    total_net_input_bytes:22270213
    total_net_output_bytes:4020
    total_net_repl_input_bytes:22270070
    total_net_repl_output_bytes:0
    
  • for diskless loading (by setting repl-diskless-load to swapdb in redis.conf)

    • master
     # Stats
    total_net_input_bytes:8984484
    total_net_output_bytes:26999927
    total_net_repl_input_bytes:0
    total_net_repl_output_bytes:25945330
    
    • slave
    # Stats
    total_net_input_bytes:25945448
    total_net_output_bytes:2769
    total_net_repl_input_bytes:25945330
    total_net_repl_output_bytes:0
    

src/server.h Outdated
Comment on lines 153 to 156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see you removed all 4 instantaneous metrics you added. i think maybe we can keep one.
i.e. one that's about replication (sum of input and output)

@oranagra oranagra added state:major-decision Requires core team consensus release-notes indication that this issue needs to be mentioned in the release notes approval-needed Waiting for core team approval to be merged labels May 26, 2022
Copy link
Member

@itamarhaber itamarhaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oranagra oranagra merged commit bb1de08 into redis:unstable May 31, 2022
@oranagra
Copy link
Member

@DarrenJiang13 can you please also make a redis-doc PR?

@DarrenJiang13
Copy link
Contributor Author

DarrenJiang13 commented May 31, 2022

@oranagra finished. Added some words to redis-doc in info.md.

trackInstantaneousMetric(STATS_METRIC_NET_OUTPUT,
stat_net_output_bytes);
stat_net_output_bytes + stat_net_repl_output_bytes);
trackInstantaneousMetric(STATS_METRIC_NET_TOTAL_REPLICATION,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oranagra I think it's better to track and display the instantaneous replication input and output separately, we built read-write split structure as @DarrenJiang13 said: master->replica->replica, the middle replica has both input and output replication flow, and it's important to tell users how many input/output flow comes from themselves and others are replication flow.

So we need instantaneous_input_kbps - instantaneous_repl_input_kbps and instantaneous_output_kbps - instantaneous_repl_output_kbps

@soloestoy
Copy link
Contributor

soloestoy commented Jun 1, 2022

@soloestoy the way i see it (please tell me if you see it differently) these instantaneous metrics are just for human eyes.
real monitoring systems, take a snapshot of the INFO every second, and can measure the increase of the raw metrics (non-instantaneous) over time.
so for instance if you have a grafana dashboard showing redis metrics, it'll still be able to show the difference between input and output, and it'll also be accurate, since it doesn't depend on these (inaccurate) "instantaneous" metrics (corresponding to 1.6 seconds or so).

so considering that these metrics are just for a person taking one snapshot of INFO via redis-cli to examine it in the console, do we really need another metric for this case?

@oranagra we don't use grafana, our monitor system depends the "instantaneous" metrics, and as I know some users in our platform use the redis' "instantaneous" metrics too.

@oranagra
Copy link
Member

oranagra commented Jun 1, 2022

grafana or no grafana, i think a monitoring system should not use these.
i think think it's a bad metric that should only be used by user that takes one snapshot from command line, and that real monitoring systems need to compute deltas from raw data they capture from redis.
but if users use it, let's give it to them..
one of you want to make a PR to re-fix this ASAP?

p.s. i'm ok with that mainly because it's already there.. but if someone would suggest new metrics like instantaneous_connections_per_sec or any other metric like that, i'll probably argue against it.

come to think of it, someone could suggest that since we have instantaneous_ops_per_sec, we should split that to ones coming from replication stream, vs normal clients (instantaneous_repl_ops_per_sec). and won't like that.
maybe we should drop instantaneous_repl_total_kbps too?
@yossigo @madolson WDYT?

@soloestoy
Copy link
Contributor

it's ok if we don't support new instantaneous metrics, but now for instantaneous_repl_total_kbps it's better to separate it, @DarrenJiang13 can you make a PR?

BTW, the instantaneous metrics help me a lot when troubleshooting problems, our monitor system is not good enough, especially it's hard to add a new item 😓

@yossigo
Copy link
Collaborator

yossigo commented Jun 2, 2022

@oranagra I am not against the instantaneous metrics, I think they're useful for basic troubleshooting if you don't have a better monitoring system so I'm OK with adding that. But if we decide we need a new metric, the first choice should always be a raw value for proper monitoring systems to use.

@oranagra
Copy link
Member

oranagra commented Jun 2, 2022

I'm not against them either. They're useful from command prompt, but I wouldn't want to add dozens of them, one for every other raw metric we have.
That's why I thought it was enough to add just one instead of two..
But if others think it's necessary, I won't block that..

I'm not sure this specific one will help a lot for troubleshooting, e.g. more than like forks per second, or error reply rate, new client connections per second, etc.
I thought that one metric to show all replication related traffic would be enough to let the viewer realize that there's a lot of replication traffic, and they can do the rest of the investigation with raw metrics.

If I had to add one new instantaneous metric, I'd probably go for new client connection rate rather than add breakdown for replication in/out.

@madolson
Copy link
Contributor

madolson commented Jun 2, 2022

I agree that I think the instantaneous metrics should really only be used for debugging. AWS relies on incremental metrics for computing metrics we expose to end users so that we can compute deltas if we miss data points if the engine is busy or something.

@oranagra
Copy link
Member

oranagra commented Jun 2, 2022

@yossigo @madolson I'm not sure how to interpret your comments. Are you in favor of merging #10810 or do you think one new instantaneous replication bandwidth metric is enough to realize that replication is or isn't the cause of high traffic.

@soloestoy did we convince you that these are no good for real monitoring anyway?
I wanna stress that we're not discussing removing the existing old metrics, just the addition of new ones, so whoever used to rely on the old ones, is not in a worse state by the addition of the single new instantaneous metric instead of 2 .

@madolson
Copy link
Contributor

madolson commented Jun 3, 2022

@oranagra I would prefer to not add the instantaneous metrics. I think just looking at the deltas should be enough to determine where the resource utilization is.

@soloestoy
Copy link
Contributor

soloestoy commented Jun 3, 2022

@soloestoy did we convince you that these are no good for real monitoring anyway?

Nope : ) because I cannot convince our users, since they prefer instantaneous metrics.

I agree we don't add new instantaneous metrics from now on. But about instantaneous_repl_total_kbps, I strongly believe it's better to separate it.

@madolson
Copy link
Contributor

madolson commented Jun 3, 2022

@soloestoy Do you know how they are ingesting these instantaneous metrics? It seems weird that folks would be looking at this instead of periodically polling and doing math, but if users have a reason for it then I'm okay splitting it. It just seems like an anti-pattern to me.

@soloestoy
Copy link
Contributor

because these instantaneous metrics are very easy to collect and display, no need to do math. And sometimes users don't collect metrics every second (maybe collect every minute), so they can only rely on instantaneous metrics.

@oranagra
Copy link
Member

oranagra commented Jun 4, 2022

Nope : ) because I cannot convince our users, since they prefer instantaneous metrics.

The way to convince them is that they won't have any other choice 8-). but besides, this is a new metrics that they didn't have till now anyway.

And sometimes users don't collect metrics every second (maybe collect every minute), so they can only rely on instantaneous metrics.

i think it's the other way around. if you take two samples 1 minute apart, the instantaneous metric won't tell you what happened in between (just in the last 1.6 seconds), but computing deltas would!.
i think the instantaneous is only useful when you take just one reading and without any tools (redis-cli).

but anyway, i think we've invested enough energy on this discussion, i think it's clear where we're going with other metrics, but let's merge that PR and put it behind us, maybe the excuse for me would be symmetry (i.e. the fact that all other metrics count input and output separately).

oranagra pushed a commit that referenced this pull request Jun 6, 2022
…and instantaneous_output_repl_kbps. (#10810)

A supplement to #10062
Split `instantaneous_repl_total_kbps` to `instantaneous_input_repl_kbps` and `instantaneous_output_repl_kbps`. 
## Work:
This PR:
- delete 1 info field:
    - `instantaneous_repl_total_kbps`
- add 2 info fields:
    - `instantaneous_input_repl_kbps / instantaneous_output_repl_kbps`
## Result:
- master
```
total_net_input_bytes:26633673
total_net_output_bytes:21716596
total_net_repl_input_bytes:0
total_net_repl_output_bytes:18433052
instantaneous_input_kbps:0.02
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
- slave
```
total_net_input_bytes:18433212
total_net_output_bytes:94790
total_net_repl_input_bytes:18433052
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.05
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
@oranagra oranagra mentioned this pull request Jun 8, 2022
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
The amount of `server.stat_net_output_bytes/server.stat_net_input_bytes`
is actually the sum of replication flow and users' data flow. 
It may cause confusions like this:
"Why does my server get such a large output_bytes while I am doing nothing? ". 

After discussions and revisions, now here is the change about what this
PR brings (final version before merge):
- 2 server variables to count the network bytes during replication,
     including fullsync and propagate bytes.
     - `server.stat_net_repl_output_bytes`/`server.stat_net_repl_input_bytes`
- 3 info fields to print the input and output of repl bytes and instantaneous
     value of total repl bytes.
     - `total_net_repl_input_bytes` / `total_net_repl_output_bytes`
     - `instantaneous_repl_total_kbps`
- 1 new API `rioCheckType()` to check the type of rio. So we can use this
     to distinguish between diskless and diskbased replication
- 2 new counting items to keep network statistics consistent between master
     and slave
    - rdb portion during diskless replica. in `rdbLoadProgressCallback()`
    - first line of the full sync payload. in `readSyncBulkPayload()`

Co-authored-by: Oran Agra <[email protected]>
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…and instantaneous_output_repl_kbps. (redis#10810)

A supplement to redis#10062
Split `instantaneous_repl_total_kbps` to `instantaneous_input_repl_kbps` and `instantaneous_output_repl_kbps`. 
## Work:
This PR:
- delete 1 info field:
    - `instantaneous_repl_total_kbps`
- add 2 info fields:
    - `instantaneous_input_repl_kbps / instantaneous_output_repl_kbps`
## Result:
- master
```
total_net_input_bytes:26633673
total_net_output_bytes:21716596
total_net_repl_input_bytes:0
total_net_repl_output_bytes:18433052
instantaneous_input_kbps:0.02
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
- slave
```
total_net_input_bytes:18433212
total_net_output_bytes:94790
total_net_repl_input_bytes:18433052
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.05
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants