MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / warnDBPoolUndersized

Function warnDBPoolUndersized

server-source-code/cmd/server/startup_checks.go:96–126  ·  view source on GitHub ↗

warnDBPoolUndersized emits a WARN log at startup when the active host count exceeds the configured DB connection pool limit by a meaningful margin. The default DB_CONNECTION_LIMIT (30) is fine for small deployments. Beyond ~50 hosts, synchronised report bursts can exhaust the pool and cause request

(
	ctx context.Context,
	cfg *config.Config,
	hostsStore *store.HostsStore,
	log *slog.Logger,
)

Source from the content-addressed store, hash-verified

94// count is not representative of any tenant's host count, and the per-tenant
95// pools are sized independently of cfg.DBConnectionLimit on the primary.
96func warnDBPoolUndersized(
97 ctx context.Context,
98 cfg *config.Config,
99 hostsStore *store.HostsStore,
100 log *slog.Logger,
101) {
102 if cfg.RegistryDatabaseURL != "" {
103 return // multi-host: per-tenant pool sizing is the wrong scope here
104 }
105 hosts, err := hostsStore.Count(ctx)
106 if err != nil {
107 return
108 }
109 if hosts <= dbPoolWarnHostThreshold {
110 return
111 }
112 recommended := recommendedDBPoolSize(hosts)
113 if cfg.DBConnectionLimit >= recommended {
114 return
115 }
116 log.Warn(
117 "database connection pool may be undersized for current host count",
118 "active_hosts", hosts,
119 "current_db_connection_limit", cfg.DBConnectionLimit,
120 "recommended_db_connection_limit", recommended,
121 "action", fmt.Sprintf(
122 "CONSIDER INCREASING DB_CONNECTION_LIMIT environment variable to %d (current: %d, active hosts: %d). With many hosts reporting concurrently, an undersized pool causes request queuing, retry backoff, and ultimately HTTP timeouts on agent reports.",
123 recommended, cfg.DBConnectionLimit, hosts,
124 ),
125 )
126}

Callers 1

mainFunction · 0.85

Calls 2

recommendedDBPoolSizeFunction · 0.85
CountMethod · 0.45

Tested by

no test coverage detected