From 4ed6344b3d467258d6179132ab7242c9d1e89fc9 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 7 Jan 2022 18:06:46 -0800 Subject: [PATCH] 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.) --- src/server/db.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/db.js b/src/server/db.js index 97a5a6d..828382f 100644 --- a/src/server/db.js +++ b/src/server/db.js @@ -35,12 +35,13 @@ async function connectToDb({ } const db = mysql - .createConnection({ + .createPool({ host, user, password, database, multipleStatements: true, + connectionLimit: 10, }) // We upgrade to promises here, instead of using the mysql2/promise import, // for compatibility with Honeycomb's automatic tracing.