laravel-debugbar icon indicating copy to clipboard operation
laravel-debugbar copied to clipboard

octane(swoole) memory leak

Open dvlpr91 opened this issue 2 years ago • 7 comments

  1. Create a new project.

  2. Install octane(swoole) and debugbar.

  3. Each time the page is refreshed, the memory increases.

  4. Set the enabled value to false in config/debugbar.php

  5. Each time the page is refreshed, memory is maintained.

dvlpr91 avatar Jun 14 '22 06:06 dvlpr91

You are not going to use debug bar in production.

ankurk91 avatar Jul 24 '22 09:07 ankurk91

@ankurk91 the memory leak will prevent developers from detecting actual memory leaks in the app.

and in some cases my 16GB ram gonna overflow because of this memory leak

ariaieboy avatar Jul 25 '22 19:07 ariaieboy

@dvlpr91 @ariaieboy

Have you tried this configuration?

Laravel with Octane:

Make sure to add LaravelDebugbar to your flush list in config/octane.php.

'flush' => [
   \Barryvdh\Debugbar\LaravelDebugbar::class,
],

lazerg avatar Aug 19 '22 03:08 lazerg

@dvlpr91 @ariaieboy

Have you tried this configuration?

Laravel with Octane:

Make sure to add LaravelDebugbar to your flush list in config/octane.php.

'flush' => [
   \Barryvdh\Debugbar\LaravelDebugbar::class,
],

Yes

dvlpr91 avatar Aug 19 '22 03:08 dvlpr91

@dvlpr91 @ariaieboy Have you tried this configuration?

Laravel with Octane:

Make sure to add LaravelDebugbar to your flush list in config/octane.php.

'flush' => [
   \Barryvdh\Debugbar\LaravelDebugbar::class,
],

Yes

Is that solved your issue?

lazerg avatar Aug 19 '22 03:08 lazerg

@dvlpr91 @ariaieboy Have you tried this configuration?

Laravel with Octane:

Make sure to add LaravelDebugbar to your flush list in config/octane.php.

'flush' => [
   \Barryvdh\Debugbar\LaravelDebugbar::class,
],

Yes

Is that solved your issue?

No, So I dumped the deguhbar in the trash.

dvlpr91 avatar Aug 19 '22 03:08 dvlpr91

@dvlpr91 @ariaieboy

Have you tried this configuration?

Laravel with Octane:

Make sure to add LaravelDebugbar to your flush list in config/octane.php.

'flush' => [
   \Barryvdh\Debugbar\LaravelDebugbar::class,
],

yes I added this config but it's not helping

ariaieboy avatar Aug 19 '22 06:08 ariaieboy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.

stale[bot] avatar Nov 02 '22 03:11 stale[bot]

Same issue when using Debugbar, Laravel 10, and Swoole. I've added the \Barryvdh\Debugbar\LaravelDebugbar::class to the flush configuration but still at every refresh of a fresh project, the ram will go up.

mehrab-wj avatar Apr 01 '23 13:04 mehrab-wj

Same issue here

aran112000 avatar Apr 01 '23 21:04 aran112000

Same here, Laravel 10, Octane + Swoole, on Laravel Sail, added the config but same leak.

louisjeck avatar May 02 '23 11:05 louisjeck

Same problem here, flush debugbar does not help. Increasing memory on every request

image

marianoarga avatar Jun 13 '23 23:06 marianoarga

Same here, but it seems like it's a "visual bug". I'm not seeing an actual increase in memory usage. Not really sure... image

victorbetini avatar Jul 01 '23 16:07 victorbetini

Sorry not really familiar with Swoole. Maybe something needs to be flushed/reset with the RAM. Do other people increase actually increasing ram, or just the visual?

Can anyone try with settings realUsage to true in https://github.com/maximebf/php-debugbar/blob/master/src/DebugBar/DataCollector/MemoryCollector.php Or by calling https://www.php.net/manual/en/function.memory-reset-peak-usage.php in the flush / event when restarted (not sure how that works with Octane)

barryvdh avatar Jul 03 '23 10:07 barryvdh

Sorry not really familiar with Swoole. Maybe something needs to be flushed/reset with the RAM. Do other people increase actually increasing ram, or just the visual?

Can anyone try with settings realUsage to true in https://github.com/maximebf/php-debugbar/blob/master/src/DebugBar/DataCollector/MemoryCollector.php Or by calling https://www.php.net/manual/en/function.memory-reset-peak-usage.php in the flush / event when restarted (not sure how that works with Octane)

Thanks for the reply! I've tried both suggestions, but none of them fixed the issue :( I'm considering not using Octane anymore... It is giving me more problems than solutions...

victorbetini avatar Jul 03 '23 13:07 victorbetini

This problem will not be easily resolved. When faced with a problem, giving up now will be the quickest solution.

dvlpr91 avatar Jul 14 '23 05:07 dvlpr91

I do not confirm the issue. Just tested on Laravel 10.13, Octane 2.0, Swoole 5.0.3, PHP 8.2.7 and Debugbar 3.8.1. Single Blade view, debug mode enabled, reported memory usage stays at 19MB no matter how many times I refresh the page. Seems that something got fixed along the way.

borys-p avatar Jul 31 '23 12:07 borys-p

We're still seeing this within Laraval apps running on Octane - Even a default Laravel install adds +~2mb per page load and compounds with every page you view until memory exhausted, or Octane restarts the worker

aran112000 avatar Aug 30 '23 16:08 aran112000

It seems to me that the problem is that they use only a "main" preloaded script for many requests, debugbar obtains the peak of the request, that would be the memory value of the entire process on this case

The solution would be to change the way it is calculated, the initial memory should be obtained with memory_get_usage, and subtract it from the peak memory of the MemorySataCollector

@barryvdh what do you think? would PR be accepted for that?

parallels999 avatar Sep 15 '23 17:09 parallels999

Hi, try https://github.com/maximebf/php-debugbar/pull/559 and let your review

erikn69 avatar Sep 18 '23 13:09 erikn69

For Octane, can Laravel just call memory_reset_peak_usage when PHP8.2+ is used?

barryvdh avatar Sep 18 '23 14:09 barryvdh

@barryvdh , still, octane handles an running process with "preload" on memory instances, so the peak is always really big, also on other OS like windows, the instance is up 19mb, https://github.com/maximebf/php-debugbar/pull/559 normalizes with a baseline before execution, That will normalize the memory calculation, what do you think of that solution? What would be the cons I did also added memory_reset_peak_usage on that PR

erikn69 avatar Sep 18 '23 14:09 erikn69

I still have this issue but I found a quick fix and thought to share it here.

The easiest fix is, when you are starting your Octane server, specify Max Request Count to something low like 1, or 2.

For example, this is how I'm running my server in development:

php artisan octane:start --watch --host=0.0.0.0 --port=8000 --max-requests=1

mehrab-wj avatar Feb 22 '24 15:02 mehrab-wj

@mehrab-wj hi, for the records, did you set true on reset_peak and with_baseline?

This was added on latest version https://github.com/barryvdh/laravel-debugbar/blob/276892c32bd71d6cc073e39a6e6c1a341ea128c0/config/debugbar.php#L202-L204

erikn69 avatar Feb 22 '24 16:02 erikn69

Hi @erikn69, No I was following the based on the readme, I will test this, Thanks.

mehrab-wj avatar Feb 24 '24 16:02 mehrab-wj

@mehrab-wj this will result in restarting the workers after each request, so you will lose all the benefits of using Octane and might even get worse performance than without it.

borys-p avatar Mar 23 '24 10:03 borys-p