-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
refactor: decouple worker threads from non-worker threads #1137
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # frankenphp.c # frankenphp.go # php_thread.go # worker.go
Hmm that segfault is interesting, It's probably not fully safe to execute a PHP script while calling |
worker.go
Outdated
// when frankenphp_finish_request() is directly called from PHP | ||
// | ||
//export go_frankenphp_finish_request_manually | ||
func go_frankenphp_finish_request_manually(threadIndex C.uintptr_t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func go_frankenphp_finish_request_manually(threadIndex C.uintptr_t) { | |
func go_frankenphp_php_finish_request(threadIndex C.uintptr_t) { |
?
I'm not fond of the name I suggest, but "manually" sounds a bit weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I guess you're right 😅 . I changed it to go_frankenphp_finish_php_request
This PR refactors how threads are started and is meant as a step towards scaling threads at runtime.
How worker threads are currently started:
Currently, worker threads are started from regular threads via sending a special request
to ServeHTTP. The disadvantage here is that between sending the special worker request
and receiving it, we are losing control over which thread becomes a worker thread.
Worker threads and regular threads are inevitable coupled to each other.
How worker threads are started with this PR:
This PR decouples worker threads from regular threads and makes the
php_thread
structa wrapper around the thread's lifetime.
A 'PHP thread' is currently just a
pthread
with its ownTSRM
storage (this doesn'tnecessarily have to be tied to a real thread in the future as discussed in #1090).
The thread starts, does some work in a loop and then stops. This PR makes it possible
to configure these 3 lifetime hooks from the go side via the
php_thread
struct:This allows re-using the same mechanism for regular threads as well as worker threads.
It also makes it easier to create other potential types of threads in the future
(like 'scheduled workers' or 'task workers').
Additionally, it now would also be possible to grab an 'idle thread', exchange it's hooks and
turn it into a different type of thread at runtime without stopping the underlying thread.
(This PR doesn't go that far though)