-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add internal Fiber API #7045
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
Add internal Fiber API #7045
Conversation
This additional internal fiber API creates and manipulates a Fiber object, allowing any internal function to start, resume, or suspend a fiber. The existing zend_fiber_context API allows custom C-based fiber creation using the bundled switching context, but does not interact with the PHP VM. This API behaves the same as calling Fiber object methods from user code, switching EGs, and triggering the fiber switch observer. In general, the Fiber object methods call these new API methods.
cc @twose |
I am sorry that I don’t know who else will use these APIs except extensions like Swoole... |
@twose Maybe, if you've already done it - could you just push your work until now onto some branch (no matter if it works or compiles properly), so that we can see the direction it's headed to and potentially give early feedback? That way we can also iterate faster on this internal fiber API as needed. Thanks :-) |
@bwoebi Ummm, I am not sure if it is appropriate to discuss this in this thread... I can delete it if anyone feels dissatisfied. It has the following key differences from the current fiber:
For all the design problems, I think we can follow the rules of the multiprocess/multithreaded model:
Generally speaking, the code will be more concise. Of course that in order to remove the Nevertheless, we still need to do a lot of work to make it work with extensions like Swoole/Swow, it's just the beginning... |
@nikic @krakjoe Updated based on feedback, please review again. @twose A lot of what you're proposing are major changes, some behavior changes would require an RFC. It seems you'll need to rebase your work and start again anyway, as the merged implementation has changed quite a bit since you started. The API I'm proposing here actually aligns better with some of what you wrote, so I think this is a good starting point. Let's merge this PR and we can iterate from there if necessary. As you suggested, each change needs to be a separate PR and discussed – some of the things you mention have been already discussed (such as putting the Fiber object and VM stack on the mmap'd memory segment). |
@trowski While some changes could necessitate a RFC if challenged, I think we can do the changes on a consensus based approach. IIRC, you and I also had discussed some things he mentioned, with which you agreed, like making getStatus() an enum of just 4 values. |
@bwoebi Sure, of course not everything proposed (in fact probably not most things) need an RFC. Now that we have enums, the status could be an enum. I personally prefer the four methods over comparing a constant to a method result – seems less friendly IMO. I don't feel strongly though and this is really minor detail anyway. Not throwing from start/resume/throw, that probably needs an RFC as it's a major behavior change in the API. |
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.
This appears okay to me.
I've listened to the opinions expressed here, and the concern that we should not merge anything right now. However, this appears to be exactly the kind of iterative improvement that we are expecting, and the suggestions made here seem like the importation of a different implementation, not iterative improvements. While I'm sure that the suggestions made here could be broken down into iterative improvements, I'm not willing to withhold approval on improvements that are ready now.
The code I showed is just another experiment that was done a long time ago. That’s why I didn’t want to show it here in the beginning and I also think that it would be better to break it down into iterative improvements too. |
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.
OK, let's start from here.
This additional internal fiber API creates and manipulates a Fiber object, allowing any internal function to start, resume, or suspend a fiber. The existing
zend_fiber_context
API allows custom C-based fiber creation using the bundled switching context, but does not interact with the PHP VM. This API useszend_fiber
and behaves the same as calling Fiber object methods from user code, switching EGs, and triggering the fiber switch observer. In general, the Fiber object methods call these new API methods.