Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/fastify-hybrid...
[poolifier.git] / examples / typescript / websocket-server-pool / ws-hybrid / src / main.ts
index 6f73fa0731504404cf5d4b26d7afdc5fc121be9d..f6536bd0bbc3bbde78e8cd5bf68cfb48099e1fc6 100644 (file)
@@ -8,13 +8,32 @@ const webSocketServerWorkerFile = join(
   `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<ClusterWorkerData, ClusterWorkerResponse>(
   Math.round(availableParallelism() / 2),
   webSocketServerWorkerFile,
   {
     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(