@coherentglobal/wasm-runner 0.1.19 → 0.2.4
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/CancellationToken.js +2 -0
- package/dist/CancellationToken.js.map +1 -1
- package/dist/browser/logger.js +6 -2
- package/dist/browser/logger.js.map +1 -1
- package/dist/browser/template/worker.template.js +111 -105
- package/dist/browser/template/worker.template.js.map +1 -1
- package/dist/browser/template.js +1 -1
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +242 -257
- package/dist/browser.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -1
- package/dist/defaultExternalResolver.js +6 -15
- package/dist/defaultExternalResolver.js.map +1 -1
- package/dist/error.js +10 -2
- package/dist/error.js.map +1 -1
- package/dist/node/logger.d.ts +2 -1
- package/dist/node/logger.js +1 -1
- package/dist/node/logger.js.map +1 -1
- package/dist/node/logger.ts +1 -1
- package/dist/node/mockLogger.d.ts +2 -1
- package/dist/node/template/main.template.ejs +54 -28
- package/dist/node/threads/mockWorkerThread.d.ts +1 -0
- package/dist/node/threads/mockWorkerThread.js +10 -3
- package/dist/node/threads/mockWorkerThread.js.map +1 -1
- package/dist/node/threads/workerPool.d.ts +2 -1
- package/dist/node/threads/workerPool.js +7 -6
- package/dist/node/threads/workerPool.js.map +1 -1
- package/dist/node/threads/workerPool.ts +10 -7
- package/dist/node/threads/workerThread.d.ts +1 -2
- package/dist/node/threads/workerThread.js +35 -42
- package/dist/node/threads/workerThread.js.map +1 -1
- package/dist/node/threads/workerThread.ts +8 -12
- package/dist/node.d.ts +13 -3
- package/dist/node.js +523 -459
- package/dist/node.js.map +1 -1
- package/dist/responseTimeMetric.d.ts +7 -3
- package/dist/responseTimeMetric.js +131 -28
- package/dist/responseTimeMetric.js.map +1 -1
- package/dist/serializer/columnarSerializer.d.ts +11 -3
- package/dist/serializer/columnarSerializer.js +49 -29
- package/dist/serializer/columnarSerializer.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +38 -48
- package/dist/utils.js.map +1 -1
- package/package.json +71 -60
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const worker_threads_1 = require("worker_threads");
|
|
13
4
|
const poolifier_1 = require("poolifier");
|
|
14
5
|
const constants_1 = require("../../constants");
|
|
15
6
|
const activeListeners = new Map();
|
|
16
7
|
class WorkerThread extends poolifier_1.ThreadWorker {
|
|
17
|
-
constructor(taskFunctions, opts) {
|
|
18
|
-
super(taskFunctions, opts);
|
|
19
|
-
this.cleanupListener = (eventId) => {
|
|
20
|
-
setTimeout(() => {
|
|
21
|
-
const listener = activeListeners.get(eventId);
|
|
22
|
-
if (listener) {
|
|
23
|
-
worker_threads_1.parentPort.off("message", listener);
|
|
24
|
-
activeListeners.delete(eventId);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
8
|
/**
|
|
30
9
|
* Sends message back to the main thread.
|
|
31
10
|
*
|
|
@@ -53,6 +32,15 @@ class WorkerThread extends poolifier_1.ThreadWorker {
|
|
|
53
32
|
worker_threads_1.parentPort.on("message", callback);
|
|
54
33
|
}
|
|
55
34
|
}
|
|
35
|
+
cleanupListener = (eventId) => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
const listener = activeListeners.get(eventId);
|
|
38
|
+
if (listener) {
|
|
39
|
+
worker_threads_1.parentPort.off("message", listener);
|
|
40
|
+
activeListeners.delete(eventId);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
56
44
|
/**
|
|
57
45
|
* Sends a request to the main thread and waits for a response.
|
|
58
46
|
*
|
|
@@ -62,28 +50,33 @@ class WorkerThread extends poolifier_1.ThreadWorker {
|
|
|
62
50
|
* @returns {Promise<Object>}
|
|
63
51
|
* Response from main thread.
|
|
64
52
|
*/
|
|
65
|
-
requestMessage(payload, context) {
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
threadId: worker_threads_1.threadId,
|
|
74
|
-
});
|
|
75
|
-
// Receive the response from parent once ready
|
|
76
|
-
const messageListener = (message) => {
|
|
77
|
-
worker_threads_1.parentPort.off("message", messageListener);
|
|
78
|
-
if ((message === null || message === void 0 ? void 0 : message.type) === constants_1.THREAD_EVENT_TYPES.RESPONSE) {
|
|
79
|
-
resolve(message === null || message === void 0 ? void 0 : message.payload);
|
|
80
|
-
}
|
|
81
|
-
else if ((message === null || message === void 0 ? void 0 : message.type) === constants_1.THREAD_EVENT_TYPES.ERROR) {
|
|
82
|
-
reject(message === null || message === void 0 ? void 0 : message.payload);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
this.onMessage(messageListener);
|
|
53
|
+
async requestMessage(payload, context) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
// Send the request to parent
|
|
56
|
+
this.postMessage({
|
|
57
|
+
payload,
|
|
58
|
+
context,
|
|
59
|
+
type: constants_1.THREAD_EVENT_TYPES.REQUEST_EXECUTE,
|
|
60
|
+
threadId: worker_threads_1.threadId,
|
|
86
61
|
});
|
|
62
|
+
// Receive the response from parent once ready
|
|
63
|
+
const messageListener = (message) => {
|
|
64
|
+
worker_threads_1.parentPort.off("message", messageListener);
|
|
65
|
+
if (message?.type === constants_1.THREAD_EVENT_TYPES.RESPONSE) {
|
|
66
|
+
resolve(message?.payload);
|
|
67
|
+
}
|
|
68
|
+
else if (message?.type === constants_1.THREAD_EVENT_TYPES.ERROR) {
|
|
69
|
+
reject(message?.payload);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
this.onMessage(messageListener);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
reportStats(payload) {
|
|
76
|
+
this.postMessage({
|
|
77
|
+
payload,
|
|
78
|
+
type: constants_1.THREAD_EVENT_TYPES.STATS_REPORT,
|
|
79
|
+
threadId: worker_threads_1.threadId,
|
|
87
80
|
});
|
|
88
81
|
}
|
|
89
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerThread.js","sourceRoot":"","sources":["../../../src/node/threads/workerThread.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workerThread.js","sourceRoot":"","sources":["../../../src/node/threads/workerThread.ts"],"names":[],"mappings":";;AAAA,mDAAoE;AACpE,yCAAyC;AACzC,+CAAqD;AAIrD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;AAElC,MAAM,YAAa,SAAQ,wBAAY;IACrC;;;;OAIG;IACH,WAAW,CAAC,OAAyB;QACnC,IAAI,6BAAY,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,2BAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,QAA+B;QACvC,IAAI,6BAAY,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN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AI,CAAC,WAAW,CAAC;YACf,OAAO;YACP,IAAI,EAAE,8BAAkB,CAAC,YAA0B;YACnD,QAAQ,EAAR,yBAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,YAAY,CAAC"}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { isMainThread, parentPort, threadId } from "worker_threads";
|
|
2
|
-
import { createId as cuid } from "@paralleldrive/cuid2";
|
|
3
2
|
import { ThreadWorker } from "poolifier";
|
|
4
3
|
import { THREAD_EVENT_TYPES } from "../../constants";
|
|
5
4
|
|
|
6
|
-
import type { TaskFunctions, TaskFunction, WorkerOptions } from "poolifier";
|
|
7
5
|
import type { EVENT_TYPE, EventRequestData } from "../../types";
|
|
8
6
|
|
|
9
7
|
const activeListeners = new Map();
|
|
10
8
|
|
|
11
9
|
class WorkerThread extends ThreadWorker {
|
|
12
|
-
constructor(
|
|
13
|
-
taskFunctions:
|
|
14
|
-
| TaskFunction<unknown, Response>
|
|
15
|
-
| TaskFunctions<unknown, Response>,
|
|
16
|
-
opts?: WorkerOptions
|
|
17
|
-
) {
|
|
18
|
-
super(taskFunctions, opts);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
10
|
/**
|
|
22
11
|
* Sends message back to the main thread.
|
|
23
12
|
*
|
|
@@ -82,11 +71,18 @@ class WorkerThread extends ThreadWorker {
|
|
|
82
71
|
} else if (message?.type === THREAD_EVENT_TYPES.ERROR) {
|
|
83
72
|
reject(message?.payload);
|
|
84
73
|
}
|
|
85
|
-
|
|
86
74
|
};
|
|
87
75
|
this.onMessage(messageListener);
|
|
88
76
|
});
|
|
89
77
|
}
|
|
78
|
+
|
|
79
|
+
reportStats(payload: any) {
|
|
80
|
+
this.postMessage({
|
|
81
|
+
payload,
|
|
82
|
+
type: THREAD_EVENT_TYPES.STATS_REPORT as EVENT_TYPE,
|
|
83
|
+
threadId,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
90
86
|
}
|
|
91
87
|
|
|
92
88
|
export default WorkerThread;
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import tmp from "tmp";
|
|
2
|
+
import EventEmitter from "events";
|
|
3
|
+
import { BaseLogger } from "pino";
|
|
2
4
|
import { NodeModel, RunnerConfig, ModelConfig, ResponseObject, Compatibility, WasmOptions, ModelInstance } from "./types";
|
|
3
5
|
import { CancellationToken } from "./CancellationToken";
|
|
4
6
|
export { ColumnarSerializer } from "./serializer/columnarSerializer";
|
|
@@ -10,7 +12,7 @@ export { ModelExecuteCancelled } from "./error";
|
|
|
10
12
|
* @class
|
|
11
13
|
* @classdesc WasmRunner class, responsible for managing model and it's lifecycle
|
|
12
14
|
*/
|
|
13
|
-
export declare class WasmRunner {
|
|
15
|
+
export declare class WasmRunner extends EventEmitter {
|
|
14
16
|
_tempWorkerFolder: tmp.DirResult;
|
|
15
17
|
_tempModelFolder: tmp.DirResult;
|
|
16
18
|
license: string;
|
|
@@ -19,6 +21,7 @@ export declare class WasmRunner {
|
|
|
19
21
|
initializingModels: string[];
|
|
20
22
|
options: WasmOptions;
|
|
21
23
|
safeCompiler: string;
|
|
24
|
+
logger: BaseLogger;
|
|
22
25
|
/**
|
|
23
26
|
* Create new Wasm Runner instance
|
|
24
27
|
*
|
|
@@ -53,7 +56,7 @@ export declare class WasmRunner {
|
|
|
53
56
|
* @returns {Promise<void>}
|
|
54
57
|
*/
|
|
55
58
|
remove(id: string): Promise<void>;
|
|
56
|
-
_parseError(rawResponse: any):
|
|
59
|
+
_parseError(rawResponse: any): object;
|
|
57
60
|
_getModel(id: string): NodeModel;
|
|
58
61
|
getModelSize(id: string): number;
|
|
59
62
|
getModelCompilerVersion(id: any): string;
|
|
@@ -65,7 +68,14 @@ export declare class WasmRunner {
|
|
|
65
68
|
isExist(id: string): boolean;
|
|
66
69
|
isModelCompatible(model: any, input: any): boolean;
|
|
67
70
|
getModelsStats(): {
|
|
68
|
-
|
|
71
|
+
thread_stats: any;
|
|
72
|
+
memory_usage_mb: any;
|
|
73
|
+
uptime_ms: number;
|
|
74
|
+
min_time_ms: any;
|
|
75
|
+
mean_time_ms: any;
|
|
76
|
+
p95_time_ms: any;
|
|
77
|
+
p99_time_ms: any;
|
|
78
|
+
max_time_ms: any;
|
|
69
79
|
busy: any;
|
|
70
80
|
size: any;
|
|
71
81
|
id: any;
|