mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

Backpressure with `QueueIterator` #440

Open decorator-factory opened 2 years ago

decorator-factory commented 2 years ago

I looked at how QueueIterator is implemented and I have a question: https://github.com/mosquito/aio-pika/blob/master/aio_pika/queue.py#L389

This is how it works, as I understand it:

  1. we start a background task consuming all the messages we can get
  2. in __anext__, we pop one item from the queue if there is one

If messages are incoming at a faster rate than they're being consumed from the iterator, won't messages pile up in memory, potentially consuming a lot of RAM? Or am I misunderstanding something?

mosquito commented 2 years ago

Generally I setting QoS for the channel.