Skip to content

Remove minimum in Fiber::ExecutionContext::Parallel#15946

Merged
straight-shoota merged 6 commits intocrystal-lang:masterfrom
ysbaddaden:rework/remove-minimum-range-of-parallel-execution-context
Jul 23, 2025
Merged

Remove minimum in Fiber::ExecutionContext::Parallel#15946
straight-shoota merged 6 commits intocrystal-lang:masterfrom
ysbaddaden:rework/remove-minimum-range-of-parallel-execution-context

Conversation

@ysbaddaden
Copy link
Collaborator

Having a minimal number of threads felt normal, but starting a parallel context with a minimum starts that number of schedulers and threads, but there's nothing to do, so the schedulers park the threads almost immediately, and even before we could spawn a fiber into the context.

The same happens when the context has no fibers to run: the schedulers park, and the parallelism returns to zero.

The actual parallelism will always reach zero instead of the configured minimum.

In practice, the range is 0..max not min..max: every parallel context starts at zero, increases to one when a first fiber is pushed, then the context will decide to increase the parallelism (assign more threads to run the schedulers) and decrease the parallelism based on the context current needs, up to the maximum parallelism, that may or may not be reached.

NOTE: the range is actually 0 on creation, then 1..max because we keep a thread to run the context's event loop (that might change in the future, if the context knows it has zero fibers).

follow up to #15936

ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Jul 1, 2025
…-lang#15946)

The context should be in control of the overall parallelism of the
context. In light of the incoming thread pool it makes more sense for
threads to be returned to the pool, so they can increase the parallelism
of contexts that need it, without starting more and more system
threads.
The context should be in control of the overall parallelism of the
context. In light of the incoming thread pool it makes more sense for
threads to be returned to the pool, so they can increase the parallelism
of contexts that need it, without starting more and more system
threads.
@ysbaddaden ysbaddaden force-pushed the rework/remove-minimum-range-of-parallel-execution-context branch from 494e8a4 to 8db16d1 Compare July 13, 2025 16:22
@ysbaddaden
Copy link
Collaborator Author

I added the deprecated constructors back. Since the feature is experimental they ignore the minimum, and the constructors themselves shall be removed in the next release.

@ysbaddaden ysbaddaden marked this pull request as ready for review July 13, 2025 16:25
@straight-shoota straight-shoota added this to the 1.18.0 milestone Jul 21, 2025
@straight-shoota straight-shoota merged commit ebb52e8 into crystal-lang:master Jul 23, 2025
38 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in Multi-threading Jul 23, 2025
@ysbaddaden ysbaddaden deleted the rework/remove-minimum-range-of-parallel-execution-context branch July 23, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants