chiitiler 1.24.0 → 1.24.2
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/README.md +15 -8
- package/dist/cli.js +27 -8
- package/dist/main.js +4 -20
- package/dist/render/pool.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -158,20 +158,27 @@ All options can be set via CLI flag or environment variable.
|
|
|
158
158
|
| `--port <n>` | `CHIITILER_PORT` | `3000` |
|
|
159
159
|
| `--debug` | `CHIITILER_DEBUG` | `false` |
|
|
160
160
|
| `--user-agent <ua>` | `CHIITILER_USER_AGENT` | (none) |
|
|
161
|
-
|
|
|
162
|
-
|
|
|
161
|
+
| `--prewarm [true\|false]` | `CHIITILER_PREWARM` | `true` |
|
|
162
|
+
| `--processes <n>` | `CHIITILER_PROCESSES` | `1` (set `0` for all CPUs) |
|
|
163
163
|
|
|
164
|
-
Prewarm is enabled by default: one tile is rendered at startup **before** the server starts listening, moving shared renderer initialization work into startup.
|
|
164
|
+
Prewarm is enabled by default: one tile is rendered at startup **before** the server starts listening, moving shared renderer initialization work into startup. `--prewarm false` or `CHIITILER_PREWARM=false` disables it. `--prewarm` alone enables it. The CLI flag takes precedence over the environment variable. Style-specific tiles, glyphs, and sprites are not preloaded.
|
|
165
|
+
|
|
166
|
+
`--processes` takes precedence over `CHIITILER_PROCESSES` and accepts non-negative integers; `0` uses all available CPUs.
|
|
165
167
|
|
|
166
168
|
### Cache
|
|
167
169
|
|
|
170
|
+
Renderer Maps are reused per style and rendering mode without an idle timeout.
|
|
171
|
+
They are released when their pool is evicted from the 10-entry LRU or explicitly
|
|
172
|
+
closed. This avoids repeated initialization after quiet periods, at the cost of
|
|
173
|
+
retaining native renderer memory between requests.
|
|
174
|
+
|
|
168
175
|
| Flag | Env | Default |
|
|
169
176
|
| --- | --- | --- |
|
|
170
177
|
| `--cache <none\|memory\|file\|s3\|gcs>` | `CHIITILER_CACHE_METHOD` | `none` |
|
|
171
178
|
| `--cache-ttl <seconds>` | `CHIITILER_CACHE_TTL_SEC` | `3600` |
|
|
172
179
|
| `--memory-cache-max-item-count <n>` | `CHIITILER_MEMORYCACHE_MAXITEMCOUNT` | `1000` |
|
|
173
|
-
|
|
|
174
|
-
|
|
|
180
|
+
| `--front-cache-ttl-sec <seconds>` | `CHIITILER_FRONT_CACHE_TTL_SEC` | `10` (seconds) |
|
|
181
|
+
| `--front-cache-max-bytes <bytes>` | `CHIITILER_FRONT_CACHE_MAX_BYTES` | `67108864` (64 MiB) |
|
|
175
182
|
| `--file-cache-dir <dir>` | `CHIITILER_FILECACHE_DIR` | `./.cache` |
|
|
176
183
|
| `--s3-cache-bucket <name>` | `CHIITILER_S3CACHE_BUCKET` | — |
|
|
177
184
|
| `--s3-region <region>` | `CHIITILER_S3_REGION` | `us-east-1` |
|
|
@@ -192,9 +199,9 @@ hits into memory; writes populate memory immediately and also write to the backi
|
|
|
192
199
|
cache. `none` and `memory` keep their existing behavior. This affects sources that
|
|
193
200
|
already use the cache, not direct `s3://`, `gs://`, or local source reads.
|
|
194
201
|
|
|
195
|
-
Set `CHIITILER_FRONT_CACHE_TTL_SEC` to a positive, finite number of seconds and
|
|
196
|
-
`CHIITILER_FRONT_CACHE_MAX_BYTES` to a positive integer number of bytes to override
|
|
197
|
-
these limits. Setting either
|
|
202
|
+
Set `--front-cache-ttl-sec` / `CHIITILER_FRONT_CACHE_TTL_SEC` to a positive, finite number of seconds and
|
|
203
|
+
`--front-cache-max-bytes` / `CHIITILER_FRONT_CACHE_MAX_BYTES` to a positive integer number of bytes to override
|
|
204
|
+
these limits. CLI flags take precedence over environment variables. Setting either limit to `0` disables the front cache and uses the
|
|
198
205
|
backing cache directly. Otherwise, invalid values stop startup when using `file`,
|
|
199
206
|
`s3`, or `gcs`.
|
|
200
207
|
These settings do not affect `none`, `memory`, or library callers.
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import
|
|
2
|
+
import cluster from 'node:cluster';
|
|
3
|
+
import { availableParallelism } from 'node:os';
|
|
4
|
+
import { Command, Option, InvalidArgumentError } from 'commander';
|
|
3
5
|
import { initServer } from './server/index.js';
|
|
4
6
|
import * as caches from './cache/index.js';
|
|
5
7
|
import { setUserAgent } from './source/userAgent.js';
|
|
@@ -72,9 +74,12 @@ function parsePort(port) {
|
|
|
72
74
|
// undefined or invalid
|
|
73
75
|
return 3000;
|
|
74
76
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
function parseProcesses(value) {
|
|
78
|
+
const count = Number(value.trim() || NaN);
|
|
79
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
80
|
+
throw new InvalidArgumentError('processes must be a non-negative safe integer');
|
|
81
|
+
}
|
|
82
|
+
return count;
|
|
78
83
|
}
|
|
79
84
|
function parseDebug(debug) {
|
|
80
85
|
// command-line option
|
|
@@ -106,9 +111,23 @@ export function createProgram() {
|
|
|
106
111
|
.option('--gcs-api-endpoint <api-endpoint>', 'gcs api endpoint', '')
|
|
107
112
|
.option('-p, --port <port>', 'port number')
|
|
108
113
|
.option('--user-agent <user-agent>', 'User-Agent header for outbound HTTP requests')
|
|
109
|
-
.
|
|
114
|
+
.addOption(new Option('--prewarm [boolean]', 'startup renderer warmup')
|
|
115
|
+
.choices(['true', 'false']).preset('true').env('CHIITILER_PREWARM').default('true'))
|
|
116
|
+
.addOption(new Option('--processes <n>', 'worker processes (0 for all CPUs)')
|
|
117
|
+
.env('CHIITILER_PROCESSES').argParser(parseProcesses).default(1))
|
|
118
|
+
.addOption(new Option('--front-cache-ttl-sec <seconds>', 'memory front cache TTL (0 to disable)')
|
|
119
|
+
.env('CHIITILER_FRONT_CACHE_TTL_SEC'))
|
|
120
|
+
.addOption(new Option('--front-cache-max-bytes <bytes>', 'memory front cache byte limit (0 to disable)')
|
|
121
|
+
.env('CHIITILER_FRONT_CACHE_MAX_BYTES'))
|
|
110
122
|
.option('-D, --debug', 'debug mode')
|
|
111
123
|
.action(async (options) => {
|
|
124
|
+
const numProcesses = options.processes === 0 ? availableParallelism() : options.processes;
|
|
125
|
+
if (cluster.isPrimary && numProcesses !== 1) {
|
|
126
|
+
// Workers inherit argv and env, and initialize their own renderer and cache.
|
|
127
|
+
for (let i = 0; i < numProcesses; i++)
|
|
128
|
+
cluster.fork();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
112
131
|
// env fallback (CHIITILER_USER_AGENT) is handled in userAgent.ts
|
|
113
132
|
if (options.userAgent !== undefined)
|
|
114
133
|
setUserAgent(options.userAgent);
|
|
@@ -131,8 +150,8 @@ export function createProgram() {
|
|
|
131
150
|
debug: parseDebug(options.debug),
|
|
132
151
|
};
|
|
133
152
|
if (['file', 's3', 'gcs'].includes(serverOptions.cache.name)) {
|
|
134
|
-
const ttl =
|
|
135
|
-
const size =
|
|
153
|
+
const ttl = options.frontCacheTtlSec;
|
|
154
|
+
const size = options.frontCacheMaxBytes;
|
|
136
155
|
serverOptions.cache = caches.withMemoryCache(serverOptions.cache, {
|
|
137
156
|
ttlSeconds: ttl === undefined ? undefined : Number(ttl.trim() || NaN),
|
|
138
157
|
maxBytes: size === undefined ? undefined : Number(size.trim() || NaN),
|
|
@@ -147,7 +166,7 @@ export function createProgram() {
|
|
|
147
166
|
// warm up BEFORE listening: Lambda Web Adapter polls the
|
|
148
167
|
// readiness check until the port opens, so work done here
|
|
149
168
|
// stays inside the INIT phase (full CPU boost)
|
|
150
|
-
if (
|
|
169
|
+
if (options.prewarm === 'true') {
|
|
151
170
|
const startedAt = Date.now();
|
|
152
171
|
try {
|
|
153
172
|
await prewarm(serverOptions.cache);
|
package/dist/main.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import cluster from 'node:cluster';
|
|
2
|
-
import { availableParallelism } from 'node:os';
|
|
3
1
|
import process from 'node:process';
|
|
4
2
|
import { createProgram } from './cli.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const processesEnv = Number(process.env.CHIITILER_PROCESSES);
|
|
10
|
-
if (processesEnv === 0)
|
|
11
|
-
return availableParallelism();
|
|
12
|
-
else
|
|
13
|
-
return processesEnv;
|
|
14
|
-
})();
|
|
15
|
-
if (cluster.isPrimary && numProcesses !== 1) {
|
|
16
|
-
// Fork workers.
|
|
17
|
-
for (let i = 0; i < numProcesses; i++)
|
|
18
|
-
cluster.fork();
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
program.parse(process.argv);
|
|
22
|
-
}
|
|
3
|
+
createProgram().parseAsync(process.argv).catch((error) => {
|
|
4
|
+
console.error(error);
|
|
5
|
+
process.exitCode = 1;
|
|
6
|
+
});
|
package/dist/render/pool.js
CHANGED
|
@@ -50,6 +50,10 @@ async function getRenderPool(style, cache, mode) {
|
|
|
50
50
|
destroy: (map) => {
|
|
51
51
|
map.release();
|
|
52
52
|
},
|
|
53
|
+
}, {
|
|
54
|
+
// Keep initialized Maps until their pool is evicted or closed. Disable
|
|
55
|
+
// idle housekeeping rather than running a timer in warm Lambda environments.
|
|
56
|
+
houseKeepInterval: 0,
|
|
53
57
|
});
|
|
54
58
|
mapPoolCache.set(cacheKey, newPool);
|
|
55
59
|
return newPool;
|