X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fwebsocket-server-pool%2Fws-hybrid%2Fsrc%2Fmain.ts;h=177d7d3b5813f04ff10dd8812f8eafeec1099407;hb=b6a7bb07d6b1e44a4504fa283f2b4016bd19c39c;hp=6f73fa0731504404cf5d4b26d7afdc5fc121be9d;hpb=80ccdab6c5ce5e7e6305c15dd29257d0acc9e302;p=poolifier.git diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts index 6f73fa07..177d7d3b 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts @@ -1,20 +1,40 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { FixedClusterPool, availableParallelism } from 'poolifier' -import { type ClusterWorkerData, type ClusterWorkerResponse } from './types.js' +import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' const webSocketServerWorkerFile = join( dirname(fileURLToPath(import.meta.url)), `websocket-server-worker${extname(fileURLToPath(import.meta.url))}` ) +const requestHandlerWorkerFile = join( + dirname(fileURLToPath(import.meta.url)), + `request-handler-worker${extname(fileURLToPath(import.meta.url))}` +) + const pool = new FixedClusterPool( Math.round(availableParallelism() / 2), webSocketServerWorkerFile, { + enableEvents: false, onlineHandler: () => { pool - .execute({ port: 8080 }) + .execute({ + port: 8080, + maxWorkers: + Math.round(availableParallelism() / 4) < 1 + ? 1 + : Math.round(availableParallelism() / 4), + workerFile: requestHandlerWorkerFile, + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: 8 + }, + errorHandler: (e: Error) => { + console.error('Thread worker error:', e) + } + }) .then(response => { if (response.status) { console.info( @@ -22,7 +42,7 @@ const pool = new FixedClusterPool( `WebSocket server is listening in cluster worker on port ${response.port}` ) } - return null + return undefined }) .catch(error => { console.error(