Skip to content

Conversation

@kxrxh
Copy link

@kxrxh kxrxh commented Nov 20, 2025

Motivation

Modifications

  • AdaptiveThrottler: Added a new flow component that regulates message processing speed using a feedback loop.
  • Resource Monitoring: Implemented ResourceMonitor with pluggable cpuUsageSampler (heuristic & measured modes) and memoryReader (cgroup v1/v2 & host support).
  • Configuration: Introduced AdaptiveThrottlerConfig for tuning thresholds, adaptation steps, and sampling intervals.
  • Testing: Added unit tests for the throttler logic and resource samplers to ensure correct behavior under load.

Verify change

  • Make sure the change passes the CI checks.
  • Do tests in Docker, K8S, host environments
  • Test functionality using demo application

kxrxh and others added 9 commits November 19, 2025 00:02
- Fix gocritic issues (elseif, ifElseChain)
- Fix gosec G115 integer overflow
- Fix revive unused parameter issues
- Fix unconvert unnecessary conversions
- Fix line length violations (>120 chars)
- Rename CPUUsageModeRusage → CPUUsageModeReal
- Move goroutineHeuristicSampler to dedicated file
- Update gopsutil from v4.25.10 → v4.24.6 for Go 1.21 compatibility
- Rename CPUUsageModeReal to CPUUsageModeMeasured for clarity
- Add clarifying comment to setSystemMemoryReader function

The new name better reflects that even gopsutil measurements are
approximations rather than absolute 'real' values.
…ed environments

- Add cgroup v2/v1 auto-detection for accurate memory stats in containers
- Normalize CPU usage sampling by core count for better accuracy
- Support custom memory readers in ResourceMonitor for flexible deployments
- Add comprehensive system_memory tests with mock file systems
- Improve test reliability with polling-based waiting instead of fixed sleeps
fix(flow): emit partial sliding window on early close (reugn#192)
- Implement a demo application showcasing the adaptive throttler in action
@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 77.25694% with 131 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.07%. Comparing base (18f3717) to head (6e24e80).

Files with missing lines Patch % Lines
internal/sysmonitor/memory_linux.go 67.94% 37 Missing and 13 partials ⚠️
internal/sysmonitor/cpu_linux.go 56.56% 29 Missing and 14 partials ⚠️
flow/adaptive_throttler.go 87.50% 14 Missing and 4 partials ⚠️
flow/resource_monitor.go 88.53% 12 Missing and 6 partials ⚠️
internal/sysmonitor/heuristic.go 85.71% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #196       +/-   ##
===========================================
- Coverage   99.53%   89.07%   -10.47%     
===========================================
  Files          13       20        +7     
  Lines         651     1227      +576     
===========================================
+ Hits          648     1093      +445     
- Misses          2       95       +93     
- Partials        1       39       +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reugn reugn changed the title Feature/adaptive throttler feat(flow): implement adaptive throttler Nov 20, 2025
…/sysmonitor package

Refactor CPU and memory monitoring code from the flow package into a dedicated internal/sysmonitor package. This improves code organization, testability, and platform-specific implementation support.

Key changes:
- Move CPU sampling logic to internal/sysmonitor with platform-specific implementations for Darwin, Linux, Windows, and fallback
- Move system memory monitoring to internal/sysmonitor with support for:
  - Linux: /proc/meminfo, cgroup v1, and cgroup v2 detection
  - Darwin: Mach kernel APIs with CGO
  - Windows: GlobalMemoryStatusEx API
  - Fallback: Error handling for unsupported platforms
  - Move heuristic CPU sampler from flow/cpu_sampler_heuristic.go to internal/sysmonitor/heuristic.go
- Update adaptive_throttler and resource_monitor to use new package
- Remove flow/cpu_sampler.go, flow/system_memory.go
Updated the getProcessCPUTimes function to use GetCurrentProcess for the current process, enhancing reliability and eliminating the need to open a process handle. This change simplifies the code and improves performance when retrieving CPU times.
@kxrxh
Copy link
Author

kxrxh commented Nov 21, 2025

@reugn Changes applied. Ready for re-review.

Copy link
Owner

Choose a reason for hiding this comment

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

Improve test coverage.

Copy link
Owner

Choose a reason for hiding this comment

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

Improve test coverage.

…at errors

- Implemented a safety check to ensure the number of CPUs is at least 1 in both Darwin and Linux CPU sampling functions.
- Updated memory reading functions to handle potential errors gracefully, defaulting to 0 for unavailable stats.
kxrxh and others added 28 commits November 22, 2025 16:59
…rottling process

Co-authored-by: Eugene R. <reugpro@gmail.com>
…quirement

Co-authored-by: Eugene R. <reugpro@gmail.com>
…ource statistics collection

Co-authored-by: Eugene R. <reugpro@gmail.com>
…its functionality

Co-authored-by: Eugene R. <reugpro@gmail.com>
…tor registry with reference counting

- Replace singleton ResourceMonitor with shared registry pattern for efficient resource sharing
- Add dynamic interval updates and improved CPU mode switching
- Enhance memory sampling with better fallback handling
- Add InDelta assertion helper for precise float comparisons
- Comprehensive test refactoring with improved mocking and coverage
- Update adaptive throttler tests to use new resource monitor architecture
@kxrxh kxrxh force-pushed the feature/adaptive-throttler branch from 16077b7 to 6e24e80 Compare November 24, 2025 14:49
@kxrxh
Copy link
Author

kxrxh commented Nov 26, 2025

@reugn Can you please re-run workflows (codecov, golangci-lint)?

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.

3 participants