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

Memory leak in Model #1326

Open
chaiyanlin opened this issue Jan 29, 2018 · 2 comments
Open

Memory leak in Model #1326

chaiyanlin opened this issue Jan 29, 2018 · 2 comments

Comments

@chaiyanlin
Copy link

chaiyanlin commented Jan 29, 2018

Here is my case:
I wrote a script as a consumer of Message Queue. But I found the memory usage will be increased after called Model::find().

e.g.

<?php
namespace app\extensions\command;

use app\models\Member;


class Test extends \lithium\console\Command
{

    public $openid;

    public function run()
    {
        while(true) {
            Member::findById(3);
            sleep(1);
            var_dump(str_pad(round(memory_get_usage(true) / (1024 * 1024), 2) . "M", 7));
        }
    }
}

output:

libraries/lithium/console/li3 test --env=test
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4M     "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.25M  "
string(7) "4.5M   "
string(7) "4.5M   "
string(7) "4.5M   "

@mariuswilms mariuswilms changed the title memory leak in cli mode? Memory leak in Model Feb 3, 2018
@bengearig
Copy link

I could not reproduce this. Perhaps not enough time was allowed for the GC to do its job? I tested with a MongoDB connection using the same code as yourself for the cli command. For me, it does as is explained, starting from 3 or 4M and rises to between 8 and 10M depending on the machine it was tested on, but then drops back to around 6M once the GC kicks in. Rising and falling until I kill it.

I tested on the following Lithium versions (framework and library versions matched):

  • 1.0.0
  • 1.0.1
  • 1.0.2
  • 1.1.0
  • 1.1.1

I tested all on PHP 5.6.33 with MongoDB 3.4 and a coworker tested 1.0.x versions with PHP 5.3.3 with MongoDB 3.2 and some version of MySQL.

@d1rk
Copy link
Member

d1rk commented Mar 31, 2018

@bengearig Thanks for that additional information and testing.

@chaiyanlin What PHP version did you use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants