-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ const { AuditContextPlugin } = require("./auditing"); | |
const pg = require("pg"); | ||
const { PROTO_ACTION_TYPES } = require("./consts"); | ||
const { withSpan } = require("./tracing"); | ||
import { NeonDialect } from "kysely-neon"; | ||
import ws from 'ws'; | ||
|
||
// withDatabase is responsible for setting the correct database client in our AsyncLocalStorage | ||
// so that the the code in a custom function uses the correct client. | ||
|
@@ -148,27 +150,34 @@ function getDialect() { | |
return parseFloat(val); | ||
}); | ||
|
||
return new PostgresDialect({ | ||
pool: new InstrumentedPool({ | ||
Client: InstrumentedClient, | ||
// Increased idle time before closing a connection in the local pool (from 10s default). | ||
// Establising a new connection on (almost) every functions query can be expensive, so this | ||
// will reduce having to open connections as regularly. https://node-postgres.com/apis/pool | ||
// | ||
// NOTE: We should consider setting this to 0 (i.e. never pool locally) and open and close | ||
// connections with each invocation. This is because the freeze/thaw nature of lambdas can cause problems | ||
// with long-lived connections - see https://github.com/brianc/node-postgres/issues/2718 | ||
// Once we're "fully regional" this should not be a performance problem anymore. | ||
// | ||
// Although I doubt we will run into these freeze/thaw issues if idleTimeoutMillis is always shorter than the | ||
// time is takes for a lambda to freeze (which is not a constant, but could be as short as several minutes, | ||
// https://www.pluralsight.com/resources/blog/cloud/how-long-does-aws-lambda-keep-your-idle-functions-around-before-a-cold-start) | ||
idleTimeoutMillis: 0, | ||
connectionTimeoutMillis: 0, | ||
connectionString: mustEnv("KEEL_DB_CONN"), | ||
}), | ||
return new NeonDialect({ | ||
connectionString: "postgresql://neondb_owner:[email protected]/neondb?sslmode=require",//mustEnv("KEEL_DB_CONN"), | ||
webSocketConstructor: ws, | ||
}); | ||
|
||
// return new PostgresDialect({ | ||
// connectisonString: mustEnv("KEEL_DB_CONN"), | ||
// client: new InstrumentedClient, | ||
// // pool: new InstrumentedPool({ | ||
// // Client: InstrumentedClient, | ||
// // // Increased idle time before closing a connection in the local pool (from 10s default). | ||
// // // Establising a new connection on (almost) every functions query can be expensive, so this | ||
// // // will reduce having to open connections as regularly. https://node-postgres.com/apis/pool | ||
// // // | ||
// // // NOTE: We should consider setting this to 0 (i.e. never pool locally) and open and close | ||
// // // connections with each invocation. This is because the freeze/thaw nature of lambdas can cause problems | ||
// // // with long-lived connections - see https://github.com/brianc/node-postgres/issues/2718 | ||
// // // Once we're "fully regional" this should not be a performance problem anymore. | ||
// // // | ||
// // // Although I doubt we will run into these freeze/thaw issues if idleTimeoutMillis is always shorter than the | ||
// // // time is takes for a lambda to freeze (which is not a constant, but could be as short as several minutes, | ||
// // // https://www.pluralsight.com/resources/blog/cloud/how-long-does-aws-lambda-keep-your-idle-functions-around-before-a-cold-start) | ||
// // idleTimeoutMillis: 0, | ||
// // connectionTimeoutMillis: 0, | ||
// // connectionString: mustEnv("KEEL_DB_CONN"), | ||
// // }), | ||
// }); | ||
|
||
default: | ||
throw Error("unexpected KEEL_DB_CONN_TYPE: " + dbConnType); | ||
} | ||
|