Skip to content

Instantly share code, notes, and snippets.

@krakjoe
Last active December 17, 2015 07:59
Show Gist options
  • Save krakjoe/5576666 to your computer and use it in GitHub Desktop.
Save krakjoe/5576666 to your computer and use it in GitHub Desktop.
<?php
class Jobs extends \Stackable {
function run() {}
}
class Job extends \Stackable {
function run() {
$this->isComplete = TRUE;
}
}
class MyWorker extends \Worker {
function run() {}
}
$jobs = new Jobs;
$worker = new MyWorker($jobs);
$worker->start();
for ($i=0;;) {
$worker->stack($jobs[$i] = new Job);
$stacked = $worker->getStacked();
if (!(++$i%500)) {
$mem = memory_get_usage();
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 ($job->isComplete) {
unset($jobs[$id]);
}
}
}
}
@krakjoe
Copy link
Author

krakjoe commented May 14, 2013

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 ...

@krakjoe
Copy link
Author

krakjoe commented May 14, 2013

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 ...

@krakjoe
Copy link
Author

krakjoe commented May 14, 2013

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