Thread and Worker Redesign and Refactor #1175
Replies: 3 comments 6 replies
-
#1137 was meant as a first step towards starting and stopping threads individually. I agree that it is not yet ideal and that there's additional complexity and race conditions. These race conditions don't matter yet though since we don't change what a thread does at runtime (yet). I like the idea of a state machine as you mentioned in #1137. Each type of thread would have its own state machine, I'll give this a go when I have time. I don't think we should keep around multiple implementations though, that kind of defeats the point of refactoring. If there are 'unforseen problems', people can just rollback to a previous version (any new feature can bring unforseen problems). |
Beta Was this translation helpful? Give feedback.
-
I was thinking of something like this for the state machine: stateDiagram-v2
[*] --> Unitialized: startup
Unitialized --> Booted: initializing php
Booted --> Ready: assigned role
Ready --> Active: Started worker script / request
Active --> Restart: PHP exit
Restart --> Ready: Reset thread
Active --> Failure: Unexpected termination
Failure --> Ready: Reset thread
Active --> Drain: Signal from watcher
Drain --> Ready: Reset thread
Ready --> Failure: Worker script crash
Ready --> Drain: Signal from watcher
Drain --> Shutdown: Graceful shutdown
Shutdown --> [*]
|
Beta Was this translation helpful? Give feedback.
-
I went ahead and added a minimal implementation of thread states that removes the global |
Beta Was this translation helpful? Give feedback.
-
@AlliBalliBaba discovered an architecture that allows for Fibers to work. However, it would be good to discuss the overall architecture and design so we can work on it together instead of one giant PR.
It would also be a good idea to use build tags and/or 'feature flags'? so we can switch between the old and new implementation easily. Thus if there is a (unforeseen) problem with the new architecture, a user can fall back to the old implementation. It would also allow for easier benchmarking.
What are the current issues with the thread/worker design?
That being said, @AlliBalliBaba has probably the most experience for how this should work; I'm just introducing ... so I'll hand it off to them.
cc: @dunglas
Beta Was this translation helpful? Give feedback.
All reactions