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

Bug 1920481: Decrease CPU usage of Prometheus exporter #437

Merged
merged 1 commit into from Jan 26, 2021

Conversation

dulek
Copy link
Contributor

@dulek dulek commented Jan 26, 2021

Seems like a thread moving the metrics data into the service exposing
them in the Prometheus format was not constrained with any sleep. This
was causing increased CPU usage of kuryr-cni pods without a real
reason to do it.

This commit solves that by rewriting the thread to use the common
multiprocessing queue pattern.

Change-Id: I0eacc37022fbf214c361dbc52b42281ffa5301fd

@openshift-ci-robot openshift-ci-robot added the bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. label Jan 26, 2021
@openshift-ci-robot
Copy link

@dulek: This pull request references Bugzilla bug 1920481, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1920481: Decrease CPU usage of Prometheus exporter

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Jan 26, 2021
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 26, 2021
pod_name = metric['name']
labels = metric['labels']
duration = metric['duration']
with lockutils.lock(pod_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to lock here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, maybe not. So I left it here thinking that prometheus_exporter might not be thread safe. Or that it's called from various places. But seems like it can only be called from this thread and we're guaranteed it's sequential.

Copy link
Contributor

Choose a reason for hiding this comment

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

right, no strong opinion. If leaving it here might be safer, it's fine.

self.prometheus_exporter.update_metric(labels, duration)
del self.metrics[pod_name]
try:
metric = self.metrics.get(timeout=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

does the get here blocks the addition of new metrics while removing from queue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I understand. This queue module should be thread safe, meaning that get() blocks until there's an item added using put(). Or the timeout happens, which we use to check self.is_running to make sure the thread is able to correctly stop even if there are no new CNI requests handled at a moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

excellent. Thanks for explaining.

Seems like a thread moving the metrics data into the service exposing
them in the Prometheus format was not constrained with any sleep. This
was causing increased CPU usage of kuryr-cni pods without a  real
reason to do it.

This commit solves that by rewriting the thread to use the common
multiprocessing queue pattern.

Change-Id: I0eacc37022fbf214c361dbc52b42281ffa5301fd
@MaysaMacedo
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 26, 2021
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dulek, MaysaMacedo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 13324f7 into openshift:master Jan 26, 2021
@openshift-ci-robot
Copy link

@dulek: All pull requests linked via external trackers have merged:

Bugzilla bug 1920481 has been moved to the MODIFIED state.

In response to this:

Bug 1920481: Decrease CPU usage of Prometheus exporter

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dulek
Copy link
Contributor Author

dulek commented Jan 27, 2021

/cherry-pick release-4.6

@openshift-cherrypick-robot

@dulek: new pull request created: #440

In response to this:

/cherry-pick release-4.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants