Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit43d1f72

Browse files
authored
chore: Implement database limits from v1 (#4669)
Under scale if there wasn't a PostgreSQL connection available,an error was occurring instead of blocking for a new connection.This fixes it!
1 parent7c238f1 commit43d1f72

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎coderd/database/db.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ type DBTX interface {
4242
// New creates a new database store using a SQL database connection.
4343
funcNew(sdb*sql.DB)Store {
4444
dbx:=sqlx.NewDb(sdb,"postgres")
45+
46+
// The default is 0 but the request will fail with a 500 if the DB
47+
// cannot accept new connections, so we try to limit that here.
48+
// Requests will wait for a new connection instead of a hard error
49+
// if a limit is set.
50+
dbx.SetMaxOpenConns(40)
51+
// Allow a max of 3 idle connections at a time. Lower values end up
52+
// creating a lot of connection churn. Since each connection uses about
53+
// 10MB of memory, we're allocating 30MB to Postgres connections per
54+
// replica, but is better than causing Postgres to spawn a thread 15-20
55+
// times/sec. PGBouncer's transaction pooling is not the greatest so
56+
// it's not optimal for us to deploy.
57+
//
58+
// This was set to 10 before we started doing HA deployments, but 3 was
59+
// later determined to be a better middle ground as to not use up all
60+
// of PGs default connection limit while simultaneously avoiding a lot
61+
// of connection churn.
62+
dbx.SetMaxIdleConns(3)
63+
4564
return&sqlQuerier{
4665
db:dbx,
4766
sdb:dbx,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp