Any way to modify prefetch count for a running consumer?

1,798 views
Skip to first unread message

kacper....@gmail.com

unread,
May 4, 2017, 12:15:56 PM5/4/17
to rabbitmq-users
Hi everyone,

I have the following use case in my code: 

Channel channel = ...;
Consumer consumer = ...;
channel.basicQos(10); // some stored prefetch count
channel.basicConsume("my-queue", false, consumer);

// some time passes
// user wants to change prefetch count on running consumer
channel.basicQos(10);

This worked under an older version of the server - now the second call to basicQos(...) updates the prefetch count on just the channel while the prefetch count on the consumer stays the same as previous.

Is there any way to modify prefetch count for a running consumer?

Michael Klishin

unread,
May 4, 2017, 12:19:21 PM5/4/17
to rabbitm...@googlegroups.com, kacper....@gmail.com
Please take a look at https://www.rabbitmq.com/consumer-prefetch.html.
> --
> You received this message because you are subscribed to the Google Groups "rabbitmq-users"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
> To post to this group, send an email to rabbitm...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
MK

Staff Software Engineer, Pivotal/RabbitMQ


kacper....@gmail.com

unread,
May 4, 2017, 12:28:12 PM5/4/17
to rabbitmq-users, kacper....@gmail.com
I have - but I'm not sure I follow. Does this mean I would need to restart the consumer? Am I trying to use the client incorrectly?

Michael Klishin

unread,
May 4, 2017, 12:36:00 PM5/4/17
to rabbitm...@googlegroups.com, kacper....@gmail.com
"RabbitMQ redefines the meaning of the  global flag in the basic.qos method" in that guide
is followed by a table that mentions "all consumers" and "new consumers".

Configuring prefetch before consuming is perfectly fine but please take a look at the table in the docs.

On 4 May 2017 at 18:28:17, kacper....@gmail.com (kacper....@gmail.com) wrote:
> I have - but I'm not sure I follow. Does this mean I would need to restart
> the consumer? Am I trying to use the client incorrectly?
>
> On Thursday, May 4, 2017 at 12:19:21 PM UTC-4, Michael Klishin wrote:
> >
> > Please take a look at https://www.rabbitmq.com/consumer-prefetch.html.
> >
> > On 4 May 2017 at 18:16:01, kacper....@gmail.com <> (

kacper....@gmail.com

unread,
May 4, 2017, 1:32:43 PM5/4/17
to rabbitmq-users, kacper....@gmail.com
Just trying to understand this a bit more:

If I set global prefetch to 10
Start a consumer
Set global prefetch to 20
Will the consumer now prefetch 20? (RabbitMQ Admin panel shows consumer prefetch at 0, with is equal to the channel's prefetch count when the consumer was started)

If I set prefetch to 10
Start a consumer
Set global prefetch to 20
Will the consumer now prefetch 10 from the channels prefetch of 20? (RabbitMQ Admin panel shows consumer prefetch at 10)

If I set prefetch to 20
Start a consumer
Set global prefetch to 10
Will the consumer now effectively prefetch 10 as the channels is limited to a prefetch of 10?

I guess I am confused by the prefetch count shown for the consumer in the administration panel. Is it showing prefetch when started or effective prefetch?

Michael Klishin

unread,
May 4, 2017, 3:16:13 PM5/4/17
to rabbitm...@googlegroups.com, kacper....@gmail.com
There could be a discrepancy between what is emitted with stats events and the effective limiter value
but I cannot tell whether that's the case without trying to reproduce it and digging in the stats tables.

Just set it per channel before you register a consumer and move on. 

Kacper Harabasz

unread,
May 4, 2017, 3:43:34 PM5/4/17
to Michael Klishin, rabbitm...@googlegroups.com
I want to be able to tune prefetch count on the fly

> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
> To post to this group, send an email to rabbitmq-users@googlegroups.com.

Michael Klishin

unread,
May 4, 2017, 6:57:41 PM5/4/17
to Kacper Harabasz, rabbitm...@googlegroups.com
To accomplish what specifically?

> To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.

> To post to this group, send an email to rabbitm...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
MK

Staff Software Engineer, Pivotal/RabbitMQ


--
Staff Software Engineer, Pivotal/RabbitMQ

kacper....@gmail.com

unread,
May 5, 2017, 5:10:38 AM5/5/17
to rabbitmq-users, kacper....@gmail.com
The code consuming the messages has multiple threads. I want to be able to adjust the thread count on the fly, and I assumed I would also need to adjust the prefetch count on the fly as needed.


To be able to tune the code consuming the messages on the fly
Reply all
Reply to author
Forward
0 new messages