Skip to content

perf: reuse timers #12539

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

Closed
wants to merge 1 commit into from
Closed

perf: reuse timers #12539

wants to merge 1 commit into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Oct 27, 2023

This patch significantly improves performance by allowing reusing timers instead of creating and deleting them at every request. With this patch, PHP does only 2 syscalls per thread (a thread can handle many requests sequentially) instead of 2 per request.

As PHP doesn't manage threads itself, calling zend_max_execution_timer_shutdown() when a thread is terminated will now be the responsibility of the caller. I think that this change is acceptable because threads are often used to handle requests until the process terminates (it's what FrankenPHP does for instance), so even if zend_max_execution_timer_shutdown() isn't called explicitly (which is better and should be done by SAPIs using threads), the OS will destroy the timers when after the process termination.

cc @arnaud-lb

@dunglas dunglas changed the title fix: don't delete an unitialized timer perf: reuse timers Oct 27, 2023
@staabm
Copy link
Contributor

staabm commented Oct 27, 2023

Do you have numbers?

@dunglas
Copy link
Member Author

dunglas commented Oct 27, 2023

I'll publish a benchmark used by FrankenPHP next week.

@arnaud-lb
Copy link
Member

This looks reasonable to me. The change is low-risk as it only impacts --enable-zend-max-execution-timers, which is only used by FrankenPHP currently. Thus, targeting release branches is likely acceptable if benchmarks justify it.

Did you consider removing the zend_max_execution_timer_init() call from init_executor() as an alternative to the early return? (for non-ZTS build this would also require to call zend_max_execution_timer_init() once per process, maybe in zend_startup().)

@bukka
Copy link
Member

bukka commented Nov 9, 2023

We should not be introducing features to stable versions (no matter what the feature is). I'm preparing RFC that touches that topic (introducing features in stable and RC versions) so it would be good to delay this at least until this is decided. I will announce it in the next few days hopefully.

@bukka
Copy link
Member

bukka commented Nov 9, 2023

I think the main problem with this is that it creates somehow precedent for other things targeting stable versions. I'm aware that this is sometimes done but I don't think that's a good thing for stability.

@dunglas
Copy link
Member Author

dunglas commented Sep 25, 2024

Closing as #13027 does exactly the same thing.

@dunglas dunglas closed this Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants