Skip to content

Do not build device Debug() strings when V(5) logging is off - #25

Merged
Jorres merged 1 commit into
mainfrom
fix/skip-device-debug-when-v5-off
Dec 2, 2026
Merged

Jorres merged 1 commit into
mainfrom
fix/skip-device-debug-when-v5-off

Conversation

@Jorres

@Jorres Jorres commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

dev.Debug() evaluated in arguments to klog is REALLY expensive even if it isnt used

noticed that when taking profiles to figure out why udev-manager was cpu starved during inc 2122

@Jorres

Jorres commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

CPU profiles, cold start, first 150s, a node in dev with 4661 devices, 250m CPU (same as , same config as in inc 2122

go tool pprof -top -cum

Before (d8bb4e6)
File: udev-manager-8dd8fe3.bin
Build ID: 9e7bb66953445eff34b5ed9edbfbb07267bec75e
Type: cpu
Time: 2026-11-30 22:35:30 CET
Duration: 150s, Total samples = 20.85s (13.90%)
Showing nodes accounting for 13.72s, 65.80% of 20.85s total
Dropped 614 nodes (cum <= 0.10s)
Showing top 40 nodes out of 189
      flat  flat%   sum%        cum   cum%
         0     0%     0%     12.57s 60.29%  github.com/ydb-platform/udev-manager/internal/plugin.(*Scatter[go.shape.*uint8]).added
         0     0%     0%     12.57s 60.29%  github.com/ydb-platform/udev-manager/internal/plugin.(*Scatter[go.shape.*uint8]).run
         0     0%     0%     12.33s 59.14%  github.com/ydb-platform/udev-manager/internal/udev.(*generic).Debug
    10.84s 51.99% 51.99%     11.08s 53.14%  runtime.cgocall
     0.03s  0.14% 52.13%     10.65s 51.08%  github.com/ydb-platform/udev-manager/internal/udev.(*generic).SystemAttributes
     0.02s 0.096% 52.23%      8.33s 39.95%  github.com/jochenvg/go-udev.(*Device).SysattrValue
         0     0% 52.23%      8.33s 39.95%  github.com/ydb-platform/udev-manager/internal/udev.(*generic).SystemAttribute
         0     0% 52.23%      7.28s 34.92%  github.com/jochenvg/go-udev.(*Device).SysattrValue.func1 (inline)
         0     0% 52.23%      7.28s 34.92%  github.com/jochenvg/go-udev._Cfunc_udev_device_get_sysattr_value
         0     0% 52.23%      3.30s 15.83%  runtime.mcall
     0.03s  0.14% 52.37%      3.26s 15.64%  runtime.schedule
     0.01s 0.048% 52.42%      3.19s 15.30%  runtime.park_m
         0     0% 52.42%      3.10s 14.87%  runtime.systemstack
     0.05s  0.24% 52.66%      2.71s 13.00%  runtime.findRunnable
         0     0% 52.66%      2.57s 12.33%  runtime.gcBgMarkWorker
         0     0% 52.66%      2.49s 11.94%  runtime.gcBgMarkWorker.func2
     0.31s  1.49% 54.15%      2.49s 11.94%  runtime.gcDrain
         0     0% 54.15%      2.31s 11.08%  github.com/jochenvg/go-udev.(*Device).Sysattrs
         0     0% 54.15%      2.16s 10.36%  runtime.gcDrainMarkWorkerDedicated (inline)
         0     0% 54.15%      2.02s  9.69%  github.com/jochenvg/go-udev.(*Device).Sysattrs.func1 (inline)
         0     0% 54.15%      2.02s  9.69%  github.com/jochenvg/go-udev._Cfunc_udev_device_get_sysattr_list_entry
     1.73s  8.30% 62.45%      1.73s  8.30%  runtime.futex
After (this PR)
File: udev-manager-4e172bc.bin
Build ID: d464b4ce950a63295a55b34771f429157452786c
Type: cpu
Time: 2026-11-30 22:48:03 CET
Duration: 150s, Total samples = 5.34s ( 3.56%)
Showing nodes accounting for 2.30s, 43.07% of 5.34s total
Dropped 394 nodes (cum <= 0.03s)
Showing top 40 nodes out of 315
      flat  flat%   sum%        cum   cum%
     0.01s  0.19%  0.19%      1.77s 33.15%  runtime.systemstack
         0     0%  0.19%      1.59s 29.78%  runtime.gcBgMarkWorker
         0     0%  0.19%      1.56s 29.21%  runtime.gcBgMarkWorker.func2
     0.10s  1.87%  2.06%      1.56s 29.21%  runtime.gcDrain
         0     0%  2.06%      1.37s 25.66%  runtime.gcDrainMarkWorkerDedicated (inline)
         0     0%  2.06%      0.87s 16.29%  runtime.markroot
         0     0%  2.06%      0.84s 15.73%  runtime.markroot.func1
         0     0%  2.06%      0.84s 15.73%  runtime.scanstack
     0.77s 14.42% 16.48%      0.77s 14.42%  runtime.cgocall
         0     0% 16.48%      0.74s 13.86%  runtime.mcall
         0     0% 16.48%      0.72s 13.48%  runtime.schedule
         0     0% 16.48%      0.70s 13.11%  github.com/jochenvg/go-udev.(*Enumerate).Devices
         0     0% 16.48%      0.70s 13.11%  github.com/ydb-platform/udev-manager/internal/udev.(*udevDiscovery).monitor
     0.70s 13.11% 29.59%      0.70s 13.11%  internal/runtime/syscall.Syscall6
     0.01s  0.19% 29.78%      0.67s 12.55%  runtime.findRunnable
         0     0% 29.78%      0.62s 11.61%  runtime.scanframeworker
         0     0% 29.78%      0.61s 11.42%  runtime.park_m
     0.55s 10.30% 40.07%      0.55s 10.30%  runtime.(*lfstack).pop (inline)
     0.04s  0.75% 40.82%      0.55s 10.30%  runtime.getempty
     0.01s  0.19% 41.01%      0.49s  9.18%  syscall.RawSyscall6
         0     0% 41.01%      0.48s  8.99%  github.com/jochenvg/go-udev.(*Enumerate).Devices.func1 (inline)
         0     0% 41.01%      0.48s  8.99%  github.com/jochenvg/go-udev._Cfunc_udev_enumerate_scan_devices

@Jorres
Jorres force-pushed the fix/skip-device-debug-when-v5-off branch from f7804c9 to d882897 Compare November 30, 2026 22:00
@Jorres

Jorres commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

Same setup, but also CPU limit 1 (was fixed after incident by Maxim Gorbunov)

After (this PR), 1 CPU
File: udev-manager-4e172bc.bin
Build ID: d464b4ce950a63295a55b34771f429157452786c
Type: cpu
Time: 2026-11-30 22:59:18 CET
Duration: 150s, Total samples = 6.50s ( 4.33%)
Showing nodes accounting for 3.65s, 56.15% of 6.50s total
Dropped 398 nodes (cum <= 0.03s)
Showing top 40 nodes out of 251
      flat  flat%   sum%        cum   cum%
         0     0%     0%      2.69s 41.38%  runtime.systemstack
     0.01s  0.15%  0.15%      2.52s 38.77%  runtime.gcBgMarkWorker
         0     0%  0.15%      2.49s 38.31%  runtime.gcBgMarkWorker.func2
     0.29s  4.46%  4.62%      2.49s 38.31%  runtime.gcDrain
         0     0%  4.62%      1.86s 28.62%  runtime.gcDrainMarkWorkerDedicated (inline)
         0     0%  4.62%      1.23s 18.92%  runtime.mcall
     0.01s  0.15%  4.77%      1.19s 18.31%  runtime.schedule
     0.05s  0.77%  5.54%      1.10s 16.92%  runtime.findRunnable
         0     0%  5.54%      1.10s 16.92%  runtime.park_m
     0.01s  0.15%  5.69%      0.99s 15.23%  runtime.markroot
         0     0%  5.69%      0.96s 14.77%  runtime.markroot.func1
     0.01s  0.15%  5.85%      0.96s 14.77%  runtime.scanstack
     0.86s 13.23% 19.08%      0.86s 13.23%  runtime.(*lfstack).pop (inline)
     0.84s 12.92% 32.00%      0.84s 12.92%  internal/runtime/syscall.Syscall6
     0.78s 12.00% 44.00%      0.78s 12.00%  runtime.cgocall
     0.05s  0.77% 44.77%      0.77s 11.85%  runtime.getempty
         0     0% 44.77%      0.71s 10.92%  github.com/jochenvg/go-udev.(*Enumerate).Devices
         0     0% 44.77%      0.71s 10.92%  github.com/ydb-platform/udev-manager/internal/udev.(*udevDiscovery).monitor
     0.20s  3.08% 47.85%      0.70s 10.77%  runtime.scanobject
         0     0% 47.85%      0.67s 10.31%  runtime.scanframeworker
         0     0% 47.85%      0.63s  9.69%  runtime.gcDrainMarkWorkerIdle (inline)
         0     0% 47.85%      0.50s  7.69%  syscall.RawSyscall6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the change to skip device debug-string generation when verbosity-5 logging is disabled.

No open issues 🎉

What changed in this PR

Avoids expensive device debug-string generation when verbosity-5 logging is disabled, reducing unnecessary work in the plugin’s device-event handling.

Changes:

  • Adds logDeviceV5, which checks whether logging is enabled before calling dev.Debug().
  • Routes six device-log calls in the add/remove handlers through the helper.
  • Adds a changelog entry describing the startup CPU improvement.
File Description
internal/​plugin/​scatter.go Guards device debug-string generation behind the verbosity check.
.changes/​unreleased/​Fixed-20261130-225321.yaml Documents the performance fix and reported CPU reduction.

Review effort: Balanced

@mvgorbunov mvgorbunov assigned SvartMetal and unassigned SvartMetal Dec 2, 2026
@mvgorbunov
mvgorbunov requested a review from SvartMetal December 2, 2026 06:55
@Jorres
Jorres merged commit 3fbb3cc into main Dec 2, 2026
3 checks passed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this file/directory belong to repo? Maybe add .changes/ to .gitignore?

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.

5 participants