Skip to content

Record more performance metrics #5175

Closed

Description

@calmh

Currently we do a hash benchmark. We track transfer rates. There are often support issues on sync being slow, and narrowing down the cause is tricky. To help that out we could sample our operations to perhaps be able to present useful data. Things we could measure:

  • Per device block request data; time taken for each request-response and the amount of data thus transferred. (This would aggregate to per-device and total transfer rates.)
  • Per block write stats. Time taken to write a block (and size) and the operation that caused it (copy or transferred).
  • Per block read stats. Time to read a block (and size) and why (copy, incoming request, etc).
  • Per block verification stats. Time to verify block hashes.
  • Per block database lookup stats. Time to iterate or look up candidate blocks from database.
  • General database stats: time per get/set operation. (Timing iterations is trickier.)
  • etc

We already keep some counters for block actions, but not fine grained and not with timing metrics.

One way to expose this could be as a prometheus endpoint, which then also buys us the data types for tracking histograms or percentiles of these things.

Actually showing, interpreting and understanding the data is another issue. Having it accessible as an endpoint that can be viewed (and included in a future "support bundle" thing) could be a good start.

Activity

  1. h1z1 commented on Sep 10, 2018

    @h1z1

    Unless it were completely optional - and default off - that kind of data would indicate what kind of hardware is behind a node. See #5160

  2. calmh commented on Sep 11, 2018

    @calmh
    MemberAuthor

    It can also reveal aspects about the data being synced. I’m not proposing to send these metrics somewhere, merely making them available for the user.

  3. h1z1 commented on Sep 11, 2018

    @h1z1

    Is that not what prometheus would enable?

  4. calmh commented on Sep 11, 2018

    @calmh
    MemberAuthor

    "Enable" as in for anyone who can talk to the REST API, sure. If the enemy has your API key you have already lost.

  5. added
    enhancement
    on Sep 11, 2018
  6. h1z1 commented on Sep 12, 2018

    @h1z1

    Completely agree which is why the stats shouldn't be enabled by default :)

  7. otbutz commented on Feb 26, 2019

    @otbutz
    Contributor
    * General database stats: time per get/set operation. (Timing iterations is trickier.)
    

    https://godoc.org/github.com/syndtr/goleveldb/leveldb#DBStats ?

  8. arl commented on Jul 21, 2019

    @arl
    Contributor

    I'd like to tackle this issue.

    So from what I understand:

    Exposing a local Prometheus HTTP endpoint, disabled by default, and maybe a script to run a Prometheus instance in a local docker container.

    I don't know the code base really well but metrics being a transversal issue, a separate package could propose a simple api to create gauge, counters, etc. Then the core syncthing code would call that package when and where in need of instrumentation.

    Does somebody has something else in mind?
    Is it the right place to discuss this?

  9. AudriusButkevicius commented on Jul 21, 2019

    @AudriusButkevicius
    Member

    Prometheus does not make it easy for it to be consumed by anything else than prometheus tho.

  10. arl commented on Jul 21, 2019

    @arl
    Contributor

    Prometheus does not make it easy for it to be consumed by anything else than prometheus tho.

    Yes I guess you're right. I believe you are referring to the the fact that metrics are pulled by the prom server, as opposed to other instrumentation stacks, which require clients to push their own metrics to the server.

    However a prometheus server is very easily set up and running, scraping the metrics of a local syncthing instance is trivial, has its own (somewhat basic but nonetheless powerful) UI served locally.
    If the objective of this issue is to have a kind of support/dev bundle one can use without prior knowledge of metrics it could be the right tool for the job, but I'm sure there are others. This is the one I know best though.

    @AudriusButkevicius do you have something else in mind?

  11. AudriusButkevicius commented on Jul 21, 2019

    @AudriusButkevicius
    Member

    I think it's ok to have prometheus support, but I think we shouls wrap prometheus in our own library, and expose N minutes of last scrapes so we could draw charts in the UI of what was happening on the device in last N minutes.

  12. AudriusButkevicius commented on Jul 21, 2019

    @AudriusButkevicius
    Member

    Potentially use something like https://github.com/prometheus/prom2json in terms of the format we return, so that it's easy to embed into the UI.

  13. arl commented on Jul 21, 2019

    @arl
    Contributor

    Ok so to sum it up, and to so ensure I got the idea.

    Any syncthing code that wishes to produce some metrics would do so by using the API provided by a new metrics sub-package. For client code of this API, metrics are format-agnostic, I mean they are just counter, gauges, etc. they are not prometheus counters, gauges, etc...

    Metrics production:

    Using the package should be as simple as creating a metric of a specific type (list of types TDB), let's say a metric.Counter, and calling some methods over that counter instance (examples would be Counter.Add(n int) or Counter.Increment().

    Metrics being disabled by default, metrics.Counter (and friends) could be interfaces, so by default a no-op implementation of metrics.Counter and friends would be used.

    To enable/disable metrics, you'd have to restart syncthing.

    Metrics consumption:

    When metrics are enabled, syncthing would both expose:

    1. a standard prometheus HTTP endpoint (standard as in directly scrap-able by a prom server).
    2. a JSON mini time-serie of the last N minutes of scrapes. This is part is ATM less clear to me.
      Overall how do you envision the interaction with the UI? I mean, would the UI periodically request the last N minutes or would it be a one time thing?
  14. AudriusButkevicius commented on Jul 21, 2019

    @AudriusButkevicius
    Member

    This is a very generic dump of thoughts:

    I am not sure how we should structure the code.
    My gut says dependency injection, as lib/syncthing is now a thing, and keeping it a library without any global state is a nice, so perhaps we should inject some sort of metrics provider and push it down where needed, or start pushing down context.WithValue everywhere (again, this is a larger change), where components would check presence of subcomponents if they are around and act on them. This would make fixing logging and other global things in the future easier.

    It would be nice to be able to toggle most settings without requiring a restart. I guess we could do metrics.Init(config.Wrapper) or config.OnChange(metrics.SetEnabled) (somewhere in cmd/syncthing before moving to lib/syncthing) to do that if we really wanted to, and keeping it global is still something we'd want to do.

    As for the actual exposure, it would be nice to show transfer rates for folders over time and simillar things.
    We could have a mini timeseries as you say, which we'd have to poll periodically to receive updates, or we could create a new event subscription (like we have for disk events), where we do time based rather than count based retention, and publish new events as we receive recordings on the counters and gauges. This way a page refresh can get "all the events available" which will be last N seconds of points, and subscribe from there. We'd have to make sure that certain things tick often enough to have some starting data, or we write a library in a way which allows the gauges to query the current value from a reporter, oppose to the reporter reporting when the value changes, when we could check the reporters once a second.

    Alternatively, we could do some mini timeseries plus followup from websocket magic or something along those lines.

    I think we'll still concepts like labels, as you'll want to track per folder, per device or per folder per device metrics, so we need to add some additional dimensions.
    I guess this could be just part of the metric name, but given we're piggy backing on prometheus, it would make sense to keep supporting that.

  15. arl commented on Jul 21, 2019

    @arl
    Contributor

    My gut says dependency injection, as lib/syncthing is now a thing, and keeping it a library without any global state is a nice, so perhaps we should inject some sort of metrics provider and push it down where needed,

    Ok

    It would be nice to be able to toggle most settings without requiring a restart. I guess we could do metrics.Init(config.Wrapper) or config.OnChange(metrics.SetEnabled) (somewhere in cmd/syncthing before moving to lib/syncthing) to do that if we really wanted to, and keeping it global is still something we'd want to do.

    Got it.

    I think we'll still concepts like labels, as you'll want to track per folder, per device or per folder per device metrics, so we need to add some additional dimensions.
    I guess this could be just part of the metric name, but given we're piggy backing on prometheus, it would make sense to keep supporting that.

    Yes, that makes sense.

    Very basic roadmap

    Thanks for the briefing. It will probably take some time, that's why I wanted to establish a very basic roadmap and start to split the task into smaller ones.

    • To start off, I'm gonna code the metrics creation/production API, with in mind the fact that it could be enabled/disabled at runtime. IMHO it should be thought, as far as possible, as an autonomous package, and be TSDB-agnostic from the outside.
    • Then I'll see to integrate it with the rest of the syncthing code, be it with dependency injection or other means.
    • At this point the standard prometheus endpoint would be up and running, producing no metrics yet.
    • I'll then use the API to instrument some part of the code.
    • Finally I'll tackle the second endpoint (the one that will be used by the UI).

    There are probably a bunch of holes, but this is a start...
    There's something to keep in mind for all subtasks, it's the fact that the feature should be enabled/disabled at runtime.

    See you around, I'm sure I'll have many other questions.
    Feel free to issue any objection, doubts, advise regarding the roadmap.

  16. AudriusButkevicius commented on Jul 21, 2019

    @AudriusButkevicius
    Member

    I think the enabling disabling at runtime is a fairly trivial problem once you have the rest solved, you can just make counter.Add noop etc.

  17. lapo-luchini commented on Mar 16, 2021

    @lapo-luchini

    There seems to be an existing external Syncthing exporter, converting current data from API to Prometheus format.

  18. mmokrejs commented on Dec 21, 2022

    @mmokrejs

    I would appreaciate if the statistics collected the delays and timeouts. Note, my system has set European timezone GMT+1 on OpenWRT router but the 1.19.2 syncthing daemon has evidently got the timezone wrong. Then the timepoint is set to the past (2022-12-20 17:22:35 vs. 2022-12-20 17:13:53.112136263 +0000 UTC):

    2022-12-20 17:22:35 Connection loop
    2022-12-20 17:22:35 negative cache entry for MYSHARE at global@https://discovery.syncthing.net/v2/ valid until 2022-12-20 17:13:53.112136263 +0000 UTC m=+62.514170461 or 2022-12-20 18:12:17.112141383 +0000 UTC m=+3566.514175421
    2022-12-20 17:22:35 negative cache entry for MYSHARE at global@https://discovery-v4.syncthing.net/v2/ valid until 2022-12-20 17:13:53.112157223 +0000 UTC m=+62.514191421 or 2022-12-20 18:12:53.112160583 +0000 UTC m=+3602.514194621
    2022-12-20 17:22:35 negative cache entry for MYSHARE at global@https://discovery-v6.syncthing.net/v2/ valid until 2022-12-20 17:13:52.17705582 +0000 UTC m=+61.579090178 or 2022-12-20 18:12:52.17706414 +0000 UTC m=+3601.579098178
    ...
    2022-12-21 12:12:47 negative cache entry for ANOTHERSHARE at global@https://discovery.syncthing.net/v2/ valid until 2022-12-21 11:26:47.663077835 +0000 UTC m=+57691.051910007 or 2022-12-21 12:25:24.663086475 +0000 UTC m=+61208.051918647
    2022-12-21 12:12:47 negative cache entry for ANOTHERSHARE at global@https://discovery-v4.syncthing.net/v2/ valid until 2022-12-21 11:26:47.663123435 +0000 UTC m=+57691.051955607 or 2022-12-21 12:25:47.663130635 +0000 UTC m=+61231.051962807
    2022-12-21 12:12:47 negative cache entry for ANOTHERSHARE at global@https://discovery-v6.syncthing.net/v2/ valid until 2022-12-21 11:26:47.663158955 +0000 UTC m=+57691.051991127 or 2022-12-21 12:25:47.663165195 +0000 UTC m=+61231.051997367
    

    There is no GUI settings entry nor config file entry to ensure syncthing knows local timezone.

    Definitely, the connection attempts via IPv6 are just useless in my situation and just slowering the speed because my upstream WAN network does not support it. But, provided the routers kernel and syncthing binary supports IPv6 it still sttempts the connection and keeps track of locally annouced IPv6 addresses.

  19. added a commit that references this issue on Aug 9, 2023
    99086c4
  20. added this to the v1.24.0 milestone on Aug 23, 2023
  21. added a commit that references this issue on Jan 28, 2024
    b9c08d3
  22. added
    frozen-due-to-age
    on Aug 3, 2024
  23. locked and limited conversation to collaborators on Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrozen-due-to-age

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions