php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60141 Consuming large amounts of memory
Submitted: 2011-10-26 15:24 UTC Modified: 2012-11-14 11:59 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:3 (60.0%)
From: steven_wright at mcafee dot com Assigned:
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.8 OS: Centos5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: steven_wright at mcafee dot com
New email:
PHP Version: OS:

 

 [2011-10-26 15:24 UTC] steven_wright at mcafee dot com
Description:
------------
amqp    0.3.1   beta

I have a script that runs a loop 10,000 times. In the loop I publish two messages. 
There are two consumers waiting in a while loop that get the messages using 
consume(). 

The script consumes about 10GB of RAM.

I am concerned about the amount of memory being used. 

The code that I pasted below should be placed into two separate files. Each one is 
run from the console. Start the consumer first.

Test script:
---------------
$cnnConfig = array("exchange" => "test-topic", "queue" => "test-queue", "hostname" => "localhost", "options" => array("type" => "topic", "autoDelete" => true));
$cnn = new AMQPConnection($cnnConfig);
$cnn->connect();
$logQ = new AMQPQueue($cnn);
$logQ->declare('log');
$logQ->bind($cnnConfig['exchange'], 'log');
$options = array('min' => 1,'max' => 10,'ack' => true);
while (true){$msg = $logQ->consume($options); var_dump($msg[0]['message_body']); }
// Producer code
$cnnConfig = array("exchange" => "test-topic", "queue" => "test-queue", "hostname" => "localhost", "options" => array("type" => "topic", "autoDelete" => true));
$cnn = new AMQPConnection($cnnConfig);
$cnn->connect();
$ex = new AMQPExchange($cnn, $cnnConfig['exchange']);
$ex->declare($cnnConfig['exchange'], $cnnConfig['options']['type'], $cnnConfig['options']['autoDelete']);
for ($i = 0; $i < 10000; $i++){
    $ex->publish('Message '.$i.' goes to test.log: ' . date("h:i:s"), 'log');
}

Expected result:
----------------
I expect that the script will echo the message 10,000 times.

string(36) "Message 0 goes to test.log: 11:19:04"
string(36) "Message 1 goes to test.log: 11:19:04"
string(37) "Message 2 goes to test.log: 11:19:04"

And so on.

Actual result:
--------------
[swright@vm1-centos5 rabbitmq]$ php rabbit-cons.php
string(36) "Message 0 goes to test.log: 11:19:04"
string(36) "Message 1 goes to test.log: 11:19:04"
string(37) "Message 11 goes to test.log: 11:19:04"
Killed




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-26 15:25 UTC] steven_wright at mcafee dot com
There is actually only one consumer in the code that I posted. Had to fit it into 
20 lines.
 [2011-11-21 21:01 UTC] jacolmode at wp dot pl
There seems to be a problem with consume() method, when there is a lot o messages 
in a queue.

Example:

consumer.php
<?php

include('config.php');

$amqp = new AMQPConnection($cfg['amqp']);
$amqp->connect();

$amqp_ex = new AMQPExchange($amqp);
$amqp_ex->declare($cfg['amqp']['exchange'],AMQP_EX_TYPE_TOPIC,AMQP_DURABLE);

$amqp_qu = new AMQPQueue($amqp);
$amqp_qu->declare($cfg['amqp']['queue'],AMQP_DURABLE); 
$amqp_qu->bind($cfg['amqp']['exchange'],'slave.#');

$i = 0;
while(true)
{
        $msgs = $amqp_qu->consume(array(
                'min' => 0,
                'max' => 10,
                'ack' => false
        ));

        foreach($msgs as $msg)
                $amqp_qu->ack($msg['delivery_tag']);

        if (!count($msgs))
                exit;
}


send.php - send 1000 messages



root@loc:~/php-amqp-bugs# php -f send.php 
root@loc:~/php-amqp-bugs# /usr/bin/time -f "%P %M" php -f consumer.php 
74% 1704880


That's 1704880 KB of RSS mem.
 [2011-11-21 21:04 UTC] jacolmode at wp dot pl
Forgot to add:

php5-amqp 0.3.1-1
php5-cli 5.3.3-7+squeeze3
php5-common 5.3.3-7+squeeze3
php5-suhosin 0.9.32.1-1

php5-amqp build with ibrabbitmq_1.0-1.20110925
 [2012-11-14 01:23 UTC] bkw at codingforce dot com
I doubt that this is relevant anymore. The library went through many changes 
since that.
 [2012-11-14 11:59 UTC] steven_wright at mcafee dot com
-Status: Open +Status: Closed
 [2012-11-14 11:59 UTC] steven_wright at mcafee dot com
Yes we have moved onto the newer library.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Apr 20 00:01:23 2021 UTC