Skip to content

grpool: let can set limit/cap dynamically#4794

Open
joy999 wants to merge 17 commits into
masterfrom
feature/grpool
Open

grpool: let can set limit/cap dynamically#4794
joy999 wants to merge 17 commits into
masterfrom
feature/grpool

Conversation

@joy999

@joy999 joy999 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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:

  • Added a LimitChangerFunc and PoolOption to allow dynamic adjustment of the pool's goroutine limit at runtime, and refactored the pool to use atomic.Int64 for thread-safe limit handling. (os/grpool/grpool.go, [1] [2] [3]
  • Implemented new methods to pause and resume the pool (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]
  • Updated the supervisor logic to support dynamic limit changes and pausing, ensuring the pool responds immediately to limit changes and pause/resume commands. (os/grpool/grpool_supervisor.go, os/grpool/grpool_supervisor.goL17-R51)

API Additions and Improvements:

  • Added methods to get and set the pool capacity at runtime (Cap, SetCap), and to clear all pending jobs (ClearJobs). (os/grpool/grpool_pool.go, [1] [2]

Testing:

  • Added unit tests to verify dynamic limit changes and pause/resume functionality, ensuring correct behavior under various scenarios. (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.

Copilot AI review requested due to automatic review settings July 16, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 + PoolOption and 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.

Comment thread os/grpool/grpool_supervisor.go
Comment thread os/grpool/grpool_supervisor.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go
Copilot AI review requested due to automatic review settings July 16, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

Comment thread os/grpool/grpool_supervisor.go
Comment thread os/grpool/grpool_supervisor.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Copilot AI review requested due to automatic review settings July 16, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 16 comments.

Comment thread os/grpool/grpool.go
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_supervisor.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 01:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

Comment thread os/grpool/grpool.go
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go
Copilot AI review requested due to automatic review settings July 17, 2026 01:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_supervisor.go Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

Comment thread os/grpool/grpool.go
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_supervisor.go Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread os/grpool/grpool_supervisor.go Outdated
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 02:40
Copilot AI review requested due to automatic review settings July 17, 2026 03:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread os/grpool/grpool_supervisor.go Outdated
Comment thread os/grpool/grpool_supervisor.go
Comment thread os/grpool/grpool_supervisor.go
Copilot AI review requested due to automatic review settings July 17, 2026 03:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread os/grpool/grpool_supervisor.go
Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_pool.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go
Copilot AI review requested due to automatic review settings July 17, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread os/grpool/grpool.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Comment thread os/grpool/grpool_z_unit_test.go Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 03:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread os/grpool/grpool.go
Comment thread os/grpool/grpool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_z_unit_test.go
Comment thread os/grpool/grpool_z_unit_test.go
Copilot AI review requested due to automatic review settings July 17, 2026 03:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_supervisor.go
Comment thread os/grpool/grpool_supervisor.go
Copilot AI review requested due to automatic review settings July 17, 2026 04:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread os/grpool/grpool_pool.go
Comment thread os/grpool/grpool_pool.go
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.

4 participants