Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Messenger - AMQP Extension - auto_setup:true leads to poor performance on RabbitMq consumers #38092

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

Closed
dorinelpna opened this issue Sep 7, 2020 · 0 comments · Fixed by #39608

Comments

@dorinelpna
Copy link

dorinelpna commented Sep 7, 2020

Symfony version(s) affected: 5.*
Description
The transport configuration - auto_setup: true (that is the default) will try to create the exchange, the queue(s) and try to bind them, for every message retrieved from the queue, leading to low get/acknowledge rate.

AmqpExt\Connection.php

 /**
     * Gets a message from the specified queue.
     *
     * @throws \AMQPException
     */
    public function get(string $queueName): ?\AMQPEnvelope
    {
        $this->clearWhenDisconnected();

        **if ($this->shouldSetup()) {
            $this->setupExchangeAndQueues();
        }**

Possible Solution

if ($this->shouldSetup() && !in_array($queueName, $this->setupQueues)) {
            $this->setupExchangeAndQueues();
            array_push($this->setupQueues, $queueName);
        }

This means $this->setupExchangeAndQueues() will be called only once when starting the consumer instance.

If queue / exchange are deleted while consumer is running

/**
    * Gets a message from the specified queue.
    *
    * @throws \AMQPException
    */
   public function get(string $queueName): ?\AMQPEnvelope
   {
    ..........
    } catch (\AMQPQueueException $e) {
           if (404 === $e->getCode() && $this->shouldSetup()) {

                $this->clearWhenDisconnected();
               // If we get a 404 for the queue, it means we need to set up the exchange & queue.
               $this->setupExchangeAndQueues();

               return $this->get($queueName);
           }

           throw $e;
       } 
........

Additional context
Not sure if there are any cases when this issue can occur.
This issue is very possible to occur when sending messages also.

@dorinelpna dorinelpna added the Bug label Sep 7, 2020
@fabpot fabpot closed this as completed Jan 1, 2021
fabpot added a commit that referenced this issue Jan 1, 2021
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Messenger] Setup queues once in AMQP

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #39605, Fix #38092, Fix #32172
| License       | MIT
| Doc PR        | -

To ease the setup, this PR also merge setup of exchange AND delayExchange.

/cc @Nyholm

Commits
-------

c2e84c6 Setup queues once in AMQP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants