Skip to content

Reduce unnecessary metric creation in loop - #256

Merged
brian-brazil merged 1 commit into
prometheus:masterfrom
umax:reduce-unnecessary-metric-creation
Mar 21, 2018
Merged

brian-brazil merged 1 commit into
prometheus:masterfrom
umax:reduce-unnecessary-metric-creation

Conversation

@umax

@umax umax commented Mar 21, 2018

Copy link
Copy Markdown
Contributor

Hi!

I will try to improve multiprocess metrics collections by a series of pull requests.
This one fixes unnecessary metric creation in loop.

The more correct way to use dict.setdefault is result = dict.setdefault(key, value). In our case:

metric = metrics.setdefault(metric_name, core.Metric(...))

instead of

metrics.setdefault(metric_name, core.Metric(...))
metric = metrics[metric_name]

But the problem is that core.Metric(...) will be executed each time when setdefault method calls whether needed or not.

Comment thread prometheus_client/multiprocess.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chaining = can be confusing, can you make this two statements?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no problem

@umax
umax force-pushed the reduce-unnecessary-metric-creation branch from 17c8202 to 350d24b Compare March 21, 2018 10:44
@brian-brazil
brian-brazil merged commit e2a5061 into prometheus:master Mar 21, 2018
@brian-brazil

Copy link
Copy Markdown
Contributor

Thanks!

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.

2 participants