Code Monkey home page Code Monkey logo

Comments (5)

mihasya avatar mihasya commented on July 22, 2024 2

Hey there! Counters are monotonically increasing, unless reset. Timers use a histogram with a decay function under the hood, so you can think of it as a moving window - the output will be biased towards the most recent samples, with older samples dropping out of the picture entirely over time. You can see the NewTimer constructor to see the defaults and follow the thread from there to see what else is possible.

Hope this helps!

from go-metrics.

mihasya avatar mihasya commented on July 22, 2024

Sorry, I didn't answer your question directly. You can see that the other variable the Timer depends on is a meter - that actually uses an exponentially weighted moving average ("EWMA") to achieve the same end. Your use case will work just fine, as the values provided by the Timer will reflect the most recent datapoints. You can plug in a different implementations of Histogram and Meter, and there are a few options and tuning knobs available for both.

We've been using the defaults in production at Opsmatic and they work just fine. Similar techniques used to calculate things like load in Linux and various timing metrics in services such as Apache.

from go-metrics.

FZambia avatar FZambia commented on July 22, 2024

Thanks for your answer @mihasya - things are more clear now, I will try to experiment with timers, the thing I already noticed - if new time interval did not introduce new timer events - exported timer values remain the same:

package main

import (
    "github.com/rcrowley/go-metrics"
    "log"
    "os"
    "time"
)

const fanout = 10
const limit = 10

func main() {

    r := metrics.NewRegistry()

    t := metrics.NewTimer()
    r.Register("hooah", t)
    for i := 0; i < fanout; i++ {
        go func() {
            j := 0
            for {
                if j < limit {
                    t.Time(func() { time.Sleep(300e6) })
                } else {
                    break
                    //t.Time(func() { time.Sleep(1e6) })
                    //time.Sleep(299e6)
                }
                j++
            }
        }()
        go func() {
            k := 0
            for {
                if k < limit {
                    t.Time(func() { time.Sleep(400e6) })
                } else {
                    break
                    //t.Time(func() { time.Sleep(2e6) })
                    //time.Sleep(398e6)
                }
                k++
            }
        }()
    }

    metrics.Log(r, 1e9, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
}

Also timer max value not updated at all when new timer events are much faster (uncomment 4 lines in example above and remove break statements).

from go-metrics.

mihasya avatar mihasya commented on July 22, 2024

@FZambia these metrics are aggregates, so it makes sense that they don't move with every single data point. Think about what "max" is supposed to mean - it's the highest value seen, right? Of course, in webops "absolute" values "since last restart" are not very useful, which is why capped samples are employed. Follow the code from here to here and here - you will see that the Sample being used uses a "reservoir" of 1028 data points. I simply don't think you're pushing in enough data points to cause the previous "max" value to be pushed out of the "reservoir."

If you look at the comment above NewTimer, you'll see the defaults were pulled from Unix load averages - those are updated quite frequently.

Hope this helps. I'm closing this issue as I start the trek to "inbox 0" on this repo. Cheers.

from go-metrics.

FZambia avatar FZambia commented on July 22, 2024

Thanks a lot, this information will definitely help. I did not mean that this behaviour is somewhat buggy - just wanted to understand how to adapt it to my needs, now I see that I have not noticed lots of internal stuff.

from go-metrics.

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.