-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Labels
Description
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
PHP 8.1.8 (cli) (built: Jul 26 2022 02:04:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.8, Copyright (c) Zend Technologies
with Zend OPcache v8.1.8, Copyright (c), by Zend Technologies
with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans
pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
event 3.0.8 stable
Example:
<?php
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() => $connection->query('SELECT 1')
->then(function (\React\MySQL\QueryResult $result) {
echo count($result->resultRows) . PHP_EOL;
//some other actions
})
);
// for diagnostic
$loop->addPeriodicTimer(1, function () {
echo sprintf(
'[%s] Current usage %f mb, Max: %f mb' . PHP_EOL,
(new \DateTime())->getTimestamp(),
round(memory_get_usage() / 1024 / 1024, 2) . ' mb',
round(memory_get_peak_usage() / 1024 / 1024, 2) . ' mb'
);
});
$loop->run():
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
[1670340928] Current usage 3.850000 mb, Max: 4.480000 mb
[1670340929] Current usage 4.200000 mb, Max: 4.480000 mb
[1670340930] Current usage 4.220000 mb, Max: 4.480000 mb
....
[1670341379] Current usage 14.960000 mb, Max: 14.990000 mb
[1670341380] Current usage 14.990000 mb, Max: 15.010000 mb
// After 453 seconds
[1670341381] Current usage 4.360000 mb, Max: 15.060000 mb
[1670341382] Current usage 4.380000 mb, Max: 15.060000 mb
...
[1670342286] Current usage 25.850000 mb, Max: 25.880000 mb
[1670342287] Current usage 25.880000 mb, Max: 25.900000 mb
[1670342288] Current usage 25.900000 mb, Max: 25.930000 mb
// Again, after 900 seconds since last 'memory free'
[1670342289] Current usage 4.520000 mb, Max: 25.930000 mb
[1670342290] Current usage 4.540000 mb, Max: 25.930000 mb
[1670342291] Current usage 4.570000 mb, Max: 25.930000 mb
...
[1670343648] Current usage 36.640000 mb, Max: 36.660000 mb
[1670343649] Current usage 36.660000 mb, Max: 36.680000 mb
[1670343650] Current usage 36.680000 mb, Max: 36.710000 mb
// Again, after 1350 seconds since last 'memory free'
[1670343651] Current usage 4.600000 mb, Max: 36.720000 mb
[1670343652] Current usage 4.620000 mb, Max: 36.720000 mb
[1670343653] Current usage 4.640000 mb, Max: 36.720000 mb