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 usage - perhaps a wee leak #33

Open
cliveza opened this issue Jun 19, 2015 · 0 comments
Open

Memory usage - perhaps a wee leak #33

cliveza opened this issue Jun 19, 2015 · 0 comments

Comments

@cliveza
Copy link

cliveza commented Jun 19, 2015

When I run the code below (the run() function) I can see memory of the parent php process continually growing, I get the following when the code starts:

PHP Notice:  unserialize(): Error at offset 0 of 74 bytes in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php on line 59
PHP Warning:  shmop_open(): unable to get shared memory segment information in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php on line 89
PHP Warning:  Invalid argument supplied for foreach() in vendor/kriswallsmith/spork/src/Spork/Fork.php on line 97

And eventually when the machine runs out of memeory I get this:

PHP Warning:  shmop_open(): unable to attach or create shared memory segment in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php on line 89
PHP Fatal error:  Uncaught exception 'Spork\Exception\ProcessControlException' with message 'Not able to create shared memory segment for PID: 14390' in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php:91
Stack trace:
#0 vendor/kriswallsmith/spork/src/Spork/ProcessManager.php(119): Spork\SharedMemory->send(Object(Spork\Util\ExitMessage), false)
#1 [internal function]: Spork\ProcessManager->Spork\{closure}()
#2 {main}
  thrown in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php on line 91
PHP Fatal error:  Uncaught exception 'Spork\Exception\ProcessControlException' with message 'Not able to create shared memory segment for PID: 14395' in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php:91
Stack trace:
#0 kriswallsmith/spork/src/Spork/ProcessManager.php(119): Spork\SharedMemory->send(Object(Spork\Util\ExitMessage), false)
#1 [internal function]: Spork\ProcessManager->Spork\{closure}()
#2 {main}
  thrown in vendor/kriswallsmith/spork/src/Spork/SharedMemory.php on line 91

If I take out the spork code and run the code sequentially then the memory stays constant.

I've tried poking around in the spork library, but haven't had any luck. Any ideas or pointers?

//in constructor
$this->manager = new ProcessManager();

// I run this 
public function run() 
{
    while (self::$enabled) {
        if (count($this->workers) >= $this->workerLimit) {
            $this->cleanUpWorkers();
        }   

        $job    = $this->fetchJobFromQueue();
        $worker = $this->findWorkerForJob($job);

        if ( ! $worker) {
            throw new \Exception("Could not find worker for {$job[0]} job");
        }

        $worker = $this->manager->fork($worker);

        $this->workers[$worker->getPid()] = $worker;
    } 
}

private function cleanUpWorkers()
{
    $this->manager->check();

    foreach($this->workers as $pid => $worker) {
        $worker->wait();

        if ($worker->isExited()) {
            unset($this->workers[$pid]);
        }
    }

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

No branches or pull requests

1 participant