Skip to content
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

[5.4] Memory usage increased since v5.4.16 #18806

Closed
rimace opened this issue Apr 14, 2017 · 5 comments
Closed

[5.4] Memory usage increased since v5.4.16 #18806

rimace opened this issue Apr 14, 2017 · 5 comments

Comments

@rimace
Copy link
Contributor

rimace commented Apr 14, 2017

  • Laravel Version: 5.4.18
  • PHP Version: 7.1.3
  • Database Driver & Version: - (isn't needed)
  • Homestead: 5.0

Description:

Memory usage increased with commit 5d9b363 (included since v5.4.16).
I have commands which imports data from CSV files. These commands all use under 7 MB RAM with v5.4.15. Since Laravel 5.4.16 the memory usage has increased to about 300 MB RAM.

Steps To Reproduce:

I could not reduce the code and reproduce the increase to 300 MB, but this code still shows that the memory usage is multiple times higher with 5.4.16 than with older versions:
https://paste.laravel.io/9q1PA

@tillkruss
Copy link
Contributor

Ping @taylorotwell.

@arcanedev-maroc
Copy link
Contributor

I've just tested your snippet and indeed there is an increased usage in memory:

  • 5.4.15: 8.6 MB
  • 5.4.16: 18.6 MB
  • 5.4.18 (latest): 18.6 MB

@laurencei
Copy link
Contributor

laurencei commented Apr 15, 2017

I've found the cause. @rimace is right - you can get a runaway memory usage with Eloquent.

I'm submitting a PR now.

This is a simpler test as well (click to show);
<?php

namespace App\Console;

use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;

class TestMemoryLeak extends Command
{
    protected $signature = 'test:memoryleak';
    protected $description = 'Tests the memory leak that appears since 5d9b363448b9aac83b610166141b8bba9f1807f8';

    public function handle()
    {
        for($i = 0; $i < 100000; $i++) {
            $article = new Article;
            $article->updated_at = '2017-04-04 00:00:01';
            $article->updated_at = '2017-04-04 00:00:01';
            $article->updated_at = '2017-04-04 00:00:01';
        }

        $this->info('used ' . round(memory_get_peak_usage() / 1024 / 1024, 1) . ' MB RAM');
    }
}

class Article extends Model {}

@laurencei
Copy link
Contributor

@rimace - Taylor has accepted the PR - so this should be fixed and this issue can be closed. If you have any more issues please advise.

@themsaid
Copy link
Member

Thanks everyone :)

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

No branches or pull requests

5 participants