`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() / 2),
+ workerFile: requestHandlerWorkerFile,
+ enableTasksQueue: true,
+ tasksQueueOptions: {
+ concurrency: 8
+ },
+ errorHandler: (e: Error) => {
+ console.error('Thread worker error:', e)
+ }
+ })
.then(response => {
if (response.status) {
console.info(
-import { dirname, extname, join } from 'node:path'
-import { fileURLToPath } from 'node:url'
import {
ClusterWorker,
DynamicThreadPool,
)
})
+ WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
+ ThreadWorkerData<DataPayload>,
+ ThreadWorkerResponse<DataPayload>
+ >(
+ workerData?.minWorkers ?? 1,
+ workerData?.maxWorkers ?? availableParallelism(),
+ workerData?.workerFile as string
+ )
+
wss.on('connection', ws => {
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
) as MessagePayload<DataPayload>
switch (type) {
case MessageType.echo:
- this.requestHandlerPool
+ WebSocketServerWorker.requestHandlerPool
.execute({ data }, 'echo')
.then(response => {
ws.send(
.catch(emptyFunction)
break
case MessageType.factorial:
- this.requestHandlerPool
+ WebSocketServerWorker.requestHandlerPool
.execute({ data }, 'factorial')
.then(response => {
ws.send(
}
}
- private static readonly requestHandlerWorkerFile = join(
- dirname(fileURLToPath(import.meta.url)),
- `request-handler-worker${extname(fileURLToPath(import.meta.url))}`
- )
-
- private static readonly requestHandlerPool = new DynamicThreadPool<
+ private static requestHandlerPool: DynamicThreadPool<
ThreadWorkerData<DataPayload>,
ThreadWorkerResponse<DataPayload>
- >(
- 1,
- Math.round(availableParallelism() / 2),
- WebSocketServerWorker.requestHandlerWorkerFile,
- {
- enableTasksQueue: true,
- tasksQueueOptions: {
- concurrency: 8
- },
- errorHandler: (e: Error) => {
- console.error('Thread worker error:', e)
- }
- }
- )
+ >
public constructor () {
super(WebSocketServerWorker.startWebSocketServer)
version: 17.7.0
'@release-it/bumper':
specifier: ^5.1.0
- version: 5.1.0(release-it@16.1.4)
+ version: 5.1.0(release-it@16.1.5)
'@release-it/keep-a-changelog':
specifier: ^4.0.0
- version: 4.0.0(release-it@16.1.4)
+ version: 4.0.0(release-it@16.1.5)
'@rollup/plugin-terser':
specifier: ^0.4.3
version: 0.4.3(rollup@3.28.0)
specifier: ^8.0.3
version: 8.0.3
lint-staged:
- specifier: ^13.2.3
- version: 13.2.3
+ specifier: ^13.3.0
+ version: 13.3.0
microtime:
specifier: ^3.1.1
version: 3.1.1
specifier: ^3.0.1
version: 3.0.1
release-it:
- specifier: ^16.1.4
- version: 16.1.4
+ specifier: ^16.1.5
+ version: 16.1.5
rollup:
specifier: ^3.28.0
version: 3.28.0
config-chain: 1.1.13
dev: true
- /@release-it/bumper@5.1.0(release-it@16.1.4):
+ /@release-it/bumper@5.1.0(release-it@16.1.5):
resolution: {integrity: sha512-mnM5QQJvK+4sqLpU7vkDbGMGh1QNwdnWNPqrkfOCyr/cKgRDvb8e+nbiNZzyI/1XsxSjnfLHDecRVuqucwE6BQ==}
engines: {node: '>=16'}
peerDependencies:
ini: 4.1.1
js-yaml: 4.1.0
lodash-es: 4.17.21
- release-it: 16.1.4
+ release-it: 16.1.5
semver: 7.5.4
dev: true
- /@release-it/keep-a-changelog@4.0.0(release-it@16.1.4):
+ /@release-it/keep-a-changelog@4.0.0(release-it@16.1.5):
resolution: {integrity: sha512-a3n6RkBaYGf2qK2Yz/FkHDkpJjLYtMvpoZBIGfOz1zmv+918YU3In9zjoBJn4f2PldIW5yTWuk81hMYAdgPFww==}
engines: {node: '>=16'}
peerDependencies:
release-it: ^16.0.0
dependencies:
detect-newline: 4.0.0
- release-it: 16.1.4
+ release-it: 16.1.5
string-template: 1.0.0
dev: true
tslib:
optional: true
dependencies:
- '@rollup/pluginutils': 5.0.2(rollup@3.28.0)
+ '@rollup/pluginutils': 5.0.3(rollup@3.28.0)
resolve: 1.22.4
rollup: 3.28.0
typescript: 5.1.6
dev: true
- /@rollup/pluginutils@5.0.2(rollup@3.28.0):
- resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
+ /@rollup/pluginutils@5.0.3(rollup@3.28.0):
+ resolution: {integrity: sha512-hfllNN4a80rwNQ9QCxhxuHCGHMAvabXqxNdaChUSSadMre7t4iEUI6fFAhBOn/eIYTgYVhBv7vCLsAJ4u3lf3g==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0
type-fest: 0.21.3
dev: true
+ /ansi-escapes@5.0.0:
+ resolution: {integrity: sha512-5GFMVX8HqE/TB+FuBJGuO5XG0WrsA6ptUqoODaT/n9mmUaZFkqnBueB4leqGBCmrUHnCnC4PCZTCd0E7QQ83bA==}
+ engines: {node: '>=12'}
+ dependencies:
+ type-fest: 1.4.0
+ dev: true
+
/ansi-regex@5.0.1:
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
engines: {node: '>=8'}
supports-color: 7.2.0
dev: true
- /chalk@5.2.0:
- resolution: {integrity: sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==}
- engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}
- dev: true
-
/chalk@5.3.0:
resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==}
engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}
engines: {node: '>=6'}
dev: true
- /cli-truncate@2.1.0:
- resolution: {integrity: sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==}
- engines: {node: '>=8'}
- dependencies:
- slice-ansi: 3.0.0
- string-width: 4.2.3
- dev: true
-
/cli-truncate@3.1.0:
resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==}
dev: true
- /commander@10.0.1:
- resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==}
- engines: {node: '>=14'}
+ /commander@11.0.0:
+ resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==}
+ engines: {node: '>=16'}
dev: true
/commander@2.20.3:
engines: {node: '>=0.10.0'}
dev: true
+ /eventemitter3@5.0.1:
+ resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==}
+ dev: true
+
/execa@5.1.1:
resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==}
engines: {node: '>=10'}
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
dev: true
- /lint-staged@13.2.3:
- resolution: {integrity: sha512-zVVEXLuQIhr1Y7R7YAWx4TZLdvuzk7DnmrsTNL0fax6Z3jrpFcas+vKbzxhhvp6TA55m1SQuWkpzI1qbfDZbAg==}
- engines: {node: ^14.13.1 || >=16.0.0}
+ /lint-staged@13.3.0:
+ resolution: {integrity: sha512-mPRtrYnipYYv1FEE134ufbWpeggNTo+O/UPzngoaKzbzHAthvR55am+8GfHTnqNRQVRRrYQLGW9ZyUoD7DsBHQ==}
+ engines: {node: ^16.14.0 || >=18.0.0}
hasBin: true
dependencies:
- chalk: 5.2.0
- cli-truncate: 3.1.0
- commander: 10.0.1
+ chalk: 5.3.0
+ commander: 11.0.0
debug: 4.3.4(supports-color@8.1.1)
execa: 7.2.0
lilconfig: 2.1.0
- listr2: 5.0.8
+ listr2: 6.6.1
micromatch: 4.0.5
- normalize-path: 3.0.0
- object-inspect: 1.12.3
pidtree: 0.6.0
string-argv: 0.3.2
yaml: 2.3.1
- supports-color
dev: true
- /listr2@5.0.8:
- resolution: {integrity: sha512-mC73LitKHj9w6v30nLNGPetZIlfpUniNSsxxrbaPcWOjDb92SHPzJPi/t+v1YC/lxKz/AJ9egOjww0qUuFxBpA==}
- engines: {node: ^14.13.1 || >=16.0.0}
+ /listr2@6.6.1:
+ resolution: {integrity: sha512-+rAXGHh0fkEWdXBmX+L6mmfmXmXvDGEKzkjxO+8mP3+nI/r/CWznVBvsibXdxda9Zz0OW2e2ikphN3OwCT/jSg==}
+ engines: {node: '>=16.0.0'}
peerDependencies:
enquirer: '>= 2.3.0 < 3'
peerDependenciesMeta:
enquirer:
optional: true
dependencies:
- cli-truncate: 2.1.0
+ cli-truncate: 3.1.0
colorette: 2.0.20
- log-update: 4.0.0
- p-map: 4.0.0
+ eventemitter3: 5.0.1
+ log-update: 5.0.1
rfdc: 1.3.0
- rxjs: 7.8.1
- through: 2.3.8
- wrap-ansi: 7.0.0
+ wrap-ansi: 8.1.0
dev: true
/load-json-file@5.3.0:
wrap-ansi: 6.2.0
dev: true
+ /log-update@5.0.1:
+ resolution: {integrity: sha512-5UtUDQ/6edw4ofyljDNcOVJQ4c7OjDro4h3y8e1GQL5iYElYclVHJ3zeWchylvMaKnDbDilC8irOVyexnA/Slw==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ dependencies:
+ ansi-escapes: 5.0.0
+ cli-cursor: 4.0.0
+ slice-ansi: 5.0.0
+ strip-ansi: 7.1.0
+ wrap-ansi: 8.1.0
+ dev: true
+
/loose-envify@1.4.0:
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
hasBin: true
aggregate-error: 3.1.0
dev: true
- /p-map@4.0.0:
- resolution: {integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==}
- engines: {node: '>=10'}
- dependencies:
- aggregate-error: 3.1.0
- dev: true
-
/p-try@2.2.0:
resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==}
engines: {node: '>=6'}
rc: 1.2.8
dev: true
- /release-it@16.1.4:
- resolution: {integrity: sha512-lLYuXfZzAzO9tDyhQKpvkrUMY43/+PMTzibcUsC4dDDzDf3JT69FhiAjkqXv9nBAotyENGMoeHtK0jRiL4YeEQ==}
+ /release-it@16.1.5:
+ resolution: {integrity: sha512-w/zCljPZBSYcCwR9fjDB1zaYwie1CAQganUrwNqjtXacXhrrsS5E6dDUNLcxm2ypu8GWAgZNMJfuBJqIO2E7fA==}
engines: {node: '>=16'}
hasBin: true
dependencies:
engines: {node: '>=12'}
dev: true
- /slice-ansi@3.0.0:
- resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==}
- engines: {node: '>=8'}
- dependencies:
- ansi-styles: 4.3.0
- astral-regex: 2.0.0
- is-fullwidth-code-point: 3.0.0
- dev: true
-
/slice-ansi@4.0.0:
resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==}
engines: {node: '>=10'}