Skip to content

Commit d7f4f90

Browse files
committed
v1.6.4
1 parent 26c0bd5 commit d7f4f90

36 files changed

Lines changed: 326 additions & 261 deletions

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,56 @@ Hash-based routing intelligently handles failures at the workflow level (not cli
136136

137137
See [Hash-Based Routing Guide](./docs/hash-routing-guide.md) for details and demos.
138138

139+
### Advanced: `MultiWorkflowPool` for Heterogeneous Clusters
140+
141+
For complex use cases involving a heterogeneous cluster of workers (e.g., some with SDXL models, others for video generation), `MultiWorkflowPool` provides fine-grained control over job routing based on workflow requirements.
142+
143+
It uses an event-driven architecture to manage clients with specific **workflow affinities**, ensuring that jobs are only sent to nodes capable of processing them.
144+
145+
- **Workflow Affinity:** Assign clients to specific workflows. Jobs are automatically routed to the correct client.
146+
- **Dynamic Job Queues:** A separate job queue is created for each workflow type, preventing head-of-line blocking.
147+
- **Event-Driven Architecture:** Zero polling for maximum efficiency and responsiveness.
148+
- **Built-in Monitoring:** Optional real-time monitoring of client and queue states.
149+
150+
**Example:**
151+
```ts
152+
import { MultiWorkflowPool, Workflow } from "comfyui-node";
153+
import SdxlWorkflow from './sdxl-workflow.json';
154+
import VideoWorkflow from './video-workflow.json';
155+
156+
// 1. Define workflows and generate their hash for affinity mapping
157+
const sdxlWF = Workflow.from(SdxlWorkflow).updateHash();
158+
const videoWF = Workflow.from(VideoWorkflow).updateHash();
159+
160+
// 2. Create a new pool
161+
const pool = new MultiWorkflowPool({
162+
logLevel: "info",
163+
enableMonitoring: true,
164+
});
165+
166+
// 3. Add clients with workflow affinity
167+
// This client is specialized for SDXL workflows
168+
pool.addClient("http://localhost:8188", { workflowAffinity: [sdxlWF] });
169+
170+
// This client is specialized for Video workflows
171+
pool.addClient("http://localhost:8189", { workflowAffinity: [videoWF] });
172+
173+
// This client is a general-purpose worker
174+
pool.addClient("http://localhost:8190");
175+
176+
// 4. Initialize the pool (connects to all clients)
177+
await pool.init();
178+
179+
// 5. Submit jobs
180+
// The pool automatically routes them to the correct client
181+
const sdxlJobId = await pool.submitJob(sdxlWF);
182+
const videoJobId = await pool.submitJob(videoWF);
183+
184+
// 6. Wait for a job to complete
185+
const results = await pool.waitForJobCompletion(sdxlJobId);
186+
console.log("SDXL Job completed!", results.images);
187+
```
188+
139189
## What's New in v1.5.0
140190

141191
- **WorkflowPool Profiling** – Enable automatic per-node performance tracking with `enableProfiling: true`.

dist/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export { seed } from "./tools.js";
1414
export { MultiWorkflowPool } from "./multipool/index.js";
1515
export { Workflow as MultiWorkflow } from "./multipool/workflow.js";
1616
export type { PoolEvent, ClientEventPayload, MultiWorkflowPoolOptions } from "./multipool/interfaces.js";
17-
export type { JobResults, JobState, JobStatus as MultiJobStatus, JobResultStatus } from "./multipool/job-state-registry.js";
18-
export type { JobProfileStats as MultiJobProfileStats } from "./multipool/job-profiler.js";
17+
export type { JobResults, JobState, JobStatus as MultiJobStatus, JobResultStatus } from "./multipool/interfaces.js";
18+
export type { JobProfileStats as MultiJobProfileStats } from "./multipool/interfaces.js";
1919
//# sourceMappingURL=index.d.ts.map

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/multipool/client-registry.d.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import { MultiWorkflowPool } from "src/multipool/multi-workflow-pool.js";
2-
import { ComfyApi } from "src/client.js";
1+
import { MultiWorkflowPool } from "./multi-workflow-pool.js";
32
import { Workflow } from "./workflow.js";
43
import { Logger } from "./logger.js";
5-
export type ClientState = "idle" | "busy" | "offline";
6-
export interface EnhancedClient {
7-
url: string;
8-
state: ClientState;
9-
nodeName: string;
10-
priority?: number;
11-
api: ComfyApi;
12-
workflowAffinity?: Set<string>;
13-
}
4+
import { EnhancedClient } from "./interfaces.js";
145
export declare class ClientRegistry {
156
pool: MultiWorkflowPool;
167
private logger;

dist/multipool/client-registry.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/multipool/client-registry.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/multipool/client-registry.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)