frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

Restart workers on Memory Limits

Open withinboredom opened this issue 11 months ago • 2 comments

Describe you feature request

Currently, in PHP, it allows setting a memory limit per a request. We also have worker scripts that restart based on the number of requests. Inspired by https://externals.io/message/126226, it may make sense to measure memory usage per the limit to handle potential memory leaks.

This needs a few things working together: GOMEMLIMIT for keeping the Go runtime in check, memory_limit ini settings, and the current container/cgroup memory limits (plus current number of threads).

From that, we can derive if a request is going to potentially exceed those limits, we can start a rolling restart of workers before handling the request. If after restarting the workers, and we are still brushing up against the limits, then we can assume there is a memory leak in go and we need to restart the entire process.

Note: this could also be an autoscaling strategy (density vs. speed)

withinboredom avatar Jan 31 '25 22:01 withinboredom

Probably related: https://github.com/caddyserver/caddy/pull/6809

dunglas avatar Feb 01 '25 00:02 dunglas

It would also be possible to restart single threads, not sure how safe that is though. Some leaking extensions could hang on shutdown (#1296)

AlliBalliBaba avatar Feb 02 '25 23:02 AlliBalliBaba