-
Notifications
You must be signed in to change notification settings - Fork 399
feat: task workers #1883
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
base: main
Are you sure you want to change the base?
feat: task workers #1883
Conversation
|
Yeah we can merge this with the modular threads logic 👍 feel free to adjust the worker as you need it |
|
This looks great. That will replace my need for the caddy-supervisor module. |
|
There are still quite a few points open:
I'm trying right now to pass any zval. After looking at how it's done in the parallel extension, we probably need to deep copy the values, though it doesn't have to be quite that complicated. Having a secure mechanism to pass zvals between threads might also be quite nice for extensions in general. We can go ahead with the current state as an initial version and work from there or I can do everything as a big chunk in this PR. |
I'd think that just like in the parallel extension, it might have some of the same issues? Such as trying to pass an exception through? Can we just use the parallel extension to lean on pre-existing code? |
|
Yeah we probably can, C dependencies are just kind of cumbersome to install and hard to test. We could allow passing anything if ext/parallel is installed, but only allow a string otherwise. Easiest way is to just go with strings for now. |
|
Cannot we copy/paste the code (with credits)? It would be better to have a core feature depending on a 3rd-party extension. |
|
I think most of them are obvious and serialisation is fine.
Unfortunate, but understandable.
Makes sense, configuration via php script seems sensible enough.
Like I said in the other thread I'd lean more towards configuration on the FrankenPHP side, but since the choice is to keep it in userland there, we should keep it in userland here too. Consistency is more important than personal preference. |
|
I implemented an external extension doing the same thing (I'll publish it soon, but I can give you access if needed). I made the HTTP request optional in #1910 IMHO, it's better to have that as an extension than in the core. WDYT? |
|
@dunglas external workers are one of the reasons I created this PR and I'd also like to merge the 'external workers' logic with task workers. Workers should do one thing: handle requests. Tasks workers offer a cleaner and more performant way to just pass a message to a PHP thread, no side effects. If you think that this PR tries to do too much at once, we can also remove the |
|
The two concepts look very similar to me: a worker waits for a request (HTTP or anything else) and may respond. I'm not sure if the PHP function and the |
|
To iterate on this, I released https://github.com/dunglas/frankenphp-queue After double thinking about it, I think I get where you want to go. I still think that we could simplify this code/merge it with the work done on extension worker, but there is indeed benefits to have this in core. What I would like to have is:
WDYT? |
|
A public api for just handling PHP requests already exists though. Can it not just be achieved by calling this with a custom worker/request/responsewriter? r, _:= frankenphp.NewRequestWithContext(r, frankenphp.WithWorkerName("...")))
frankenphp.ServeHTTP(rw, r)
doSomethingAfterRequest()What's missing is a way to just handle a message. I still think a separate I can remove the Btw your extension has the same problem with copying zvals across threads. The zval gets arena-deallocated as soon as the thread restarts/shuts down and it cannot mix with other PHP threads. So it must be converted to an intermediary representation for queuing. Maybe the answer is to just have |
|
I guess the only case where it would make sense to use |
|
Just to clarify again where we go from here:
|
This PR adds a new type of worker thread 'task workers'
caddyfile:
from a regular or worker PHP thread:
inside of the task worker:
Allows:
#1795 is also the reason why this feature is marked as experimental for now. Currently tasks are only passed as strings, but it would theoretically be possible to pass anything, even closures (while keeping thread safety in mind).