Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC 0002: ExecutionContext [EPIC] #15342

Open
ysbaddaden opened this issue Jan 14, 2025 · 0 comments · May be fixed by #15302
Open

Implement RFC 0002: ExecutionContext [EPIC] #15342

ysbaddaden opened this issue Jan 14, 2025 · 0 comments · May be fixed by #15302
Assignees
Labels
kind:feature topic:multithreading tough-cookie Multi-faceted and challenging topic, making it difficult to arrive at a straightforward decision.
Milestone

Comments

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Jan 14, 2025

Tracking issue to implement RFC #0002 that will introduce execution contexts into Crystal.

Draft

Related pull requests to prepare for the actual implementation:

Actual pull requests that implement some of the RFC (to be extracted from #15302):

The following depend on both PR above:

  • ExecutionContext::SingleThreaded
  • ExecutionContext::MultiThreaded
  • ExecutionContext::Isolated
  • ExecutionContext::Monitor

Related issues, that are impacted by the MT paradigm shift:

@ysbaddaden ysbaddaden added kind:feature topic:multithreading tough-cookie Multi-faceted and challenging topic, making it difficult to arrive at a straightforward decision. labels Jan 14, 2025
@ysbaddaden ysbaddaden added this to the 1.16.0 milestone Jan 14, 2025
@ysbaddaden ysbaddaden self-assigned this Jan 14, 2025
@ysbaddaden ysbaddaden moved this to In Progress in Multi-threading Jan 14, 2025
@ysbaddaden ysbaddaden linked a pull request Jan 14, 2025 that will close this issue
straight-shoota pushed a commit that referenced this issue Feb 12, 2025
Introduces 3 queues that will be used the ExecutionContext schedulers. They derivate from Go's internal queues (`q`, `runq` and `globrunq`).

1. `Fiber::List`: holds an unbounded singly-linked list of Fiber with a bulk insert operation.

2. `ExecutionContext::GlobalQueue`: wraps a `Fiber::Queue` with optional thread-safety and a bulk grab operation. There will be a single global queue per execution context shared among one or more schedulers.

   The point is to have an unbounded space to store as many fibers as needed, or to store cross context enqueues —the runnables queue below only supports a single producer.

3. `ExecutionContext::Runnables`: a bounded, lock-free, chase-lev queue (single producer, multiple consumers) with bulk operations. There will be a one runnables queue per execution context scheduler (aka local queue).

   On overflow or underflow it pushes/grabs half the queue size to/from the global queue (locking the mutex once in a while). 

   Any scheduler can steal from any runnables queue in the execution context at any time, directly into their own local queue.

   The point is to have a quick list to push/pop and steal from, and to limit the occurrences where we must lock the scheduler mutex to reach to the global queue.

Refs #15342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feature topic:multithreading tough-cookie Multi-faceted and challenging topic, making it difficult to arrive at a straightforward decision.
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants
@ysbaddaden and others