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

collector.histogram is slow #461

Open
ochaton opened this issue Jun 11, 2023 · 2 comments
Open

collector.histogram is slow #461

ochaton opened this issue Jun 11, 2023 · 2 comments
Assignees
Labels
feature A new functionality

Comments

@ochaton
Copy link
Member

ochaton commented Jun 11, 2023

collector histogram is just bunch of counters, it is too bad for it to be slow. I've slightly rewrite collectors/histogram to speed it up:

With constant labels for each observe

127.0.0.1:3301> clock.bench(function() local lbls = {method='api.users.get',ok='true'} local prev = clock.time() for _ = 1, 1e6 do api_timings_hist:observe(clock.time()-prev, lbls) prev = clock.time() end end)
---
- - 16.211009
...

127.0.0.1:3301> clock.bench(function() local lbls = {method='api.users.get',ok='true'} local prev = clock.time() for _ = 1, 1e6 do api_timings_fast:observe(clock.time()-prev, lbls) prev = clock.time() end end)
---
- - 1.884366
...

Without labels on observe

127.0.0.1:3301> clock.bench(function() local prev = clock.time() for _ = 1, 1e6 do api_timings_hist:observe(clock.time()-prev) prev = clock.time() end end)
---
- - 10.5773
...
127.0.0.1:3301> clock.bench(function() local prev = clock.time() for _ = 1, 1e6 do api_timings_fast:observe(clock.time()-prev) prev = clock.time() end end)
---
- - 1.810581
...

Source code of FastHistogram is available on my gist: https://gist.github.com/ochaton/305e4668b41e2721b82b92217d74c9ba

Initialisation

local metrics = require 'metrics'
local metrics_fast_hist = require 'metrics.fast'

metrics.set_global_labels({
	app_name = 'bench',
	instance_name = 'bench_001',
})

local api_timings_fast = metrics_fast_hist:new('api_call', 'Histogram of API call',nil, {})
local api_timings_hist = metrics.histogram('api_call_hist', 'Histogram of API call',nil, {})

rawset(_G, 'api_timings_hist', api_timings_hist)
rawset(_G, 'api_timings_fast', api_timings_fast)

@yngvar-antonsson please take a look, and me you'll suggest better approach to increase perfomance of metrics/histogram

@ochaton
Copy link
Member Author

ochaton commented Jun 11, 2023

In my opinion 500K observations per second is still very-very slow

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days

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

No branches or pull requests

2 participants