Skip to content

Commit 17e32d6

Browse files
authored
Runtime memory Metrics (#1103)
* Add main thread memory stats to worker * changeset * add polling * don't log condition code * changeset * add profiling to steps * add profile and interval options to the worker * changeset * runtime: add profiler for the workflow as a whole * types * versions: [email protected]
1 parent 48c79b5 commit 17e32d6

File tree

25 files changed

+310
-24
lines changed

25 files changed

+310
-24
lines changed

packages/cli/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @openfn/cli
22

3+
## 1.18.1
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [3cd3cd5]
8+
- @openfn/runtime@1.7.4
9+
310
## 1.18.0
411

512
### Minor Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.18.0",
3+
"version": "1.18.1",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/engine-multi/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# engine-multi
22

3+
## 1.8.0
4+
5+
### Minor Changes
6+
7+
- 475f8cf: Add options to profile memory usage in workflows. This should give a more accurate reading of the memory used by a run, but may have a small impact on performance
8+
9+
### Patch Changes
10+
11+
- Updated dependencies [3cd3cd5]
12+
- @openfn/runtime@1.7.4
13+
314
## 1.7.1
415

516
### Patch Changes

packages/engine-multi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/engine-multi",
3-
"version": "1.7.1",
3+
"version": "1.8.0",
44
"description": "Multi-process runtime engine",
55
"main": "dist/index.js",
66
"type": "module",

packages/engine-multi/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const createAPI = async function (
6363
'configuration',
6464
'response',
6565
],
66+
profile: options.profile,
67+
profilePollInterval: options.profilePollInterval,
6668
};
6769

6870
logger.info(`memory limit set to ${options.memoryLimitMb}mb`);

packages/engine-multi/src/api/execute.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const execute = async (context: ExecutionContext) => {
4343
whitelist,
4444
jobLogLevel: options.jobLogLevel,
4545
repoDir: options.repoDir,
46+
profile: context.options.profile,
47+
profilePollInteval: context.options.profilePollInterval,
4648
} as RunOptions;
4749

4850
const workerOptions = {

packages/engine-multi/src/engine.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import type {
2727
import type { AutoinstallOptions } from './api/autoinstall';
2828

2929
const DEFAULT_RUN_TIMEOUT = 1000 * 60 * 10; // ms
30-
3130
const DEFAULT_MEMORY_LIMIT_MB = 500;
32-
3331
const DEFAULT_PAYLOAD_LIMIT_MB = 10;
32+
const DEFAULT_PROFILE = false;
33+
const DEFAULT_PROFILE_POLL_INTERVAL = 10;
3434

3535
// For each workflow, create an API object with its own event emitter
3636
// this is a bit weird - what if the emitter went on state instead?
@@ -84,6 +84,9 @@ export type EngineOptions = {
8484

8585
workerValidationTimeout?: number;
8686
workerValidationRetries?: number;
87+
88+
profile?: boolean;
89+
profilePollInterval?: number;
8790
};
8891

8992
export type InternalEngine = RuntimeEngine & {
@@ -106,6 +109,9 @@ const createEngine = async (
106109
const defaultMemoryLimit = options.memoryLimitMb || DEFAULT_MEMORY_LIMIT_MB;
107110
const defaultPayloadLimit =
108111
options.payloadLimitMb || DEFAULT_PAYLOAD_LIMIT_MB;
112+
const defaultProfile = options.profile ?? DEFAULT_PROFILE;
113+
const defaultProfilePollInterval =
114+
options.profilePollInterval ?? DEFAULT_PROFILE_POLL_INTERVAL;
109115

110116
let resolvedWorkerPath;
111117
if (workerPath) {
@@ -165,6 +171,8 @@ const createEngine = async (
165171
memoryLimitMb: opts.memoryLimitMb ?? defaultMemoryLimit,
166172
payloadLimitMb: opts.payloadLimitMb ?? defaultPayloadLimit,
167173
jobLogLevel: opts.jobLogLevel,
174+
profile: defaultProfile,
175+
profilePollInterval: defaultProfilePollInterval,
168176
},
169177
});
170178

packages/engine-multi/src/worker/thread/run.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import { COMPILE_START, COMPILE_COMPLETE } from '../events';
1515
export type RunOptions = {
1616
repoDir: string;
1717
whitelist?: RegExp[];
18-
sanitize: SanitizePolicies;
18+
sanitize?: SanitizePolicies;
1919
statePropsToRemove?: string[];
2020
jobLogLevel?: LogLevel;
21+
profile?: boolean;
22+
profilePollInterval?: number;
2123
};
2224

2325
const eventMap = {
@@ -29,8 +31,15 @@ const eventMap = {
2931

3032
register({
3133
run: async (plan: ExecutionPlan, input: State, runOptions: RunOptions) => {
32-
const { repoDir, whitelist, sanitize, statePropsToRemove, jobLogLevel } =
33-
runOptions;
34+
const {
35+
repoDir,
36+
whitelist,
37+
sanitize,
38+
statePropsToRemove,
39+
jobLogLevel,
40+
profile,
41+
profilePollInterval,
42+
} = runOptions;
3443
const { logger, jobLogger, adaptorLogger } = createLoggers(
3544
plan.id!,
3645
sanitize,
@@ -60,6 +69,8 @@ register({
6069
whitelist,
6170
cacheKey: plan.id,
6271
},
72+
profile,
73+
profilePollInterval,
6374
statePropsToRemove,
6475
callbacks: {
6576
// TODO: this won't actually work across the worker boundary
@@ -75,6 +86,7 @@ register({
7586
},
7687
},
7788
};
89+
logger.log(' >>', options.profile, options.profilePollInterval);
7890

7991
return execute(plan.id!, async () => {
8092
const start = Date.now();

packages/lightning-mock/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @openfn/lightning-mock
22

3+
## 2.3.3
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [3cd3cd5]
8+
- Updated dependencies [475f8cf]
9+
- @openfn/runtime@1.7.4
10+
- @openfn/engine-multi@1.8.0
11+
312
## 2.3.2
413

514
### Patch Changes

packages/lightning-mock/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/lightning-mock",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
44
"private": true,
55
"description": "A mock Lightning server",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)