@teamkeel/functions-runtime 0.387.1-next.3 → 0.387.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/database.js +17 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/functions-runtime",
3
- "version": "0.387.1-next.3",
3
+ "version": "0.387.1",
4
4
  "description": "Internal package used by @teamkeel/sdk",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/database.js CHANGED
@@ -4,8 +4,8 @@ const { AuditContextPlugin } = require("./auditing");
4
4
  const pg = require("pg");
5
5
  const { PROTO_ACTION_TYPES } = require("./consts");
6
6
  const { withSpan } = require("./tracing");
7
- import { NeonDialect } from "kysely-neon";
8
- import ws from 'ws';
7
+ const { NeonDialect } = require("kysely-neon");
8
+ const ws = require("ws");
9
9
 
10
10
  // withDatabase is responsible for setting the correct database client in our AsyncLocalStorage
11
11
  // so that the the code in a custom function uses the correct client.
@@ -153,12 +153,25 @@ function getDialect() {
153
153
  return new PostgresDialect({
154
154
  pool: new InstrumentedPool({
155
155
  Client: InstrumentedClient,
156
+ // Increased idle time before closing a connection in the local pool (from 10s default).
157
+ // Establising a new connection on (almost) every functions query can be expensive, so this
158
+ // will reduce having to open connections as regularly. https://node-postgres.com/apis/pool
159
+ //
160
+ // NOTE: We should consider setting this to 0 (i.e. never pool locally) and open and close
161
+ // connections with each invocation. This is because the freeze/thaw nature of lambdas can cause problems
162
+ // with long-lived connections - see https://github.com/brianc/node-postgres/issues/2718
163
+ // Once we're "fully regional" this should not be a performance problem anymore.
164
+ //
165
+ // Although I doubt we will run into these freeze/thaw issues if idleTimeoutMillis is always shorter than the
166
+ // time is takes for a lambda to freeze (which is not a constant, but could be as short as several minutes,
167
+ // https://www.pluralsight.com/resources/blog/cloud/how-long-does-aws-lambda-keep-your-idle-functions-around-before-a-cold-start)
168
+ idleTimeoutMillis: 120000,
156
169
  connectionString: mustEnv("KEEL_DB_CONN"),
157
170
  }),
158
171
  });
159
172
  case "neon":
160
173
  return new NeonDialect({
161
- connectionString: "postgres://keel_runtime:vr3PuGQGb06I1Q0Daj6S9gFFq00zWso8@ep-dry-fog-a21c7eft-pooler.eu-central-1.aws.neon.tech/neondb?sslmode=require",// mustEnv("KEEL_DB_CONN"),
174
+ connectionString: mustEnv("KEEL_DB_CONN"),
162
175
  webSocketConstructor: ws,
163
176
  });
164
177
  default:
@@ -179,4 +192,4 @@ getDatabaseClient();
179
192
 
180
193
  module.exports.getDatabaseClient = getDatabaseClient;
181
194
  module.exports.useDatabase = useDatabase;
182
- module.exports.withDatabase = withDatabase;
195
+ module.exports.withDatabase = withDatabase;