max 25 conc connections (#691)

This commit is contained in:
Vikhyath Mondreti
2025-07-15 03:50:59 -07:00
committed by GitHub
parent bb759368d9
commit 0c5e70fc23

View File

@@ -11,25 +11,23 @@ const connectionString = env.POSTGRES_URL ?? env.DATABASE_URL
/**
* Connection Pool Allocation Strategy
*
* Main App (this file): 3 connections per instance
* Socket Server Operations: 2 connections
* Socket Server Room Manager: 1 connection
* Main App: 25 connections per instance
* Socket Server: 3 connections total
*
* With ~3-4 Vercel serverless instances typically active:
* - Main app: 3 × 4 = 12 connections
* - Socket server: 2 + 1 = 3 connections
* - Buffer: 5 connections for spikes/other services
* - Total: ~20 connections (at capacity limit)
*
* This conservative allocation prevents pool exhaustion while maintaining performance.
* - Main app: 25 × 4 = 100 connections
* - Socket server: 3 connections
* - Buffer: 25 connections
* - Total: ~128 connections
* - Supabase limit: 128 connections (16XL instance)
*/
const postgresClient = postgres(connectionString, {
prepare: false, // Disable prefetch as it is not supported for "Transaction" pool mode
idle_timeout: 20, // Reduce idle timeout to 20 seconds to free up connections faster
connect_timeout: 30, // Increase connect timeout to 30 seconds to handle network issues
max: 2, // Further reduced limit to prevent Supabase connection exhaustion
onnotice: () => {}, // Disable notices to reduce noise
prepare: false,
idle_timeout: 20,
connect_timeout: 30,
max: 25,
onnotice: () => {},
})
const drizzleClient = drizzle(postgresClient, { schema })