-
Notifications
You must be signed in to change notification settings - Fork 66
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
Strange behavior while 'free memory' #168
Comments
Hey @yyydevf ,thanks for bringing this up 👍 We're currently not aware of any memory leaks and it's hard to see the time difference when only using the timestamp, but the behavior you're seeing sounds similar to the other ticket you opened in reactphp/http: reactphp/http#477 Could this be the same case here? |
@SimonFrings Hello, thats not about memory leak, memory have free, but i'm trying to understand, whats the magic 450 seconds
I have repeated the tests with normal dates, sorry for timestamps:
Browser works fine. Code: <?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
$loop = \React\EventLoop\Loop::get();
$browser = new \React\Http\Browser();
$loop->addPeriodicTimer(
1,
fn() => $browser->get('https://google.com')
->then(function ( $result) {
//echo count($result->resultRows) . PHP_EOL;
//some other actions
})
);
$loop->addPeriodicTimer(1, function () {
echo sprintf(
'[%s] Current usage %f mb, Max: %f mb' . PHP_EOL,
(new \DateTime())->format("G:i:s"),
round(memory_get_usage() / 1024 / 1024, 2) . ' mb',
round(memory_get_peak_usage() / 1024 / 1024, 2) . ' mb'
);
});
$loop->run(); Log:
|
Can someone explain why free memory only after 10mb, not after every request? Increasing number of queries have better result: <?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
$loop = \React\EventLoop\Loop::get();
$factory = new \React\MySQL\Factory();
$connection = $factory->createLazyConnection('root:root@localhost:13306/db1');
$loop->addPeriodicTimer(
1,
fn() => \React\Promise\all([
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
$connection->query('SELECT 1'),
])->then(function ($result) {
//echo count($result->resultRows) . PHP_EOL;
//some other actions
})
);
$loop->addPeriodicTimer(1, function () {
echo sprintf(
'[%s] Current usage %f mb, Max: %f mb' . PHP_EOL,
(new \DateTime())->format("G:i:s"),
round(memory_get_usage() / 1024 / 1024, 2) . ' mb',
round(memory_get_peak_usage() / 1024 / 1024, 2) . ' mb'
);
});
$loop->run(); Log
|
I think what we see here might be PHP's behavior with cyclic references. As written in this article on php.net :
As far as I understand it, all cyclic references will be put in a buffer. When this buffer contains a certain number of garbage references PHP will start cleaning them. This is why your memory grows to @clue invested a lot of time in reactphp/promise to get rid of these cyclic garbage references in reactphp/promise#119, reactphp/promise#118 and more. This is also why reactphp/http behaves normal. I don't know if mysql creates cyclic garbage references, this needs some further investigation, but it would explain the behavior you're seeing. One thing I want to point out is that you're currently only looking at the resolved case when using the $loop->addPeriodicTimer(
1,
fn() => $connection->query('SELECT 1')->then(
function (\React\MySQL\QueryResult $result) {
echo count($result->resultRows) . PHP_EOL;
//some other actions
},
function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
})
); I think this should answer your question, this is why I'll close this ticket for now. |
Hello.
I wanna to create like a cron job for my application: every second select some data from table and do something with them, looks good, but have some troubles;
php -v
pecl list
Example:
I do not query anything in database, just select 1, but memory increase per request
Ill tested around a hour and can someone explain to me this behavior? Sometimes memory cleared.
Whats the magic 450 seconds?
Free memory after 450/900/1350/1800 seconds, not every 450 seconds, its arithmetic progression +450 per step
The text was updated successfully, but these errors were encountered: