@tumbaland/backend-core 1.55.0 → 1.56.0
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.
- package/dist/database/connection.d.ts +16 -16
- package/dist/database/connection.js +16 -16
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ConnectOptions } from 'mongoose';
|
|
2
2
|
/**
|
|
3
|
-
* How the pool behaves
|
|
3
|
+
* How the pool behaves, so a burst of requests does not pay for opening connections.
|
|
4
4
|
*
|
|
5
|
-
* Measured, not assumed:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* requests pay for it badly:
|
|
5
|
+
* Measured, not assumed: against a database across the internet (the hosted one
|
|
6
|
+
* this replaced) a lookup took about 17 ms on a warm connection and 850 to
|
|
7
|
+
* 1,370 ms on a cold one, so distance was not the cost. Opening a connection was.
|
|
8
|
+
* It is a TCP and TLS handshake and an authentication, from a small machine, and
|
|
9
|
+
* the driver defaults make a burst of requests pay for it badly:
|
|
10
10
|
*
|
|
11
11
|
* - It keeps no connections open, and an idle one is eventually dropped by
|
|
12
|
-
* something
|
|
13
|
-
*
|
|
12
|
+
* something on the way, so the first request after a quiet spell starts from
|
|
13
|
+
* nothing.
|
|
14
14
|
* - It opens at most two connections at a time. Opening a thread sends five or
|
|
15
15
|
* six requests at once, so they queued behind each other, a second or so per
|
|
16
16
|
* pair, and the thread took three to seven seconds.
|
|
@@ -20,8 +20,8 @@ import { ConnectOptions } from 'mongoose';
|
|
|
20
20
|
* - `maxConnecting` lets the pool open several at once when it does need more.
|
|
21
21
|
* - `maxIdleTimeMS` retires a connection that has sat idle for a few minutes,
|
|
22
22
|
* before something else kills it, and the pool opens a fresh one in its place.
|
|
23
|
-
* - `family: 4` skips the IPv6 half of every hostname lookup.
|
|
24
|
-
* a resolver that is slow to answer for AAAA delays every new connection.
|
|
23
|
+
* - `family: 4` skips the IPv6 half of every hostname lookup. The database is
|
|
24
|
+
* IPv4, and a resolver that is slow to answer for AAAA delays every new connection.
|
|
25
25
|
*
|
|
26
26
|
* Each can be set per deployment, for a database that is somewhere else.
|
|
27
27
|
*/
|
|
@@ -29,12 +29,12 @@ export declare function poolOptions(env?: NodeJS.ProcessEnv): ConnectOptions;
|
|
|
29
29
|
/**
|
|
30
30
|
* Connects once and throws on failure. There is deliberately no retry loop here.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
32
|
+
* The driver already retries for us: `connect()` keeps doing server selection
|
|
33
|
+
* for `serverSelectionTimeoutMS` (30s by default) before it rejects, so a
|
|
34
|
+
* transient DNS or network blip, or a database container that is still starting,
|
|
35
|
+
* is absorbed there. Anything that survives that is a real fault — bad
|
|
36
|
+
* credentials, a wrong address, a database that is down — and no amount of
|
|
37
|
+
* retrying fixes it.
|
|
38
38
|
*
|
|
39
39
|
* Callers exit non-zero when this throws, which hands the problem to the
|
|
40
40
|
* container restart policy (`restart: unless-stopped`) that already supervises
|
|
@@ -16,17 +16,17 @@ let connected = false;
|
|
|
16
16
|
let pending = null;
|
|
17
17
|
let listenersRegistered = false;
|
|
18
18
|
/**
|
|
19
|
-
* How the pool behaves
|
|
19
|
+
* How the pool behaves, so a burst of requests does not pay for opening connections.
|
|
20
20
|
*
|
|
21
|
-
* Measured, not assumed:
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* requests pay for it badly:
|
|
21
|
+
* Measured, not assumed: against a database across the internet (the hosted one
|
|
22
|
+
* this replaced) a lookup took about 17 ms on a warm connection and 850 to
|
|
23
|
+
* 1,370 ms on a cold one, so distance was not the cost. Opening a connection was.
|
|
24
|
+
* It is a TCP and TLS handshake and an authentication, from a small machine, and
|
|
25
|
+
* the driver defaults make a burst of requests pay for it badly:
|
|
26
26
|
*
|
|
27
27
|
* - It keeps no connections open, and an idle one is eventually dropped by
|
|
28
|
-
* something
|
|
29
|
-
*
|
|
28
|
+
* something on the way, so the first request after a quiet spell starts from
|
|
29
|
+
* nothing.
|
|
30
30
|
* - It opens at most two connections at a time. Opening a thread sends five or
|
|
31
31
|
* six requests at once, so they queued behind each other, a second or so per
|
|
32
32
|
* pair, and the thread took three to seven seconds.
|
|
@@ -36,8 +36,8 @@ let listenersRegistered = false;
|
|
|
36
36
|
* - `maxConnecting` lets the pool open several at once when it does need more.
|
|
37
37
|
* - `maxIdleTimeMS` retires a connection that has sat idle for a few minutes,
|
|
38
38
|
* before something else kills it, and the pool opens a fresh one in its place.
|
|
39
|
-
* - `family: 4` skips the IPv6 half of every hostname lookup.
|
|
40
|
-
* a resolver that is slow to answer for AAAA delays every new connection.
|
|
39
|
+
* - `family: 4` skips the IPv6 half of every hostname lookup. The database is
|
|
40
|
+
* IPv4, and a resolver that is slow to answer for AAAA delays every new connection.
|
|
41
41
|
*
|
|
42
42
|
* Each can be set per deployment, for a database that is somewhere else.
|
|
43
43
|
*/
|
|
@@ -57,12 +57,12 @@ function poolOptions(env = process.env) {
|
|
|
57
57
|
/**
|
|
58
58
|
* Connects once and throws on failure. There is deliberately no retry loop here.
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
60
|
+
* The driver already retries for us: `connect()` keeps doing server selection
|
|
61
|
+
* for `serverSelectionTimeoutMS` (30s by default) before it rejects, so a
|
|
62
|
+
* transient DNS or network blip, or a database container that is still starting,
|
|
63
|
+
* is absorbed there. Anything that survives that is a real fault — bad
|
|
64
|
+
* credentials, a wrong address, a database that is down — and no amount of
|
|
65
|
+
* retrying fixes it.
|
|
66
66
|
*
|
|
67
67
|
* Callers exit non-zero when this throws, which hands the problem to the
|
|
68
68
|
* container restart policy (`restart: unless-stopped`) that already supervises
|