Conversation
- Fix misleading log in release(): invalid/evicted workers now log 'already evicted, discarding' instead of 'returned to pool' - Fix newTestPool in pool_test.go: wire ctx/cancel so addWorker goroutines (triggered by maybeScaleUp) don't panic on nil p.ctx; register t.Cleanup(cancel) to prevent goroutine leaks - Document Shutdown(): clarify that p.cancel() and close(p.done) are intentionally distinct — cancel kills in-flight factory.Spawn calls, done stops healthCheckLoop and runTTLSweep
observer/observer.go — NodeStats struct + PollNodeStats() public API
observer/observer_linux.go — Linux impl: /proc/meminfo (RAM) + /proc/stat
(CPU idle, two samples 100ms apart)
observer/observer_unsupported.go — zero-valued stub for non-Linux builds
observer/observer_test.go — cross-platform test (zero on darwin, live on linux)
pool.go: extend PoolStats with Node observer.NodeStats field; wire
PollNodeStats() into Pool.Stats(). On Linux Stats() now blocks ~100ms
to measure CPU idle — documented in godoc and README.
README.md: add Monitoring section showing Stats() output with Node field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces host-level resource monitoring to the pool, allowing users to observe not just pool state (workers, sessions) but also the underlying machine's memory and CPU idle percentage. The new functionality is implemented in a cross-platform way: on Linux, it reads from
/procfiles, while on other platforms it returns zeroed values. Documentation and tests are included, and several minor improvements and clarifications were made to the codebase and comments.Host resource monitoring
observersubpackage, which provides thePollNodeStats()function to sample total/available memory and CPU idle percentage on Linux (returns zeroed values on other platforms). (observer/observer.go,observer/observer_linux.go,observer/observer_unsupported.go) [1] [2] [3]PoolStatsnow includes aNodefield (of typeobserver.NodeStats), populated by callingobserver.PollNodeStats()inPool.Stats(). (pool.go) [1] [2] [3]README.md)Testing and code quality
PollNodeStats()that checks for correct values and platform-specific behavior. (observer/observer_test.go)pool_test.go) [1] [2]Minor improvements
releaseto indicate when a worker is already evicted (e.g., due to crash or health check). (pool.go)Shutdownto clarify the purpose of signals sent during shutdown. (pool.go)