Tạo pool connections sẵn, tái sử dụng thay vì mở/đóng mỗi query.
js
new Pool({ max: 20, idleTimeoutMillis: 30000 })Không có pooling: mỗi request mở connection mới → chậm, exhaust DB connections.
- Prisma, Sequelize tự quản lý pool.
- Monitor: active/idle/waiting connections.
A connection pool maintains a set of pre-opened connections and reuses them instead of opening/closing one per query. new Pool({ max: 20, idleTimeoutMillis: 30000 }).
- Without pooling: each request opens a new connection — slow and quickly exhausts the database's connection limit.
- ORMs like Prisma and Sequelize manage pools automatically.
- Monitor: active, idle, and waiting connection counts.