-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug][ErrorHandler] Increased the reserved memory from 10k to 32k #44327
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
[Debug][ErrorHandler] Increased the reserved memory from 10k to 32k #44327
Conversation
The ErrorHandler's job includes handling out of memory (OOM) exceptions, therefore it is imoprtant that that feature works. In the current state, when handling OOM exceptions, the error handler produces an OOM error itself, because the old 10k reserve is apparently not enough anymore. To mitigate that, the reserved memory gets bumped to 32k (which is enouogh).
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Thank you @sakalys. |
* Increase reserved memory for error handling Follow up to #42630 The error handler should be able to report exceptions arising from exceeding the PHP memory limit. Because of changes made to error handling, the previously configured value is no longer sufficiently large. A similar change was also done in Symfony a while ago, see symfony/symfony#44327. I used the following artisan command to determine the amount of memory required for error handling, using a reporter that simply writes to a file: ```php <?php declare(strict_types=1); namespace App\Console\Commands; use Illuminate\Console\Command; final class MeasureHandlerMemory extends Command { protected $signature = 'measure-handler-memory'; private int $peak; public function handle(): void { $this->peak = memory_get_peak_usage(); trigger_error('', E_USER_ERROR); } public function __destruct() { $used = memory_get_peak_usage() - $this->peak; echo "error handling used: " . $used . "\n"; $before = memory_get_usage(); $times = 10240; $reserve = str_repeat('x', $times); $after = memory_get_usage() - $before; echo 'repeat times ' . $times . ' reserves: ' . $after . "\n"; $ratio = $after / $times; echo 'ratio between bytes and repeat: ' . $ratio . "\n"; echo 'minimum times to repeat: ' . $used / $ratio . "\n"; } } ``` * Free memory in HandleExceptions::handleShutdown() While validating the effectiveness of #42630 in our application, I found that the call `$error = error_get_last()` causes a tiny bit of memory usage. Thus, I think it is better to clear memory as soon as entering the handler. * Update HandleExceptions.php Co-authored-by: Taylor Otwell <[email protected]>
* Increase reserved memory for error handling Follow up to laravel#42630 The error handler should be able to report exceptions arising from exceeding the PHP memory limit. Because of changes made to error handling, the previously configured value is no longer sufficiently large. A similar change was also done in Symfony a while ago, see symfony/symfony#44327. I used the following artisan command to determine the amount of memory required for error handling, using a reporter that simply writes to a file: ```php <?php declare(strict_types=1); namespace App\Console\Commands; use Illuminate\Console\Command; final class MeasureHandlerMemory extends Command { protected $signature = 'measure-handler-memory'; private int $peak; public function handle(): void { $this->peak = memory_get_peak_usage(); trigger_error('', E_USER_ERROR); } public function __destruct() { $used = memory_get_peak_usage() - $this->peak; echo "error handling used: " . $used . "\n"; $before = memory_get_usage(); $times = 10240; $reserve = str_repeat('x', $times); $after = memory_get_usage() - $before; echo 'repeat times ' . $times . ' reserves: ' . $after . "\n"; $ratio = $after / $times; echo 'ratio between bytes and repeat: ' . $ratio . "\n"; echo 'minimum times to repeat: ' . $used / $ratio . "\n"; } } ``` * Free memory in HandleExceptions::handleShutdown() While validating the effectiveness of laravel#42630 in our application, I found that the call `$error = error_get_last()` causes a tiny bit of memory usage. Thus, I think it is better to clear memory as soon as entering the handler. * Update HandleExceptions.php Co-authored-by: Taylor Otwell <[email protected]>
The ErrorHandler's job includes handling out of memory (OOM) exceptions,
therefore it is important that that feature works. In the current state,
when handling OOM exceptions, the error handler produces an OOM error
itself, because the old 10kB reserve is apparently not enough anymore.
To mitigate that, the reserved memory gets bumped to 32k (which is enough).
Note I'm not familiar with the whole open source submitting process, so any feedback and instructions on how to improve this PR are welcome.
I am not sure on how to write a unit test to test something like that (talking about the issue here #40824).