A
A
Alexander2018-08-01 15:35:25
PHP
Alexander, 2018-08-01 15:35:25

RabbitMQ: The number of channels is growing. How to properly close channels?

Good day! I ran into the following problem - there is a server with RabbitMQ, json packets are periodically published to it, which are then taken by another server by a php script that runs on the crown once a minute. I noticed that after a certain period of time (depending on the current load on the project), the number of channels exceeds several tens of thousands, after which the server with RabbitMQ safely crashes and refuses to accept incoming connections.
In my code I use calls:

$channel->close();
$connection->close();

But it seems that there is no sense in closing the channel. How to overcome this problem?
Thanks in advance!
Below is the part of my code where the problem seems to be:
$connection = new AMQPStreamConnection($server, $port, $login, $pass);
$channel = $connection->channel();
$channel->queue_declare('q_output', false, true, false, false);
        
while($msg = $channel->basic_get("q_output", true)) {
        // тут полезная нагрузка
}

$channel->close();
$connection->close();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2018-08-01
@Sanasol

It is not clear how the code is run, how many times it is run, etc.
The code does not reach your close if the tasks are constantly flying fresh and the timeouts for dying in the absence of tasks are not configured.
But even indefinitely they should not be created by themselves. You obviously run the script endlessly with some kind of cron, so they hang.

I
Ivan Bogomolov, 2018-11-14
@kraso4niy

Maybe where you // have a payload here, the script runs for a long time and keeps the channel open. Then another one of the same is launched and also works for a long time ... and so many times, therefore tcp is clogged, cpu grows and everything falls.
You can rewrite the code so that after get before the payload, the channel is closed. And it's still not clear why you need while. Received one message and closed everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question