Skip to content

feat: maximum wait times#1445

Merged
dunglas merged 6 commits intomainfrom
feat/busy-timeouts
Mar 19, 2025
Merged

feat: maximum wait times#1445
dunglas merged 6 commits intomainfrom
feat/busy-timeouts

Conversation

@AlliBalliBaba
Copy link
Copy Markdown
Contributor

@AlliBalliBaba AlliBalliBaba commented Mar 15, 2025

This PR adds a simple timeout option for waiting too long for a PHP thread to accept a request. This helps the server recover faster during latency spikes by not allowing an endless accumulation of queued requests. It's similar to reverse-proxy timeouts and originally inspired by this discussion and another one I can't find anymore.

frankenphp {
    max_wait_time 15s
}

max_wait_time is not enabled by default, but it might make sense to equate this to the php.ini max_execution_time.

performance impact

The performance impact is ~0 if the max_wait_time option is not enabled (selecting over a nil channel is free).
If the option is enabled, there's a slight performance degradation in the optimized 'Hello World' (135000 RPS -> 125000 RPS 20 CPU cores). Real-live applications shouldn't feel this degradation though. In go 1.22 enabling the option would even increase performance, but go 1.23 changed it's timer implementation a bit, which apparently traded some efficiency for precision.

other considerations

This is only a first step towards making the server more resilient. I've thought of other ways to time out threads and came to the conclusion that this is probably best done in combination with the 'scaling' logic. The same goroutine that stops idle threads might also kill stuck threads or restart threads that reach memory limits.

docs

Docs should probably be added after another release to avoid them going up before the actual feature

@dunglas dunglas merged commit 9cca128 into main Mar 19, 2025
56 checks passed
@dunglas dunglas deleted the feat/busy-timeouts branch March 19, 2025 12:21
@dunglas
Copy link
Copy Markdown
Member

dunglas commented Mar 19, 2025

Thanks!

@dunglas
Copy link
Copy Markdown
Member

dunglas commented Mar 26, 2025

We must update the docs to mention this new feature.

@AlliBalliBaba
Copy link
Copy Markdown
Contributor Author

@dunglas 👍 I'll create a PR when I get to it

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.

2 participants