Skip to content

Fix #1: reduce CPU usage during SMB file copy monitoring#5

Open
elstefan-assistant wants to merge 2 commits intomasterfrom
fix/issue-1-smb-cpu-load
Open

Fix #1: reduce CPU usage during SMB file copy monitoring#5
elstefan-assistant wants to merge 2 commits intomasterfrom
fix/issue-1-smb-cpu-load

Conversation

@elstefan-assistant
Copy link
Collaborator

@elstefan-assistant elstefan-assistant commented Mar 7, 2026

Summary

This PR addresses #1 (high CPU load during SMB copy) by removing per-packet heavy allocations/parsing and throttling expensive fallback paths.

Changes

  • PackageWorker
    • Replaced full-buffer copies with exact-length pooled buffer copies via ArrayPool.
    • Removed repeated receive buffer re-allocation and now reuses a fixed packet buffer.
    • Added fast-path packet parsing for IPv4/TCP destination port 445 (SMB) without allocating full IpHeader/TcpHeader objects for every packet.
    • Returns pooled buffers in finally to avoid memory growth/leaks.
  • WolHelper
    • Throttled unknown-IP logging (max once per IP per 5 minutes) to reduce log I/O pressure.
    • Throttled ARP refresh attempts (max once per minute globally) instead of refreshing on every unknown packet.

Expected Impact

  • Lower CPU utilization under heavy SMB traffic due to far fewer allocations and less object construction per packet.
  • Lower disk I/O from reduced repeated unknown-IP logs.
  • Preserved WoL behavior for SMB destination traffic (dst port 445) with existing wake cooldown logic intact.

Validation

  • Static behavior validation completed from code-path review (port-filtering and wake path preserved).
  • Runtime benchmark/functional verification requires Windows host + .NET SDK/runtime due to raw socket + Windows service constraints noted in README.

Closes #1

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.

Heavy CPU load when copying files over network

1 participant