Last active
December 17, 2015 07:59
-
-
Save krakjoe/5576666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Jobs extends \Stackable { | |
function run() {} | |
} | |
class Job extends \Stackable { | |
function run() { | |
$this->isComplete = TRUE; | |
} | |
} | |
class MyWorker extends \Worker { | |
function run() {} | |
} | |
$jobs = []; | |
$worker = new MyWorker($jobs); | |
$worker->start(); | |
for ($i=0;;) { | |
$worker->stack($jobs[] = new Job); | |
if (!(++$i%500)) { | |
$mem = memory_get_usage(); | |
$stacked = $worker->getStacked(); | |
echo str_pad($i, 9), "mem usage: $mem | stack size: $stacked\n"; | |
// Manual garbage collection doesn't help; it only makes the code really slow without mitigating memory growth. | |
foreach ($jobs as $id => $job) { | |
if (is_object($job) && | |
$job->isComplete) { | |
unset( | |
$jobs[$id]); | |
} | |
} | |
} | |
} |
pastebin: http://pastebin.com/2cLf9Z5d
got to a silly number with no sign of letting up ...
will await feedback ... is new so might be errors still ... but I think much better/faster/easier to manage memory of now ...
spin off to create pool of workers & show tidy in production ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok at this point, with new changes, there's much improvement ... somehow at random points (I've seen 2 million tasks be executed sometimes, sometimes 300k), the stack still grows, so there's still a bug, but I'll get it eventually ... I will pastebin a log from an execution till it fails ...