bschmitt / laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages
MIT License
270 stars 86 forks source link

Latest updates in php-amqplib/php-amqplib cause high CPU usage when using consume #63

Closed umbrella-artem-seryak closed 5 years ago

umbrella-artem-seryak commented 5 years ago

Hey guys,

Due to the latest updates in the php-amqplib/php-amqplib (I describe them in more details here) the current way consume method is implemented causes an infinite loop in case blocking is set to false(which it is by default). https://github.com/bschmitt/laravel-amqp/blob/master/src/Consumer.php#L73

This is due to the fact php-amqplib/php-amqplib disables timeouts for a non-blocking wait() (https://github.com/php-amqplib/php-amqplib/pull/642/files#diff-195c265ed9a66166715118df34df6ea3R339) and stops execution instead, leading to another wait cal, and so on, and so on.

You may probably want to reflect this in the documentation for consume to set that blocking => true in config, otherwise it may consume lots of CPU since php-amqplib 2.9.

mgriego commented 5 years ago

Just to piggyback on that, the blocking config option isn't really documented anywhere at all that I could see, but, given the latest changes, it's SUPER important for queue consumers.

stevenklar commented 5 years ago

@umbrella-artem-seryak do you see this as a issue of this library? Because if it is not we always need to keep up with the documentation of php-amqplib issues.

Or do you suggest a change in the Consumer? Please feel free to contribute and open a PR in case you got a suggestion.