Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 4a3f35b

Browse files
committed
Cap max number of connections used by default
Cap to 50 connections
1 parent 4cd2e6c commit 4a3f35b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/pgclient/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ func (cfg *Config) GetNumConnections() (min int, max int, numCopiers int, err er
146146
log.Warn("msg", "database can only handle 1 connection")
147147
return 1, 1, 1, nil
148148
}
149-
// we try to only use 80% the database connections
149+
// we try to only use 80% the database connections, capped at 50
150150
max = int(0.8 * float32(max))
151+
if max > 50 {
152+
max = 50
153+
}
151154
}
152155

153156
// we want to leave some connections for non-copier usages, so in the event
@@ -160,8 +163,8 @@ func (cfg *Config) GetNumConnections() (min int, max int, numCopiers int, err er
160163
}
161164

162165
numCopiers = perProc * maxProcs
163-
// we leave one connection per-core for non-copier usages
164-
if numCopiers+maxProcs > max {
166+
// we try to leave one connection per-core for non-copier usages, otherwise using half the connections.
167+
if numCopiers > max-maxProcs {
165168
log.Warn("msg", fmt.Sprintf("had to reduce the number of copiers due to connection limits: wanted %v, reduced to %v", numCopiers, max/2))
166169
numCopiers = max / 2
167170
}

0 commit comments

Comments
 (0)