repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Comment cleanup
[poolifier.git]
/
src
/
pools
/
cluster
/
fixed.ts
diff --git
a/src/pools/cluster/fixed.ts
b/src/pools/cluster/fixed.ts
index 4ec81c07bab66b0ebad1cb3eed371ea568989ef0..971116bc27cfbd3cd470faa83a904a3949984920 100644
(file)
--- a/
src/pools/cluster/fixed.ts
+++ b/
src/pools/cluster/fixed.ts
@@
-1,7
+1,9
@@
-import { fork, isMaster, setupMaster, Worker } from 'cluster'
+import type { Worker } from 'cluster'
+import cluster from 'cluster'
import type { MessageValue } from '../../utility-types'
import type { MessageValue } from '../../utility-types'
-import type { PoolOptions } from '../abstract-pool'
import { AbstractPool } from '../abstract-pool'
import { AbstractPool } from '../abstract-pool'
+import type { PoolOptions } from '../pool'
+import { PoolType } from '../pool-internal'
/**
* Options for a poolifier cluster pool.
/**
* Options for a poolifier cluster pool.
@@
-23,9
+25,8
@@
export interface ClusterPoolOptions extends PoolOptions<Worker> {
*
* This pool selects the workers in a round robin fashion.
*
*
* This pool selects the workers in a round robin fashion.
*
- * @template Data Type of data sent to the worker. This can only be serializable data.
- * @template Response Type of response of execution. This can only be serializable data.
- *
+ * @template DataType of data sent to the worker. This can only be serializable data.
+ * @template ResponseType of response of execution. This can only be serializable data.
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
* @since 2.0.0
*/
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
* @since 2.0.0
*/
@@
-38,24
+39,26
@@
export class FixedClusterPool<
*
* @param numberOfWorkers Number of workers for this pool.
* @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
*
* @param numberOfWorkers Number of workers for this pool.
* @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
- * @param
opts Options for this fixed cluster pool. Default: `{ maxTasks: 1000 }`
+ * @param
[opts={}] Options for this fixed cluster pool.
*/
public constructor (
numberOfWorkers: number,
filePath: string,
*/
public constructor (
numberOfWorkers: number,
filePath: string,
- public readonly opts: ClusterPoolOptions = {
maxTasks: 1000
}
+ public readonly opts: ClusterPoolOptions = {}
) {
super(numberOfWorkers, filePath, opts)
}
) {
super(numberOfWorkers, filePath, opts)
}
+ /** @inheritdoc */
protected setupHook (): void {
protected setupHook (): void {
-
setupMaster
({
+
cluster.setupPrimary
({
exec: this.filePath
})
}
exec: this.filePath
})
}
+ /** @inheritdoc */
protected isMain (): boolean {
protected isMain (): boolean {
- return
isMaster
+ return
cluster.isPrimary
}
/** @inheritdoc */
}
/** @inheritdoc */
@@
-64,6
+67,7
@@
export class FixedClusterPool<
worker.kill()
}
worker.kill()
}
+ /** @inheritdoc */
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
@@
-76,14
+80,24
@@
export class FixedClusterPool<
worker.on('message', listener)
}
worker.on('message', listener)
}
+ /** @inheritdoc */
protected createWorker (): Worker {
protected createWorker (): Worker {
- return fork(this.opts.env)
+ return
cluster.
fork(this.opts.env)
}
}
+ /** @inheritdoc */
protected afterWorkerSetup (worker: Worker): void {
protected afterWorkerSetup (worker: Worker): void {
- // We will attach a listener for every task,
- // when task is completed the listener will be removed but to avoid warnings we are increasing the max listeners size
- worker.setMaxListeners(this.opts.maxTasks ?? 1000)
+ // Listen worker messages.
this.registerWorkerMessageListener(worker, super.workerListener())
}
this.registerWorkerMessageListener(worker, super.workerListener())
}
+
+ /** @inheritdoc */
+ public get type (): PoolType {
+ return PoolType.FIXED
+ }
+
+ /** @inheritdoc */
+ public get busy (): boolean {
+ return this.internalGetBusyStatus()
+ }
}
}