friends-of-reactphp / stomp

STOMP bindings for ReactPHP.
MIT License
115 stars 42 forks source link

Memory leak #29

Open Lelya opened 11 years ago

Lelya commented 11 years ago

Hi! When I worked on this test, I have a problem - memory leak.



require __DIR__.'/../vendor/autoload.php';
$conf = require __DIR__ . '/config/apollo.php';

$loop = React\EventLoop\Factory::create();
$factory = new React\Stomp\Factory($loop);
$client = $factory->createClient($conf);

$client
    ->connect()
    ->then(function ($client) use ($loop) {
        $prevMessageCount = 0;
        $messageCount = 0;
        $loop->addPeriodicTimer(1, function () use (&$i, $client, &$messageCount) {     
        for ($i = 0; $i < 3000; $i++) {
                       $client->send('/queue/migration', 'Hello! This id message number '.$messageCount);
            echo "Posted this message: 'Hello! This id message number'.$messageCount.'\n";  
            $messageCount++;
            $kmem = memory_get_usage(true) / 1024;
            $mem  = memory_get_usage() / 1024;
            echo "Request: $i\n";
            echo "Memory: $mem KiB\n";
            echo "Real Memory: $kmem KiB\n";     
                }
        });
        $loop->addPeriodicTimer(1, function () use (&$prevMessageCount, &$messageCount) {
            $diff = $messageCount - $prevMessageCount;
            echo "Sent this second: $diff\n";
            $prevMessageCount = $messageCount;
        });
    }, function (\Exception $e) {
        echo sprintf("Could not connect: %s\n", $e->getMessage());
    });

$loop->run();

Testing my client with one listener. Different tests. When you send 100 messages per second, there is no memory leak. When posting more than 500 messages per second memory leaks in an arithmetic progression.

How can fix it?

igorw commented 11 years ago

Are you sure all of the 500 messages per second are being delivered? If there is an I/O bottleneck then they may be queued, leading memory to grow.