Bird
Raised Fist0
RabbitMQdevops~20 mins

Consumer prefetch optimization in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RabbitMQ Prefetch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does setting the prefetch count in RabbitMQ consumers control?

In RabbitMQ, consumers can set a prefetch count. What does this setting control?

AThe maximum number of messages sent to the consumer without receiving acknowledgments.
BThe total number of messages in the queue at any time.
CThe number of consumers connected to the queue.
DThe maximum size of the message payload the consumer can receive.
Attempts:
2 left
💡 Hint

Think about how many messages a consumer can work on before telling the server it finished.

💻 Command Output
intermediate
1:30remaining
What is the output of setting prefetch count to 1 in RabbitMQ consumer?

Consider a RabbitMQ consumer with prefetch count set to 1. What is the expected behavior?

AThe consumer receives all messages in the queue at once.
BThe consumer receives messages in batches of 10 by default.
CThe consumer receives one message at a time and must acknowledge it before receiving the next.
DThe consumer ignores acknowledgments and receives messages continuously.
Attempts:
2 left
💡 Hint

Prefetch count 1 means the consumer processes messages one by one.

❓ Configuration
advanced
2:00remaining
Which command correctly sets prefetch count to 5 using rabbitmqctl?

You want to limit a consumer's prefetch count to 5 using rabbitmqctl. Which command is correct?

Arabbitmqctl set_prefetch_count 5
Brabbitmqctl set_policy my_policy "^" '{"prefetch-count":5}' --apply-to consumers
Crabbitmqctl set_qos --prefetch-count=5
Drabbitmqctl set_qos -p / my_queue 5
Attempts:
2 left
💡 Hint

Prefetch count is set per channel or queue using set_qos command.

❓ Troubleshoot
advanced
2:00remaining
Why might a consumer with prefetch count 10 still get overwhelmed?

A consumer has prefetch count set to 10 but is still overwhelmed and slow. What could be the reason?

AThe consumer is not acknowledging messages, causing RabbitMQ to resend them.
BPrefetch count only limits messages per queue, not per consumer.
CThe consumer is using automatic acknowledgments, so prefetch count is ignored.
DThe queue has more than 10 messages, so prefetch count is ineffective.
Attempts:
2 left
💡 Hint

Think about what happens if messages are not acknowledged.

🔀 Workflow
expert
3:00remaining
Order the steps to optimize consumer prefetch for a high-throughput RabbitMQ system

Arrange the following steps in the correct order to optimize consumer prefetch settings for better throughput and stability.

A3,1,2,4
B1,3,2,4
C1,2,3,4
D2,1,3,4
Attempts:
2 left
💡 Hint

Start by understanding current performance before changing settings.

Practice

(1/5)
1.

What does setting the prefetch_count in RabbitMQ control?

easy
A. The number of producers connected
B. The total number of queues in RabbitMQ
C. The maximum size of a message
D. The number of messages a consumer can receive before acknowledging

Solution

  1. Step 1: Understand prefetch_count meaning

    The prefetch_count limits how many messages a consumer can get without acknowledging previous ones.
  2. Step 2: Relate to consumer message handling

    This setting helps control consumer load by limiting unacknowledged messages.
  3. Final Answer:

    The number of messages a consumer can receive before acknowledging -> Option D
  4. Quick Check:

    prefetch_count controls message flow to consumer = D [OK]
Hint: Prefetch limits unacknowledged messages per consumer [OK]
Common Mistakes:
  • Confusing prefetch_count with queue count
  • Thinking it limits message size
  • Assuming it controls producers
2.

Which of the following is the correct way to set prefetch_count to 10 using RabbitMQ's basic.qos command?

easy
A. channel.set_qos(10)
B. channel.prefetch(10)
C. channel.basic_qos(prefetch_count=10)
D. channel.qos(prefetch=10)

Solution

  1. Step 1: Recall RabbitMQ client method for QoS

    The correct method to set prefetch count is basic_qos with prefetch_count argument.
  2. Step 2: Match syntax with options

    channel.basic_qos(prefetch_count=10) uses channel.basic_qos(prefetch_count=10), which is the correct syntax.
  3. Final Answer:

    channel.basic_qos(prefetch_count=10) -> Option C
  4. Quick Check:

    basic_qos with prefetch_count sets limit = B [OK]
Hint: Use basic_qos(prefetch_count=number) to set prefetch [OK]
Common Mistakes:
  • Using incorrect method names like set_qos or prefetch
  • Passing wrong parameter names
  • Confusing method with queue settings
3.

Given the following Python code snippet using pika library, what will be the effect of setting prefetch_count=5?

channel.basic_qos(prefetch_count=5)
for method_frame, properties, body in channel.consume('task_queue'):
    process_message(body)
    channel.basic_ack(method_frame.delivery_tag)
medium
A. Consumer will receive up to 5 unacknowledged messages at a time
B. Consumer will receive only 1 message at a time
C. Consumer will receive all messages without limit
D. Consumer will reject messages after 5

Solution

  1. Step 1: Understand prefetch_count effect in code

    Setting prefetch_count=5 limits unacknowledged messages to 5 per consumer.
  2. Step 2: Analyze message flow in loop

    The consumer processes and acknowledges messages one by one but can hold up to 5 unacknowledged messages simultaneously.
  3. Final Answer:

    Consumer will receive up to 5 unacknowledged messages at a time -> Option A
  4. Quick Check:

    prefetch_count=5 means max 5 unacked messages = A [OK]
Hint: prefetch_count sets max unacked messages per consumer [OK]
Common Mistakes:
  • Thinking it limits to 1 message only
  • Assuming unlimited messages are received
  • Confusing reject with prefetch behavior
4.

Identify the issue in this RabbitMQ consumer code snippet that sets prefetch_count=0 and explain why it might cause problems:

channel.basic_qos(prefetch_count=0)
for method_frame, properties, body in channel.consume('queue'):
    process(body)
    channel.basic_ack(method_frame.delivery_tag)
medium
A. prefetch_count=0 disables prefetch, causing unlimited unacknowledged messages
B. prefetch_count=0 means no messages will be delivered
C. prefetch_count=0 causes syntax error
D. prefetch_count=0 limits to 1 message only

Solution

  1. Step 1: Understand prefetch_count=0 meaning

    Setting prefetch_count=0 disables the limit, allowing unlimited unacknowledged messages.
  2. Step 2: Explain potential problem

    This can overload the consumer with too many messages, causing memory or processing issues.
  3. Final Answer:

    prefetch_count=0 disables prefetch, causing unlimited unacknowledged messages -> Option A
  4. Quick Check:

    prefetch_count=0 means no limit, risk overload = A [OK]
Hint: prefetch_count=0 means unlimited messages, risky for consumers [OK]
Common Mistakes:
  • Thinking 0 means no messages delivered
  • Assuming it causes syntax error
  • Believing it limits to 1 message
5.

You have a slow consumer that processes messages in 10 seconds each. To optimize throughput without overloading it, which prefetch_count value is best if you want to keep the consumer busy but not overwhelmed?

hard
A. 1
B. 10
C. 100
D. 0

Solution

  1. Step 1: Analyze consumer speed and prefetch impact

    A slow consumer taking 10 seconds per message should have a prefetch count that allows some parallelism but avoids overload.
  2. Step 2: Choose prefetch_count to balance load

    Setting prefetch_count to 10 allows the consumer to receive up to 10 messages unacknowledged, keeping it busy without too many messages queued.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    Prefetch matches consumer speed for balance = C [OK]
Hint: Match prefetch to consumer speed to avoid overload [OK]
Common Mistakes:
  • Setting prefetch too low causing idle time
  • Setting prefetch too high causing overload
  • Using 0 which causes unlimited messages
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard