Skip to content

feat(telemetry): report host and per-server memory usage - #3584

Merged
athitten merged 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/memory-profiling
Sep 23, 2026
Merged

athitten merged 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/memory-profiling

Conversation

@ananthsub

@ananthsub ananthsub commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Add centralized, opt-in memory profiling to NeMo Gym's existing Lens/OpenTelemetry integration. One periodic orchestrator sampler reports:

  • host used, available, total, and sampled-peak memory;
  • current RSS/PSS and sampled peaks for every logical Gym server and its local descendants;
  • the number of processes currently attributed to each server.

Users can enable the profiler through YAML or environment variables. Environment-only enablement supports gym eval submit and other orchestrated runs without editing benchmark configs:

NEMO_GYM_OTEL_ENABLED=1 \
NEMO_GYM_OTEL_MEMORY_PROFILING_ENABLED=1 \
NEMO_GYM_OTEL_MEMORY_PROFILING_INTERVAL_SECONDS=1

Disabled runs create no sampler thread and perform no memory reads. Detached/reparented processes and remote Ray actors are explicitly outside per-server accounting; host metrics still expose their contribution to node pressure.

Related to #3155. This implements the centralized memory portion; runtime GC, event-loop, and request-cycle telemetry remain out of scope.

Relationship to #2935

PR #2935 also introduces host and process-tree memory reads, sampled inline when spans close. This focused PR centralizes that memory contract behind one periodic sampler so idle periods remain visible and request completion does not trigger repeated process-tree walks. It adds PSS, logical-server identity, process count, available memory, and sampled peaks. The broader correlation/concurrency work in #2935 can consume these latest readings for span attributes when rebased, while dropping its overlapping memory module.

Local runtime evidence

  • Uvicorn worker scaling for the policy proxy:
    • 1 worker / 1 process: 171 MB PSS
    • 2 workers / 4 processes: 427 MB PSS
    • 4 workers / 6 processes: 680 MB PSS
    • 8 workers / 10 processes: 1,191 MB PSS
  • Stateless resources server, 10,000 requests at client concurrency 512 with 64 KiB payloads: 0 errors; PSS rose from 308 MB idle to a 546 MB sampled peak.
  • Stateless resources server, 20,000 requests at client concurrency 1,024 with 64 KiB payloads: 0 errors; 656 requests/s; 833 MB sampled PSS peak.
  • Controlled subprocess allocation: PSS rose from 26 MB to 197 MB and returned to 26 MB; gym.server.memory.sampled_peak retained 206 MB.
  • Environment-only smoke emitted host and per-server metrics without a telemetry YAML block.
  • Combined host plus 64-process sampling at a one-second interval: 9.24 ms mean, 8.15 ms median, 14.15 ms p95.

Validation

  • uv run pytest tests/unit_tests/telemetry/ tests/unit_tests/test_cli.py tests/unit_tests/test_server_utils.py -q — 354 passed.
  • uv run pytest tests/unit_tests/telemetry/test_memory.py --cov=nemo_gym.telemetry.memory --cov-report=term-missing --cov-fail-under=0 -q — 15 passed, 98.20% profiler coverage.
  • uv run pre-commit run --all-files — passed.
  • cd fern && npm run check — 0 errors, 1 existing warning.
  • uv run gym dev test on the prior upstream base — 5,667 passed and 2 unrelated CLI output-wrapping assertions failed locally; both reproduced in isolation because Rich wraps long temporary paths despite the tests setting COLUMNS=1000.

Rollout evidence

N/A for model rollout behavior: this change affects application telemetry only and does not alter agents, verifiers, datasets, rewards, or model requests. The real multi-worker and high-concurrency HTTP smoke tests above exercise the changed runtime path directly.

Compatibility

Telemetry and memory profiling remain disabled by default. Server PSS requires Linux smaps_rollup; when unavailable, Gym emits RSS from statm and omits PSS. Host usage is calculated as total minus available. Sampled peaks can miss allocations shorter than the configured interval and are documented as sampled rather than exact cgroup lifetime peaks.

@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Sep 21, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team September 21, 2026 23:20
@github-actions

Copy link
Copy Markdown
Contributor

@ananthsub

Copy link
Copy Markdown
Contributor Author

Related to #3155. Implements the server memory-footprint portion through process-tree RSS/PSS metrics; per-worker runtime, GC, event-loop, and request-cycle telemetry remain out of scope.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Sep 22, 2026

@iguehring-nvidia iguehring-nvidia left a comment

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.

Thx much! Two minor things:

  1. The switch is only reachable through YAML. telemetry.memory_profiling.enabled is a nested field and is not in _ENV_FIELD_MAP, so configure_telemetry_env never translates it and _start_memory_profiler never reads a variable for it. For a job submitted with gym eval submit, Gym's telemetry is switched on entirely through the driver's environment (NEMO_GYM_OTEL_ENABLED, _SPAN_GROUPS, _LOGS_ENABLED, …), so memory profiling would stay off unless every benchmark config carries the block. Could you add a flattened mapping, e.g. memory_profiling.enabled → NEMO_GYM_OTEL_MEMORY_PROFILING_ENABLED (and the interval), following the existing Gym-owned flags in _ENV_FIELD_MAP? Then #3619 can turn it on with one line and every orchestrated run gets it.

  2. Pointing out some overlap with @oyilmaz-nvidia 's PR #2935. That PR also adds nemo_gym/telemetry/memory.py, with a different design: psutil sampling inside each server at span close, emitting host-wide gym.host.memory_* and a per-process gym.process_tree.memory_used_mib.

@ananthsub
ananthsub force-pushed the ananthsub/memory-profiling branch from b628e4c to 1212a08 Compare September 23, 2026 20:48
@ananthsub ananthsub changed the title feat(telemetry): report per-server memory usage feat(telemetry): report host and per-server memory usage Sep 23, 2026
@ananthsub

Copy link
Copy Markdown
Contributor Author

@iguehring-nvidia Thanks — addressed both points in 1212a08.

  1. Added flattened NEMO_GYM_OTEL_MEMORY_PROFILING_ENABLED and NEMO_GYM_OTEL_MEMORY_PROFILING_INTERVAL_SECONDS mappings. RunHelper now reconstructs the effective memory config after env precedence, so an environment-only gym eval submit flow starts the profiler. Unit coverage and a real environment-only smoke verify host and per-server metrics with no telemetry YAML block.
  2. Reviewed feat(telemetry): full correlation chain, saturation, concurrency, and Pareto-efficiency metrics #2935 and expanded this focused PR into the centralized periodic memory implementation: host used/available/total/peak plus logical-server RSS/PSS/peak/process count. This avoids request-biased span-close sampling and keeps one process-tree walk/overhead budget. The broader correlation and concurrency work in feat(telemetry): full correlation chain, saturation, concurrency, and Pareto-efficiency metrics #2935 remains complementary and can consume the cached/latest memory readings for span attributes when rebased; I documented the relationship in the PR body and tagged @oyilmaz-nvidia here for coordination.

@athitten
athitten added this pull request to the merge queue Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/35930553349

Merged via the queue into NVIDIA-NeMo:main with commit e7ff83d Sep 23, 2026
42 checks passed
@ananthsub
ananthsub deleted the ananthsub/memory-profiling branch September 24, 2026 00:05

This branch was previously deployed

1 inactive deployment
public — 1212a083 Deployed Sep 23, 2026 by copy-pr-bot[bot] via release / finalize / notify #3616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants