Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

memory leak when pthreads in pthreads #954

Open
Still4 opened this issue Nov 25, 2019 · 1 comment
Open

memory leak when pthreads in pthreads #954

Still4 opened this issue Nov 25, 2019 · 1 comment

Comments

@Still4
Copy link

Still4 commented Nov 25, 2019

<?php

$worker_num_total = 40;
$global_data = array();
$variables_list = array_pad(array(), 1000000, 0);
$variables = array_chunk($variables_list, 40);
foreach ($variables as $key => $chunks) {
    $pool = new \Pool($worker_num_total, \Worker::class);
    $pool->submit(new SecondThread($chunks));
    while (($worker_num = $pool->collect()) > 0) {
        usleep(100000);
    }
    $pool->shutdown();
    unset($pool);
    gc_collect_cycles();
}

class SecondThread extends \Thread
{

    private $chunks;

    public function __construct($chunks)
    {
        $this->chunks = $chunks;
    }

    public function run()
    {
        $pool = new \Pool(10, \Worker::class);
        foreach ($this->chunks as $chunk) {
            $pool->submit(new ThirdThread($chunk));
        }
        while (($worker_num = $pool->collect()) > 0) {
            usleep(100000);
        }
        $pool->shutdown();
        unset($pool);
        gc_collect_cycles();
    }

}

class ThirdThread extends \Thread
{

    private $chunk;

    public function __construct($chunk)
    {
        $this->chunk = $chunk;
    }

    public function run()
    {
        $this->chunk;
    }

}

?>

the first minute
image
about 5 mins later
image
about 10 mins later
image

@Still4
Copy link
Author

Still4 commented Nov 25, 2019

php versoin
PHP 7.2.6 (cli) (built: Jun 1 2018 07:54:23) ( ZTS )
pthread
3.1.7dev

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant