Git Product home page Git Product logo

Comments (5)

jiacai2050 avatar jiacai2050 commented on July 30, 2024

Anyone working on this? I would like to contribute as my project depend heavily on this.

from rust-prometheus.

mxinden avatar mxinden commented on July 30, 2024

As far as I know there is no-one working on this @jiacai2050. Before you do, would you mind describing your use-case?

This crate supports local metrics via the local module which operates on non-thread-synchronized memory, thus bypassing the performance cost of atomic operations, eventually being flushed back to their global thread-synchronized counterparts.

I am not aware of a use-case that can not be achieved with the local module, but only with the currently missing idea of metrics local to a given core or thread.

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

@jiacai2050 I think you can try with thread local metrics + static metrics. According to our experiments this is already very efficient, although theoretically core-local is even better than thread local :)

from rust-prometheus.

jiacai2050 avatar jiacai2050 commented on July 30, 2024

@mxinden @breeswish Thanks for your suggestion.
local module is useful for when update metric in for-loop, but what I want is thread-local metrics update in its own thread, and only flush when prometheus scrapes.
AFAIK, thread-local metrics is better than core-local which requires flush when return from functions.
I will check what @breeswish mentions, see if it will meet my requirements.

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

@jiacai2050 The current implementation of the thread local metrics provided by this crate is an auto-flush one. Every time you update a thread local metric, the thread local last update time is checked, and then the thread local metric is synced to the global one if specified interval is elapsed. For both public Push and Pull interfaces, the value in the global one is used.

This kind of thread local metric avoids frequently updating a global shared memory, i.e. reduces contention to improve performance. It is mostly useful if you update your metrics very frequently in multiple threads (e.g. 1000 times per sec, updated by multiple worker threads).

Static metrics macros in this crate is another story. Normally when you use metrics with labels (i.e. metrics vectors), the label needs to be put or retrieve from a HashMap in runtime. However, in many scenarios the metric labels are deterministic and known at compile time. Static metrics macros help you define these static metrics easily, in a way similar to normal metric vectors, without the need to write many boilerplates. It saves HashMap lookup cost.

The two techniques (static metrics and thread-local metrics) can be used together to achieve the best performance this crate offers.

from rust-prometheus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.