zlacker

[parent] [thread] 11 comments
1. pauldd+(OP)[view] [source] 2023-09-24 21:33:30
USE. ADVISORY. LOCKS.

Do not use SKIP LOCKED unless it is a toy/low throughout.

Row locks require transactions and disk writes.

Advisory locks require neither. (However, you do have to stay inside the configurable memory budget.)

replies(4): >>ukd1+D3 >>mikeoc+i5 >>sorent+G9 >>klysm+Ub
2. ukd1+D3[view] [source] 2023-09-24 22:08:04
>>pauldd+(OP)
Maybe it's changed in the last year or so, but from benchmarking and writing / running queue software for Postgres - SKIP LOCKED was/is significantly faster. Is that different for MySQL?
3. mikeoc+i5[view] [source] 2023-09-24 22:22:05
>>pauldd+(OP)
Pretty common advice for scaling Postgres is to deploy pgbouncer in transaction mode in front of it to handle connection pooling.

Advisory locks don’t work in this setup (and will start behaving in strange ways if you do try to use them.) Something to consider if you go this route.

replies(2): >>ris+N8 >>pauldd+TA2
◧◩
4. ris+N8[view] [source] [discussion] 2023-09-24 22:54:57
>>mikeoc+i5
Transaction-scoped advisory locks are very much a thing too.
5. sorent+G9[view] [source] 2023-09-24 23:02:12
>>pauldd+(OP)
To do anything safe and interesting you’ll need transactions. Using SKIP LOCKED won’t be your bottleneck, your application will. Job queues are about side effects and the rest of your application needs to keep up.

Oban is able to run over 1m jobs a minute, and the ultimate bottleneck is throttling in application code to prevent thrashing the database: https://getoban.pro/articles/one-million-jobs-a-minute-with-...

replies(1): >>pauldd+xm
6. klysm+Ub[view] [source] 2023-09-24 23:30:29
>>pauldd+(OP)
Not all use cases are high throughput. That’s not what makes it a toy
replies(1): >>pauldd+2d
◧◩
7. pauldd+2d[view] [source] [discussion] 2023-09-24 23:43:12
>>klysm+Ub
"Toy/low throughput" = "Toy or low throughout"
replies(1): >>djur+EF
◧◩
8. pauldd+xm[view] [source] [discussion] 2023-09-25 01:40:43
>>sorent+G9
That's true.

However in the empty poll case, you can avoid a transaction.

◧◩◪
9. djur+EF[view] [source] [discussion] 2023-09-25 05:42:31
>>pauldd+2d
Can you define "low throughput"? I think people have significantly different ideas of what that means.
replies(2): >>klysm+q03 >>pauldd+T73
◧◩
10. pauldd+TA2[view] [source] [discussion] 2023-09-25 17:19:55
>>mikeoc+i5
Depends. That has more to do with how your're scaling application servers.
◧◩◪◨
11. klysm+q03[view] [source] [discussion] 2023-09-25 19:07:12
>>djur+EF
Yeah I think people generally reach for “big” tools when this “toy” would work fine for the vast majority of projects.
◧◩◪◨
12. pauldd+T73[view] [source] [discussion] 2023-09-25 19:39:37
>>djur+EF
> Can you define "low throughput"?

IDK maybe <1000 messages per minute

Not saying SKIP LOCKED can't work with that many. But you'll probably want to do something with lower overhead.

FWIW, Que uses advisory locks [1]

[1] https://github.com/que-rb/que

[go to top]