File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,25 @@ type DBTX interface {
42
42
// New creates a new database store using a SQL database connection.
43
43
func New (sdb * sql.DB ) Store {
44
44
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
+
45
64
return & sqlQuerier {
46
65
db : dbx ,
47
66
sdb : dbx ,
You can’t perform that action at this time.
0 commit comments