rpc: add cpu_load to getpeerinfo #31672

pull vasild wants to merge 1 commits into bitcoin:master from vasild:peer_cpu_load changing 7 files +85 −0
  1. vasild commented at 2:02 pm on January 16, 2025: contributor

    Add a new field cpu_load to the output of getpeerinfo RPC.

    It represents the CPU time spent by the message handling thread for the given peer, weighted for the duration of the connection. That is, for example, if two peers are equally demanding and one is connected longer than the other, then they will have the same cpu_load number.


    Monitoring CPU usage is useful on its own. Also related to #31033.

  2. DrahtBot commented at 2:02 pm on January 16, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31672.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK jonatack, sipa, theStack, BrandonOdiwuor, 1440000bytes

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 (Multiprocess bitcoin by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label RPC/REST/ZMQ on Jan 16, 2025
  4. vasild force-pushed on Jan 16, 2025
  5. DrahtBot added the label CI failed on Jan 16, 2025
  6. DrahtBot commented at 2:05 pm on January 16, 2025: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/35717681069

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  7. jonatack commented at 2:25 pm on January 16, 2025: member
    Concept ACK if this can be a reliable, useful metric and help pave the path to #31033.
  8. sipa commented at 3:24 pm on January 16, 2025: member
    Concept ACK
  9. rpc: add cpu_load to getpeerinfo
    Add a new field `cpu_load` to the output of `getpeerinfo` RPC.
    
    It represents the CPU time spent by the message handling thread for the
    given peer, weighted for the duration of the connection. That is, for
    example, if two peers are equally demanding and one is connected longer
    than the other, then they will have the same `cpu_load` number.
    2a7b61eb9e
  10. vasild force-pushed on Jan 16, 2025
  11. theStack commented at 6:15 pm on January 16, 2025: contributor

    Concept ACK

    Might be worth noting that this is currently only available on POSIX systems (i.e. not available on Windows, but on all other systems that we support AFAICT) in both the RPC help and a release note.

  12. BrandonOdiwuor commented at 7:00 pm on January 16, 2025: contributor
    Concept ACK
  13. fanquake commented at 1:06 pm on January 17, 2025: member

    Seems like there was some very brief discussion in #31033, and the conclusion “I guess this should start with planting some metrics”, but I’m not sure putting changes into Bitcoin Core is the right first step.

    Before changing our API, it’d be good to atleast show some usage that indicates that the changes here are useful. I assume you’ve already been running this locally, and collecting the data, so it’d be good to know what it turned up?

    As noted in #31033, others have also already conducted similar research (https://b10c.me/projects/023-cpu-usage-of-peers/ or https://delvingbitcoin.org/t/cpu-usage-of-peers/196), and it seems like the data you’d expose here, will be less detailed / useful than what can/has already been produced using tracepoints or similar, so I’m wondering if this is the best approach.

  14. vasild commented at 4:44 pm on January 17, 2025: contributor

    @fanquake IMO, monitoring CPU usage is useful on its own, even if we don’t start treating peers differently based on that metric (https://github.com/bitcoin/bitcoin/issues/31033). In other words, this metric is useful at least as much as a bunch of other metrics in the getpeerinfo output.

    Yes, I have been running this locally - there is like 65x difference between the least and most demanding peers. I am curious to correlate this to the messages being sent/received to/from those peers and to have a histogram of the data, not just least / most demanding (e.g. histogram of bitcoin-cli getpeerinfo |jq ".[].cpu_load"). I view those as something nice to build on top of this PR, not as a blocker that’s needed to justify the usefulness of the CPU time metric.

  15. 1440000bytes commented at 5:34 pm on January 17, 2025: none
    Concept ACK
  16. vasild commented at 12:25 pm on January 20, 2025: contributor

    Might be worth noting that this is currently only available on POSIX systems (i.e. not available on Windows

    Right. GetThreadTimes() looks like a promising Windows alternative. I will try to implement that here. Switching to draft because I will push some work-in-progress a bunch of times.

  17. vasild marked this as a draft on Jan 20, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-01-21 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me