Skip to content
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

feat: worker pooling #962

Merged
merged 22 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ghjk/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exclude = [
]

[workspace.package]
version = "0.5.0"
version = "0.5.1-rc.0"
edition = "2021"

[workspace.dependencies]
Expand Down
357 changes: 357 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/templates/deno/api/example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Policy, t, typegraph } from "jsr:@typegraph/[email protected]";
import { PythonRuntime } from "jsr:@typegraph/[email protected]/runtimes/python";
import { DenoRuntime } from "jsr:@typegraph/[email protected]/runtimes/deno";
import { Policy, t, typegraph } from "jsr:@typegraph/[email protected].1-rc.0";
import { PythonRuntime } from "jsr:@typegraph/[email protected].1-rc.0/runtimes/python";
import { DenoRuntime } from "jsr:@typegraph/[email protected].1-rc.0/runtimes/deno";

await typegraph("example", (g) => {
const pub = Policy.public();
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/deno/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
typegate:
image: ghcr.io/metatypedev/typegate:v0.5.0
image: ghcr.io/metatypedev/typegate:v0.5.1-rc.0
restart: always
ports:
- "7890:7890"
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/node/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
typegate:
image: ghcr.io/metatypedev/typegate:v0.5.0
image: ghcr.io/metatypedev/typegate:v0.5.1-rc.0
restart: always
ports:
- "7890:7890"
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "MCLI_LOADER_CMD='npm x tsx' meta dev"
},
"dependencies": {
"@typegraph/sdk": "^0.5.0"
"@typegraph/sdk": "^0.5.1-rc.0"
},
"devDependencies": {
"tsx": "^3.13.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/python/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
typegate:
image: ghcr.io/metatypedev/typegate:v0.5.0
image: ghcr.io/metatypedev/typegate:v0.5.1-rc.0
restart: always
ports:
- "7890:7890"
Expand Down
4 changes: 2 additions & 2 deletions examples/templates/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poetry]
name = "example"
version = "0.5.0"
version = "0.5.1-rc.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
typegraph = "0.5.0"
typegraph = "0.5.1-rc.0"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[tool.poetry]
name = "metatype"
version = "0.5.0"
version = "0.5.1-rc.0"
description = ""
authors = []

Expand Down
2 changes: 1 addition & 1 deletion src/pyrt_wit_wire/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyrt_wit_wire"
version = "0.5.0"
version = "0.5.1-rc.0"
description = "Wasm component implementing the PythonRuntime host using wit_wire protocol."
license = "MPL-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/typegate/engine/src/runtimes/wit_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub fn op_wit_wire_destroy(
scope: &mut v8::HandleScope<'_>,
#[string] instance_id: String,
) {
debug!("destroying wit_wire instnace {instance_id}");
debug!("destroying wit_wire instance {instance_id}");
let ctx = {
let state = state.borrow();
let ctx = state.borrow::<Ctx>();
Expand Down
2 changes: 1 addition & 1 deletion src/typegate/src/runtimes/deno/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class DenoRuntime extends Runtime {
}

async deinit(): Promise<void> {
// await this.workerManager.deinit();
this.workerManager.deinit();
Natoandro marked this conversation as resolved.
Show resolved Hide resolved
}

materialize(
Expand Down
9 changes: 5 additions & 4 deletions src/typegate/src/runtimes/deno/worker_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ export class WorkerManager
extends BaseWorkerManager<TaskSpec, DenoMessage, DenoEvent> {
constructor(private config: WorkerManagerConfig) {
super(
"deno runtime",
(taskId: TaskId) => {
return new DenoWorker(taskId, import.meta.resolve("./worker.ts"));
},
);
}

callFunction(
async callFunction(
name: string,
modulePath: string,
relativeModulePath: string,
args: unknown,
internalTCtx: TaskContext,
) {
const taskId = createTaskId(`${name}@${relativeModulePath}`);
this.createWorker(name, taskId, {
await this.delegateTask(name, taskId, {
modulePath,
functionName: name,
});
Expand All @@ -49,13 +50,13 @@ export class WorkerManager

return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
this.destroyWorker(name, taskId);
this.deallocateWorker(name, taskId);
reject(new Error(`${this.config.timeout_ms}ms timeout exceeded`));
}, this.config.timeout_ms);

const handler: (event: DenoEvent) => void = (event) => {
clearTimeout(timeoutId);
this.destroyWorker(name, taskId);
this.deallocateWorker(name, taskId);
switch (event.type) {
case "SUCCESS":
resolve(event.result);
Expand Down
5 changes: 3 additions & 2 deletions src/typegate/src/runtimes/patterns/worker_manager/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export class DenoWorker<M extends BaseMessage, E extends BaseDenoWorkerMessage>
await handlerFn(message.data as E);
};

this.#worker.onerror = /*async*/ (event) =>
handlerFn(
this.#worker.onerror = async (event) => {
await handlerFn(
{
type: "WORKER_ERROR",
event,
} as E,
);
};
}

send(msg: M) {
Expand Down
Loading
Loading