4 ms·
Why would it be preferable for it to be unbounded? Bounds let you have a `try_push` function that can obviously fail, whereas with unbounded you can only reall
by secondcoming 4y ago
Why would it be preferable for it to be unbounded?
Bounds let you have a `try_push` function that can obviously fail, whereas with unbounded you can only really know it failed because of OOM, or your producer thread gets blocked.
When `try_push` failure happens you know something strange is happening in your code.
- amelius 4y agoUnbounded can also have a try_push() functionality. Unbounded is preferable because that's how we do everything else, and best prepares for porting to larger architectures. Do your strings have a maximum size, for example?
- secondcoming 4y agoIn what circumstances would a ‘try_push’ fail on an unbounded queue? On a bounded queue it would fail when the queue is full. The size of the queue can be read from a config file, and is tuned to the capability of the machine.
- amelius 4y ago> In what circumstances would a ‘try_push’ fail on an unbounded queue? When you have an out-of-memory situation. The thing you are trying to express is that you want a queue that stops working only when it physically can't work. Putting arbitrary large numbers in config files is not the way to express it.
- secondcoming 4y agoSo then your program gets killed. Using a bounded queue let's you handle these situations gracefully and then you can tie these errors to alerts, which are then tied to a scaling policy.
- anonymoushn 4y agoThis doesn't seem correct. What if, for example, the long-running tasks would like to allocate memory, and they cannot because the user has clicked the button a few billion times? In that case, it seems like perhaps we should have accepted fewer jobs, so that we would be able to perform the ones we accepted.
- detinho 4y agoIf the only thing you need to allocate memory to is your queue, then maybe. Otherwise you'd incur in problems like the sibling comment. That's the very same reason you limit connection pools on applications that connect to a database: to prevent some instance to use all the database server connections and leave nothing to other instances.
- imtringued 4y agoWe have bounded queues because consumers and producers can consume at different rates. An unbounded queue will have the producer fill up main memory and then you need to do load shedding which turned the whole unbounded story into a lie.