Hey, I'm looking for concurrently calling a PostgreSQL database.
Each request is really simple, and is fast to execute (individually) according to EXPLAIN ANALYZE: Execution Time: 0.043 ms.
var wg sync.WaitGroup
wg.Add(8)
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
go func() { go d.db.First(&sponsors); wg.Done() }()
wg.Wait()
Each query is so simple, I expect 8 concurrent queries to be almost as fast as 1 query, if it really calls concurrently. Except the first query is relatively fast (200ms, network is the bottleneck) but executing all of them takes 1.6s.
As a reference, if I execute the one of these requests in my local DB administration tool (Postico), it shows 120ms.
2021/04/10 03:03:18 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[253.060ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:18 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[991.458ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1122.117ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1126.283ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1125.981ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1127.910ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1129.831ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
2021/04/10 03:03:19 /usr/local/go/src/runtime/asm_amd64.s:1371 SLOW SQL >= 200ms
[1129.891ms] [rows:1] SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1
EXPLAIN ANALYZE SELECT * FROM "sponsor" ORDER BY "sponsor"."id" LIMIT 1;
Limit (cost=0.29..0.48 rows=1 width=137) (actual time=0.022..0.023 rows=1 loops=1)
-> Index Scan using sponsor_pkey on sponsor (cost=0.29..6336.49 rows=32283 width=137) (actual time=0.021..0.021 rows=1 loops=1)
Planning Time: 0.102 ms
Execution Time: 0.043 ms
Am I misunderstanding that the whole thing should take around [120ms, 200ms], and not 1.6s? If so, what's the incorrect assumption?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: alimoli
Any update here?