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

Parse Durations much faster #461

Merged
merged 2 commits into from Mar 6, 2023

Conversation

bboreham
Copy link
Member

@bboreham bboreham commented Mar 6, 2023

Without using a regexp.

This shows up in profiles of Prometheus service discovery, since ParseDuration is called twice per discovered target.

name             old time/op    new time/op    delta
ParseDuration-4    2.54µs ±28%    0.04µs ± 3%   -98.30%  (p=0.008 n=5+5)

name             old alloc/op   new alloc/op   delta
ParseDuration-4      480B ± 0%        0B       -100.00%  (p=0.079 n=4+5)

name             old allocs/op  new allocs/op  delta
ParseDuration-4      2.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

Code inspired by Go standard library time.ParseDuration, but simplified and supporting different units.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Without using a regexp.

Code inspired by Go standard library `time.ParseDuration`, but
simplified and supporting different units.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@roidelapluie roidelapluie merged commit d7d98af into prometheus:main Mar 6, 2023
@roidelapluie
Copy link
Member

Thanks!

@bboreham
Copy link
Member Author

bboreham commented Mar 7, 2023

Now I realise this makes one of the Prometheus tests fail due to changed error message:

--- FAIL: TestPopulateLabels (0.00s)
    manager_test.go:436: 
                Error Trace:    /home/vagrant/src/github.com/prometheus/prometheus/scrape/manager_test.go:436
                Error:          Error message not equal:
                                expected: "error parsing scrape interval: not a valid duration string: \"2notseconds\""
                                actual  : "error parsing scrape interval: unknown unit \"notseconds\" in duration \"2notseconds\""
                Test:           TestPopulateLabels

Do you think it's important to retain consistency of error messages? I.e. shall I fix it here or in the test?

@bboreham bboreham deleted the faster-parseduration branch March 27, 2023 16:29
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.

None yet

2 participants