-
Notifications
You must be signed in to change notification settings - Fork 70
Limit gProfiler memory & CPU usage and --log-usage support in exe mode. #564
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |||||
| from typing import Iterable, Optional, Type, cast | ||||||
|
|
||||||
| import configargparse | ||||||
| from granulate_utils.exceptions import AlreadyInCgroup, UnsupportedCGroupV2 | ||||||
| from granulate_utils.linux.cgroups.cpu_cgroup import CpuCgroup | ||||||
| from granulate_utils.linux.cgroups.memory_cgroup import MemoryCgroup | ||||||
| from granulate_utils.linux.ns import is_running_in_init_pid | ||||||
| from granulate_utils.linux.process import is_process_running | ||||||
| from granulate_utils.metadata import Metadata | ||||||
|
|
@@ -602,6 +605,30 @@ def parse_cmd_args() -> configargparse.Namespace: | |||||
| " beginning of a session.", | ||||||
| ) | ||||||
|
|
||||||
| parser.add_argument( | ||||||
| "--limit-memory", | ||||||
| default=(1 << 30), # 1Gi, same as in the k8s DaemonSet | ||||||
| dest="memory_limit", | ||||||
| type=int, | ||||||
| help="Limit on the memory used by gProfiler." | ||||||
| ) | ||||||
|
|
||||||
| parser.add_argument( | ||||||
| "--limit-cpu", | ||||||
| default=0.5, # 500m, same as in the k8s DaemonSet | ||||||
| dest="cpu_limit", | ||||||
| type=float, | ||||||
| help="Limit on the cpu used by gProfiler." | ||||||
|
||||||
| help="Limit on the cpu used by gProfiler." | |
| help="Limit on the cpu used by gProfiler. Units are cores and the default is %(default)s" |
same for memory (with appropriate units)
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log is not needed IMO. As I suggested in https://github.com/Granulate/gprofiler/pull/564/files#r1007993619, log only the negative case.
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Creatone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,17 @@ | |
|
|
||
| import psutil | ||
|
|
||
| CGROUPFS_ROOT = "/sys/fs/cgroup" # TODO extract from /proc/mounts, this may change | ||
| from granulate_utils.linux.cgroups.cgroup import find_v1_hierarchies, find_v2_hierarchy | ||
|
|
||
|
|
||
| # TODO(Creatone): Move it to granulate-utils. | ||
| def _obtain_cgroup_controller_path(cgroup: str, controller: str) -> str: | ||
| cgroup_v1_hierarchies = find_v1_hierarchies() | ||
| if len(cgroup_v1_hierarchies) != 1: | ||
| assert controller in cgroup_v1_hierarchies | ||
| return f"{cgroup_v1_hierarchies[controller]}{cgroup}" | ||
| else: | ||
| return f"{find_v2_hierarchy()}/{controller}{cgroup}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will work now - because cgroups v2 files are different. For example - there is no I created a ticket for cgroups v2 support. Until that's done, I suggest you raise an exception here if v2 is in use. Also I see that granulate-utils does this check: |
||
|
|
||
|
|
||
| class UsageLoggerInterface: | ||
|
|
@@ -30,7 +40,8 @@ class CpuUsageLogger(UsageLoggerInterface): | |
|
|
||
| def __init__(self, logger: logging.LoggerAdapter, cgroup: str): | ||
| self._logger = logger | ||
| self._cpuacct_usage = Path(f"{CGROUPFS_ROOT}{cgroup}cpuacct/cpuacct.usage") | ||
| cpu_root = _obtain_cgroup_controller_path(cgroup, 'cpuacct') | ||
| self._cpuacct_usage = Path(os.path.join(cpu_root, "cpuacct.usage")) | ||
| self._last_usage: Optional[int] = None | ||
| self._last_ts: Optional[float] = None | ||
|
|
||
|
|
@@ -78,7 +89,7 @@ class MemoryUsageLogger(UsageLoggerInterface): | |
|
|
||
| def __init__(self, logger: logging.LoggerAdapter, cgroup: str): | ||
| self._logger = logger | ||
| memory_root = f"{CGROUPFS_ROOT}{cgroup}memory" | ||
| memory_root = _obtain_cgroup_controller_path(cgroup, 'memory') | ||
| self._memory_usage = Path(os.path.join(memory_root, "memory.usage_in_bytes")) | ||
| self._memory_watermark = Path(os.path.join(memory_root, "memory.max_usage_in_bytes")) | ||
| self._last_usage: Optional[int] = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I specific no CPU limit? i.e
--limit-cpu noneshould be a possible parameter, not necessarily this way, but you should be able to limit ONLY the memory or CPU.