-
Notifications
You must be signed in to change notification settings - Fork 9
Document storage tuning, thread debugging, MQTT durable sessions, analytics config #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kriszyp
wants to merge
1
commit into
main
Choose a base branch
from
docs/storage-tuning-debugging-mqtt-analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| --- | ||
| title: Worker Thread Debugging | ||
| --- | ||
|
|
||
| # Worker Thread Debugging | ||
|
|
||
| Harper runs as a main thread plus a pool of worker threads (configurable via `threads.count`). The `threads.debug` option exposes the Node.js inspector on each thread so you can attach Chrome DevTools, VS Code, or any [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) (CDP) client to step through component code, inspect heap state, or capture CPU profiles. | ||
|
|
||
| For the worker thread architecture, see [Architecture Overview](../database/overview.md#architecture-overview). | ||
|
|
||
| ## Enabling the Debugger | ||
|
|
||
| The simplest form starts the inspector on the main thread at the default port (`9229`): | ||
|
|
||
| ```yaml | ||
| threads: | ||
| debug: true | ||
| ``` | ||
|
|
||
| For per-thread debugging, expand to an object: | ||
|
|
||
| ```yaml | ||
| threads: | ||
| debug: | ||
| startingPort: 9229 | ||
| host: 127.0.0.1 | ||
| waitForDebugger: false | ||
| ``` | ||
|
|
||
| | Property | Type | Default | Description | | ||
| | ----------------- | --------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `port` | `integer` | `9229` | Port for the main thread inspector. Use this when you only need to debug startup or main-thread behavior. | | ||
| | `startingPort` | `integer` | _(none)_ | When set, each worker thread gets a sequential inspector port starting from this value. Thread N uses port `startingPort + N`. The main thread keeps `port`. | | ||
| | `host` | `string` | `127.0.0.1` | Interface the inspector binds to. Leave on loopback in production; use `0.0.0.0` only when tunneling over SSH or operating in a trusted network. | | ||
| | `waitForDebugger` | `boolean` | `false` | Pause each thread at startup until a debugger attaches. Useful for catching bugs that occur during component initialization. | | ||
|
|
||
| ## Attaching Chrome DevTools | ||
|
|
||
| 1. Set `threads.debug.startingPort: 9230` (so worker threads use 9230, 9231, … and the main thread keeps 9229). | ||
| 2. Start Harper. | ||
| 3. Open `chrome://inspect` in Chrome. | ||
| 4. Click **Configure** and add `localhost:9229`, `localhost:9230`, … for each thread you want to inspect. | ||
| 5. The threads appear under **Remote Target**. Click **inspect** to open DevTools for that thread. | ||
|
|
||
| ## Attaching VS Code | ||
|
|
||
| Add an entry per thread to `.vscode/launch.json`. The example below attaches to the main thread and two workers: | ||
|
|
||
| ```json | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { "type": "node", "request": "attach", "name": "Harper main", "port": 9229 }, | ||
| { "type": "node", "request": "attach", "name": "Harper worker 1", "port": 9230 }, | ||
| { "type": "node", "request": "attach", "name": "Harper worker 2", "port": 9231 } | ||
| ], | ||
| "compounds": [ | ||
| { "name": "Harper (all threads)", "configurations": ["Harper main", "Harper worker 1", "Harper worker 2"] } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Run the compound configuration to attach to every thread at once. | ||
|
|
||
| ## Debugging Remote Instances | ||
|
|
||
| Inspector ports must remain on `127.0.0.1` in production. To reach them from a developer workstation, tunnel each port over SSH: | ||
|
|
||
| ```bash | ||
| ssh -L 9229:127.0.0.1:9229 \ | ||
| -L 9230:127.0.0.1:9230 \ | ||
| -L 9231:127.0.0.1:9231 \ | ||
| harper.example.com | ||
| ``` | ||
|
|
||
| Then point Chrome DevTools or VS Code at `localhost:9229–9231` as if they were local. | ||
|
|
||
| ## Waiting for the Debugger at Startup | ||
|
|
||
| When a bug only reproduces during component initialization, set `waitForDebugger: true`. Each thread starts paused on its first line until a debugger attaches and resumes execution. This is also the safest way to debug an initialization sequence that completes too quickly to manually attach. | ||
|
|
||
| ```yaml | ||
| threads: | ||
| debug: | ||
| startingPort: 9230 | ||
| waitForDebugger: true | ||
| ``` | ||
|
|
||
| **Health checks and load balancers** will fail while the threads are paused — only enable `waitForDebugger` in dedicated debug environments. | ||
|
|
||
| ## Heap Snapshots Near the Limit | ||
|
|
||
| ### `threads.heapSnapshotNearLimit` | ||
|
|
||
| Type: `boolean` • Default: `false` | ||
|
|
||
| When the V8 heap approaches the limit set by `threads.maxHeapMemory`, the thread writes a `.heapsnapshot` file to the Harper root directory before the process exits with an out-of-memory error. The snapshot can be loaded into Chrome DevTools (Memory tab → **Load profile**) to identify retained objects responsible for the leak. | ||
|
|
||
| ```yaml | ||
| threads: | ||
| maxHeapMemory: 1024 | ||
| heapSnapshotNearLimit: true | ||
| ``` | ||
|
|
||
| Snapshots can be large (often a sizable fraction of the heap limit) and writing them blocks the thread briefly — leave disabled for normal operation and enable only when investigating an out-of-memory pattern. | ||
|
|
||
| ## Related | ||
|
|
||
| - [Configuration Options — `threads`](./options.md#threads) — full thread configuration reference | ||
| - [Architecture Overview](../database/overview.md#architecture-overview) — how worker threads fit into Harper | ||
| - [Node.js Inspector documentation](https://nodejs.org/en/learn/getting-started/debugging) — debugger protocol details |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not going to block on this, but this whole double space and special dot character (at least its not on my keyboard) seems extra. Most of the docs use regular characters like
-here.