temporalio / temporalio/samples-typescript

Add sample: worker thread pool for Activities

Open
#185 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
465
Forks
148
Avg merge
1d 10h
Merged PRs (30d)
11

Description

Using https://github.com/piscinajs/piscina

Background

Activities are in the main thread. If you’re doing CPU-intensive work in Activities, I’d recommend doing them inside worker threads that you create.

https://github.com/temporalio/sdk-typescript/blob/main/docs/arch.svg

Make sure to hook up cancellation to the thread pool:

Heartbeats become more complicated when running in a different thread, the easiest way to achieve that is by periodically emitting empty heartbeats in the main thread, but you won't be able to report progress this way. If you need more advance heartbeat behavior you can use MessageChannel or Atomics.notify or bypass the worker heartbeat mechanism and emit heartbeats yourself with an AsyncCompletionClient.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Piscina's cancelable-tasks documentation and the Temporal Activity Context cancellationSignal API linked in the issue. Build a TypeScript sample showing CPU-intensive Activities in a Piscina worker thread pool, with cancellation connected to the pool and a documented heartbeat approach. Done means the sample demonstrates the requested worker, cancellation, and heartbeat behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.