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.
[go to top]