NeonN
Neon2y ago
36 replies
spotty-amber

Increased duration in queries using Pool on Lambda

I have being playing more with Neon Pool driver and found that on Vercel Serverless Function (Lambda), the queries take significantly longer.

I'm using drizzle for this test and wrote 2 instances to test with.
1) Edge compatible Pool Driver
import { neonConfig, Pool } from "@neondatabase/serverless"
import { drizzle } from "drizzle-orm/neon-serverless"

if (!process.env.VERCEL_ENV) {
  neonConfig.wsProxy = (host) => `${host}:5433/v1`
  neonConfig.useSecureWebSocket = false
  neonConfig.pipelineTLS = false
  neonConfig.pipelineConnect = false
}

export const getDb = () => {
  const pool = new Pool({ connectionString: process.env.DATABASE_URL })
  return {
    db: drizzle(pool),
    [Symbol.asyncDispose]: async () => {
      console.log("disposing pool")
      return await pool.end()
    },
  }
}


2) Normal Drizzle Adapter for Lambda
import { drizzle } from "drizzle-orm/postgres-js"
import postgres from "postgres"

export const db = drizzle(postgres(process.env.DATABASE_URL)) 
Was this page helpful?