Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce MilliTimer #131

Merged
merged 1 commit into from
May 27, 2022
Merged

introduce MilliTimer #131

merged 1 commit into from
May 27, 2022

Conversation

tomwans
Copy link
Contributor

@tomwans tomwans commented May 24, 2022

This provides an API so that we can move away from microsecond-based
timers.

The StatsD spec suggests using milliseconds, and they're a great fit
for the typical RPCs we are measuring. Most RPCs take about
1-1000ms, which makes it easy for a human to spot and tell the
difference vs. microseconds which would be 1000us-1000000us. We don't
need that amount of fidelity.

Consumers can continue using NewTimer, using microseconds, which might
be appropriate for other use cases like timing functions. But most new
callers should move toward MilliTimer functions.

This provides an API so that we can move away from microsecond-based
timers.

The StatsD spec suggests using milliseconds, and they're a great fit
for the typical RPCs we are measuring. Most RPCs take about
1-1000ms, which makes it easy for a human to spot and tell the
difference vs. microseconds which would be 1000us-1000000us. We don't
need that amount of fidelity.

Consumers can continue using NewTimer, using microseconds, which might
be appropriate for other use cases like timing functions or tight
in-memory queues. But most new
callers should move toward MilliTimer functions.
@danielmmetz
Copy link
Contributor

Two questions/comments:

  1. Extending the interface is a breaking change if anyone is importing and using that with a different implementation. Probably fine, but thought it was worth calling out. WDYT?

  2. Were you able to find the context for why the default has been microseconds?
    As far as I can tell it's a relic of whatever predated this library?

@tomwans tomwans marked this pull request as ready for review May 27, 2022 17:00
@tomwans
Copy link
Contributor Author

tomwans commented May 27, 2022

  • Extending the interface is a breaking change if anyone is importing and using that with a different implementation. Probably fine, but thought it was worth calling out. WDYT?

I think the consumer should have their own interface that they can change in that case. It's Not Great that we expose an interface in this package in the first place, to be honest. That is why interfaces should really be kept at the consumer as much as possible.

  • Were you able to find the context for why the default has been microseconds?
    As far as I can tell it's a relic of whatever predated this library?

Some folks did some archaeology on this but the trail stops cold in 2016. Either way there's no great reason for it.

@tomwans tomwans merged commit 56ec36f into master May 27, 2022
@tomwans tomwans deleted the milliseconds branch May 27, 2022 17:22
Copy link
Contributor

@crockeo crockeo left a comment

Choose a reason for hiding this comment

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

It looks like this is used semi-frequently in mock scopes, but they can probably(?) be automatically regenerated.

https://sourcegraph.lyft.net/search?q=context:global+-repo:gostats+func.%2B%5C%28.%2B%5C%29.%2BNewTimer&patternType=regexp

t.AddDuration(dur)
}

func (t *timer) AddDuration(dur time.Duration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

silly nit: can this be below AddValue for consistency of ordering?

}

func (t *timer) AddDuration(dur time.Duration) {
t.sink.FlushTimer(t.name, float64(dur/t.base))
Copy link
Contributor

Choose a reason for hiding this comment

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

this is maybe a "i'm not a go programmer" piece of feedback, but the float64(dur/t.base) doesn't make a lot of sense unless you happen to know that:

  • durations in go are actually nanoseconds
  • time.Millisecond and time.Microsecond are the amount of nanoseconds in a ms or a µs

thoughts on adding a comment explicating what this does?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants