Use a connection pool

This should both fix cases where the connection closes for various reasons, by having the pool reconnect; and also should be a second way of solving some of the blocking issues we were having with large queries, by letting faster queries use parallel connections.

Idk what a reasonable number is, 10 seems to be what various guides are saying? Might tune it down if it ends up pushing various connection limits? (We could also constrain it on dev specifically, if that matters.)
This commit is contained in:
Emi Matchu 2022-01-07 18:06:46 -08:00
parent ca812784a6
commit 4ed6344b3d

View file

@ -35,12 +35,13 @@ async function connectToDb({
} }
const db = mysql const db = mysql
.createConnection({ .createPool({
host, host,
user, user,
password, password,
database, database,
multipleStatements: true, multipleStatements: true,
connectionLimit: 10,
}) })
// We upgrade to promises here, instead of using the mysql2/promise import, // We upgrade to promises here, instead of using the mysql2/promise import,
// for compatibility with Honeycomb's automatic tracing. // for compatibility with Honeycomb's automatic tracing.