grpool: let can set limit/cap dynamically#4794
Open
joy999 wants to merge 17 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances os/grpool (GoFrame’s goroutine pool) to support dynamic adjustment of the goroutine limit at runtime and introduces a pause/resume control surface, with accompanying supervisor updates and new unit tests.
Changes:
- Add
LimitChangerFunc+PoolOptionand wire dynamic limit updates into the supervisor loop. - Add pool pause/resume state (
Parse/Resume,IsParsed) and timer control to stop/resume supervision. - Extend unit tests to cover dynamic limit changes and parse/resume behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| os/grpool/grpool.go | Adds option-based construction, limit-changer plumbing, and package-level Parse/Resume helpers. |
| os/grpool/grpool_pool.go | Implements parsed state + resume/parse behavior and worker behavior changes. |
| os/grpool/grpool_supervisor.go | Updates supervisor logic to honor parsed state and dynamically update the limit. |
| os/grpool/grpool_z_unit_test.go | Adds tests for dynamic limits and parse/resume behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
coleannie313-design
approved these changes
Jul 18, 2026
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 significant enhancements to the goroutine pool (
grpool) by adding support for dynamic resizing of the pool, pause/resume functionality, and improved state management. These changes make the pool more flexible and robust, allowing runtime adjustment of worker limits and better control over job execution. The pull request also includes comprehensive tests for the new features.Dynamic Pool Management and Control:
LimitChangerFuncandPoolOptionto allow dynamic adjustment of the pool's goroutine limit at runtime, and refactored the pool to useatomic.Int64for thread-safe limit handling. (os/grpool/grpool.go, [1] [2] [3]Pause,Resume,IsPaused), preventing new jobs from starting while paused and resuming execution when desired. (os/grpool/grpool.go, [1];os/grpool/grpool_pool.go, [2]os/grpool/grpool_supervisor.go, os/grpool/grpool_supervisor.goL17-R51)API Additions and Improvements:
Cap,SetCap), and to clear all pending jobs (ClearJobs). (os/grpool/grpool_pool.go, [1] [2]Testing:
os/grpool/grpool_z_unit_test.go, os/grpool/grpool_z_unit_test.goR117-R202)These changes greatly improve the flexibility and usability of the goroutine pool, making it suitable for more advanced and dynamic workloads.