zlacker

[return to "Choose Postgres queue technology"]
1. aduffy+82[view] [source] 2023-09-24 20:41:49
>>bo0tzz+(OP)
For several projects I’ve opted for the even dumber approach, that works out of the box with every ORM/Query DSL framework in every language: using a normal table with SELECT FOR UPDATE SKIP LOCKED

https://www.pgcasts.com/episodes/the-skip-locked-feature-in-...

It’s not “web scale” but it easily extends to several thousand background jobs in my experience

◧◩
2. orange+r8[view] [source] 2023-09-24 21:27:19
>>aduffy+82
As I understand, with SKIP LOCKED rows would no longer be processed in-order?
◧◩◪
3. riku_i+mf[view] [source] 2023-09-24 22:30:09
>>orange+r8
article says he also uses "order by" clause, but I am wondering if it will severely limit throughput since all messages will need to be sorted on each lookup, but this probably can be solved by introducing index.
◧◩◪◨
4. vore+Sl[view] [source] 2023-09-24 23:38:48
>>riku_i+mf
It seems strictly worse to use ORDER BY in this case, since if you're using SKIP LOCKED you should be doing parallel processing anyway, and if you're doing parallel processing, ordering is already going out the window.
◧◩◪◨⬒
5. nsonha+an[view] [source] 2023-09-24 23:53:41
>>vore+Sl
Parallel or not, the order is of importance in any queue system.
◧◩◪◨⬒⬓
6. sarche+4x[view] [source] 2023-09-25 01:52:51
>>nsonha+an
Unless you can guarantee that the processing time of each job is exactly the same, if you have multiple workers processing the same queue, you can’t order anything except the start time.

You can use locks to effectively break the queue into sub queues so that each sub queue is only being processed by 1 worker. Then you can order that sub queue.

◧◩◪◨⬒⬓⬔
7. nsonha+xA[view] [source] 2023-09-25 02:37:01
>>sarche+4x
job should be attempted inthe same order/priority they are enqueued, that's the meaning of the word "queue". That they take varrying amounts of time is another matter.
◧◩◪◨⬒⬓⬔⧯
8. worthl+lF[view] [source] 2023-09-25 03:29:38
>>nsonha+xA
Queue can clearly mean "work that needs to be completed" not necessarily 'work completed in order'. Your definition is much stricter than it needs to be for most use cases.
◧◩◪◨⬒⬓⬔⧯▣
9. nsonha+B31[view] [source] 2023-09-25 08:29:13
>>worthl+lF
There is clearly a conceptual difference between a set of things from which you pull things out randomly, and a queue. A queue always has intrinsic criteria to select the next item to be pulled out.
◧◩◪◨⬒⬓⬔⧯▣▦
10. sarche+0s1[view] [source] 2023-09-25 12:07:24
>>nsonha+B31
There are many times when the start order doesn’t really matter, and the additional sorting overhead isn’t worth it. In those cases people will still tend to refer to the entity holding the jobs to be processed as a queue despite the fact that it doesn’t strictly follow FIFO order.

If they are being technically precise, queue isn’t the correct term, but language changes with context and time. Either way the implementation isn’t wrong if strict start order has been considered and isn’t important.

◧◩◪◨⬒⬓⬔⧯▣▦▧
11. nsonha+if4[view] [source] 2023-09-26 01:27:06
>>sarche+0s1
you're confusing between "i don't care about order", and "there is no order". Name ONE queue implementation that doesn't have order.
◧◩◪◨⬒⬓⬔⧯▣▦▧▨
12. sarche+Ow5[view] [source] 2023-09-26 12:10:45
>>nsonha+if4
Here you go. One of the first tutorials explaining how SKIP LOCKED works in Postgres implants a job “queue” that doesn’t have an order by clause. https://www.pgcasts.com/episodes/the-skip-locked-feature-in-...

I’m not confusing anything. I’ve seen random selection “job queues” implemented many times. As long as you truly don’t care about start order, it’s fine to trade it for increased throughout.

◧◩◪◨⬒⬓⬔⧯▣▦▧▨◲
13. nsonha+Ih8[view] [source] 2023-09-27 01:42:09
>>sarche+Ow5
> doesn’t have an “order by” clause

Does that mean it doesn't have any order or that whoever writes the query doesn't care about order?

Also we are arguing over whether pg suffices as a queue implementation, and you use itself as an example?

◧◩◪◨⬒⬓⬔⧯▣▦▧▨◲◳
14. sarche+c4b[view] [source] 2023-09-27 18:49:16
>>nsonha+Ih8
It means that you are telling pg that you don’t care about order, so it is free to optimize the query in whatever way it wants to. The order can change query to query depending on numerous external factors.

I’m not using pg itself as an example. I’m using a specific implementation of a “job queue” built with pg.

I’ve seen and you can search for and find many implementations of “job queues” using relational databases where job start order guarantees are traded away for throughput.

[go to top]