Skip to content

Commit 43c86a6

Browse files
committed
document environment variables and increase code cache default
- Document all 13 env vars in README, organized by category - Add V8_EXECUTE mode explanations (PINNED, POOLED, ONESHOT) - Increase SNAPSHOT_CACHE_MAX default from 500 to 5000
1 parent e026f3c commit 43c86a6

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

README.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,59 @@ NATS_SERVERS='nats://localhost:4222'
5353

5454
### Environment Variables
5555

56-
| Variable | Default | Description |
57-
| ---------------- | --------------- | ----------------------------------------------------------- |
58-
| `DATABASE_URL` | - | PostgreSQL connection string |
59-
| `NATS_SERVERS` | - | NATS server URL |
60-
| `WORKER_DOMAINS` | `workers.rocks` | Comma-separated list of worker domains for internal routing |
56+
#### Required
57+
58+
| Variable | Description |
59+
| -------------- | ---------------------------- |
60+
| `DATABASE_URL` | PostgreSQL connection string |
61+
| `NATS_SERVERS` | NATS server URL |
62+
63+
#### Networking
64+
65+
| Variable | Default | Description |
66+
| ----------------------------- | --------------- | ----------------------------------------------------------- |
67+
| `WORKER_DOMAINS` | `workers.rocks` | Comma-separated list of worker domains for internal routing |
68+
| `HTTP_POOL_MAX_IDLE_PER_HOST` | `100` | Max idle HTTP connections per host (for worker `fetch()`) |
69+
70+
#### V8 Runtime
71+
72+
| Variable | Default | Description |
73+
| ------------------------ | --------- | ------------------------------------------------ |
74+
| `V8_EXECUTE` | `PINNED` | Execution mode: `PINNED`, `POOLED`, or `ONESHOT` |
75+
| `SNAPSHOT_CACHE_MAX` | `5000` | Max entries in the in-memory code cache LRU |
76+
| `WORKER_POOL_SIZE` | CPU cores | Number of V8 worker threads |
77+
| `MAX_QUEUED_WORKERS` | pool × 10 | Max queued tasks before backpressure |
78+
| `WORKER_WAIT_TIMEOUT_MS` | `10000` | Timeout (ms) waiting for a worker slot |
79+
80+
`V8_EXECUTE` modes:
81+
82+
##### `PINNED` (default)
83+
84+
Thread-local isolate pools — each thread maintains its own pool of V8 isolates, keyed by tenant (`user_id`). Zero cross-thread contention. Multiple isolates can exist per tenant for concurrent requests. Includes backpressure via per-thread queue with configurable size and timeout.
85+
86+
A new V8 context is created per request, so no JS state leaks between requests. The isolate (engine, heap, GC) is reused to avoid the allocation cost.
87+
88+
##### `POOLED`
89+
90+
Single global LRU pool shared across all threads, protected by a mutex. Isolates are keyed by `worker_id`. Simpler model but higher contention under load since all threads compete for the same lock.
91+
92+
##### `ONESHOT`
93+
94+
Fresh V8 isolate per request, destroyed after each response. No reuse, no pooling. Slower (~1-2ms overhead per request) but useful for debugging. Also serves as a workaround for a V8 SIGSEGV (`SEGV_PKUERR`) that affects PINNED and POOLED modes in some containerized environments (see [#2](https://github.com/openworkers/openworkers-runner/issues/2)).
95+
96+
#### Telemetry (OpenTelemetry)
97+
98+
| Variable | Default | Description |
99+
| ------------------- | -------------------- | ------------------------------------------ |
100+
| `OTLP_ENDPOINT` | - | OTLP exporter endpoint (enables telemetry) |
101+
| `OTLP_SERVICE_NAME` | `openworkers-runner` | Service name reported to OTLP |
102+
| `OTLP_HEADERS` | - | Extra headers for OTLP exporter |
103+
104+
#### NATS Authentication
105+
106+
| Variable | Default | Description |
107+
| ------------------ | ------- | ----------------------------- |
108+
| `NATS_CREDENTIALS` | - | Path to NATS credentials file |
61109

62110
#### Internal Routing (`WORKER_DOMAINS`)
63111

src/snapshot_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use lru::LruCache;
1111
use once_cell::sync::Lazy;
1212

1313
/// Default max number of cached snapshots.
14-
const DEFAULT_MAX_ENTRIES: usize = 500;
14+
const DEFAULT_MAX_ENTRIES: usize = 5000;
1515

1616
/// Cache key: (worker_id, version)
1717
type CacheKey = (String, i32);

0 commit comments

Comments
 (0)