Comparing version 5.0.0-alpha.0 to 5.0.0-alpha.1
@@ -5,2 +5,13 @@ # Changelog | ||
## [5.0.0-alpha.1](https://github.com/piscinajs/piscina/compare/v5.0.0-alpha.0...v5.0.0-alpha.1) (2025-01-10) | ||
### ⚠ BREAKING CHANGES | ||
* **#305:** Expose new `PiscinaHistogram` abstraction (#723) | ||
### Features | ||
* **#305:** Expose new `PiscinaHistogram` abstraction ([#723](https://github.com/piscinajs/piscina/issues/723)) ([86d736c](https://github.com/piscinajs/piscina/commit/86d736cf4c239d20e1a403d11a82b7ead0611aa8)), closes [#305](https://github.com/piscinajs/piscina/issues/305) | ||
## [5.0.0-alpha.0](https://github.com/piscinajs/piscina/compare/v4.6.1...v5.0.0-alpha.0) (2024-12-04) | ||
@@ -7,0 +18,0 @@ |
@@ -1,3 +0,1 @@ | ||
import type { Histogram } from 'node:perf_hooks'; | ||
import type { HistogramSummary } from './types'; | ||
export declare const READY = "_WORKER_READY"; | ||
@@ -27,5 +25,3 @@ /** | ||
}; | ||
export declare function createHistogramSummary(histogram: Histogram): HistogramSummary; | ||
export declare function toHistogramIntegerNano(milliseconds: number): number; | ||
export declare function maybeFileURLToPath(filename: string): string; | ||
export declare function getAvailableParallelism(): number; |
@@ -7,4 +7,2 @@ "use strict"; | ||
exports.markMovable = markMovable; | ||
exports.createHistogramSummary = createHistogramSummary; | ||
exports.toHistogramIntegerNano = toHistogramIntegerNano; | ||
exports.maybeFileURLToPath = maybeFileURLToPath; | ||
@@ -55,30 +53,2 @@ exports.getAvailableParallelism = getAvailableParallelism; | ||
}; | ||
function createHistogramSummary(histogram) { | ||
const { mean, stddev, min, max } = histogram; | ||
return { | ||
average: mean / 1000, | ||
mean: mean / 1000, | ||
stddev, | ||
min: min / 1000, | ||
max: max / 1000, | ||
p0_001: histogram.percentile(0.001) / 1000, | ||
p0_01: histogram.percentile(0.01) / 1000, | ||
p0_1: histogram.percentile(0.1) / 1000, | ||
p1: histogram.percentile(1) / 1000, | ||
p2_5: histogram.percentile(2.5) / 1000, | ||
p10: histogram.percentile(10) / 1000, | ||
p25: histogram.percentile(25) / 1000, | ||
p50: histogram.percentile(50) / 1000, | ||
p75: histogram.percentile(75) / 1000, | ||
p90: histogram.percentile(90) / 1000, | ||
p97_5: histogram.percentile(97.5) / 1000, | ||
p99: histogram.percentile(99) / 1000, | ||
p99_9: histogram.percentile(99.9) / 1000, | ||
p99_99: histogram.percentile(99.99) / 1000, | ||
p99_999: histogram.percentile(99.999) / 1000 | ||
}; | ||
} | ||
function toHistogramIntegerNano(milliseconds) { | ||
return Math.max(1, Math.trunc(milliseconds * 1000)); | ||
} | ||
function maybeFileURLToPath(filename) { | ||
@@ -85,0 +55,0 @@ return filename.startsWith('file:') |
import { Worker, MessagePort } from 'node:worker_threads'; | ||
import { EventEmitterAsyncResource } from 'node:events'; | ||
import { version } from '../package.json'; | ||
import type { Transferable, ResourceLimits, EnvSpecifier, HistogramSummary } from './types'; | ||
import type { Transferable, ResourceLimits, EnvSpecifier } from './types'; | ||
import { kQueueOptions, kTransferable, kValue } from './symbols'; | ||
@@ -9,2 +9,3 @@ import { TaskQueue, ArrayTaskQueue, FixedQueue, PiscinaTask, TransferList, TransferListItem } from './task_queue'; | ||
import { AbortSignalAny } from './abort'; | ||
import { PiscinaHistogram } from './histogram'; | ||
interface Options { | ||
@@ -68,4 +69,3 @@ filename?: string | null; | ||
get completed(): number; | ||
get waitTime(): HistogramSummary | null; | ||
get runTime(): any; | ||
get histogram(): PiscinaHistogram; | ||
get utilization(): number; | ||
@@ -72,0 +72,0 @@ get duration(): number; |
@@ -16,3 +16,3 @@ "use strict"; | ||
}; | ||
var _DirectlyTransferable_value, _ArrayBufferViewTransferable_view, _Piscina_pool; | ||
var _DirectlyTransferable_value, _ArrayBufferViewTransferable_view, _Piscina_pool, _Piscina_histogram; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -37,2 +37,3 @@ exports.FixedQueue = exports.version = exports.queueOptionsSymbol = exports.valueSymbol = exports.transferableSymbol = exports.Piscina = exports.workerData = exports.isWorkerThread = exports.move = void 0; | ||
const abort_1 = require("./abort"); | ||
const histogram_1 = require("./histogram"); | ||
const errors_1 = require("./errors"); | ||
@@ -87,2 +88,3 @@ const common_1 = require("./common"); | ||
this.completed = 0; | ||
this.histogram = null; | ||
this.start = node_perf_hooks_1.performance.now(); | ||
@@ -99,4 +101,3 @@ this.inProcessPendingMessages = false; | ||
if (this.options.recordTiming) { | ||
this.runTime = (0, node_perf_hooks_1.createHistogram)(); | ||
this.waitTime = (0, node_perf_hooks_1.createHistogram)(); | ||
this.histogram = new histogram_1.PiscinaHistogramHandler(); | ||
} | ||
@@ -333,3 +334,3 @@ // The >= and <= could be > and < but this way we get 100 % coverage 🙃 | ||
const now = node_perf_hooks_1.performance.now(); | ||
(_a = this.waitTime) === null || _a === void 0 ? void 0 : _a.record((0, common_1.toHistogramIntegerNano)(now - task.created)); | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.recordWaitTime(now - task.created); | ||
task.started = now; | ||
@@ -380,3 +381,3 @@ candidate[symbols_1.kWorkerData].postTask(task); | ||
if (taskInfo.started) { | ||
(_a = this.runTime) === null || _a === void 0 ? void 0 : _a.record((0, common_1.toHistogramIntegerNano)(node_perf_hooks_1.performance.now() - taskInfo.started)); | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.recordRunTime(node_perf_hooks_1.performance.now() - taskInfo.started); | ||
} | ||
@@ -562,2 +563,3 @@ if (err !== null) { | ||
_Piscina_pool.set(this, void 0); | ||
_Piscina_histogram.set(this, null); | ||
if (typeof options.filename !== 'string' && options.filename != null) { | ||
@@ -684,26 +686,40 @@ throw new TypeError('options.filename must be a string or null'); | ||
} | ||
get waitTime() { | ||
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").waitTime) { | ||
return null; | ||
get histogram() { | ||
if (__classPrivateFieldGet(this, _Piscina_histogram, "f") == null) { | ||
const piscinahistogram = { | ||
// @ts-expect-error | ||
get runTime() { var _a; return (_a = this.histogram) === null || _a === void 0 ? void 0 : _a.runTimeSummary; }, | ||
// @ts-expect-error | ||
get waitTime() { var _a; return (_a = this.histogram) === null || _a === void 0 ? void 0 : _a.waitTimeSummary; }, | ||
resetRunTime() { | ||
var _a; | ||
// @ts-expect-error | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.resetRunTime(); | ||
}, | ||
resetWaitTime() { | ||
var _a; | ||
// @ts-expect-error | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.resetWaitTime(); | ||
}, | ||
}; | ||
Object.defineProperty(piscinahistogram, 'histogram', { | ||
value: __classPrivateFieldGet(this, _Piscina_pool, "f").histogram, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}); | ||
__classPrivateFieldSet(this, _Piscina_histogram, piscinahistogram, "f"); | ||
} | ||
return (0, common_1.createHistogramSummary)(__classPrivateFieldGet(this, _Piscina_pool, "f").waitTime); | ||
; | ||
return __classPrivateFieldGet(this, _Piscina_histogram, "f"); | ||
} | ||
get runTime() { | ||
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").runTime) { | ||
return null; | ||
} | ||
return (0, common_1.createHistogramSummary)(__classPrivateFieldGet(this, _Piscina_pool, "f").runTime); | ||
} | ||
get utilization() { | ||
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").runTime) { | ||
if (__classPrivateFieldGet(this, _Piscina_pool, "f").histogram == null) { | ||
return 0; | ||
} | ||
// count is available as of Node.js v16.14.0 but not present in the types | ||
const count = __classPrivateFieldGet(this, _Piscina_pool, "f").runTime.count; | ||
const count = __classPrivateFieldGet(this, _Piscina_pool, "f").histogram.runTimeCount; | ||
if (count === 0) { | ||
return 0; | ||
} | ||
if (!__classPrivateFieldGet(this, _Piscina_pool, "f").runTime) { | ||
return 0; | ||
} | ||
// The capacity is the max compute time capacity of the | ||
@@ -714,3 +730,3 @@ // pool to this point in time as determined by the length | ||
const capacity = this.duration * __classPrivateFieldGet(this, _Piscina_pool, "f").options.maxThreads; | ||
const totalMeanRuntime = (__classPrivateFieldGet(this, _Piscina_pool, "f").runTime.mean / 1000) * count; | ||
const totalMeanRuntime = (__classPrivateFieldGet(this, _Piscina_pool, "f").histogram.runTimeSummary.mean / 1000) * count; | ||
// We calculate the appoximate pool utilization by multiplying | ||
@@ -771,3 +787,3 @@ // the mean run time of all tasks by the number of runtime | ||
exports.Piscina = Piscina; | ||
_Piscina_pool = new WeakMap(); | ||
_Piscina_pool = new WeakMap(), _Piscina_histogram = new WeakMap(); | ||
exports.default = Piscina; | ||
@@ -774,0 +790,0 @@ exports.move = Piscina.move; |
@@ -36,24 +36,2 @@ import type { MessagePort, Worker } from 'node:worker_threads'; | ||
} | ||
export interface HistogramSummary { | ||
average: number; | ||
mean: number; | ||
stddev: number; | ||
min: number; | ||
max: number; | ||
p0_001: number; | ||
p0_01: number; | ||
p0_1: number; | ||
p1: number; | ||
p2_5: number; | ||
p10: number; | ||
p25: number; | ||
p50: number; | ||
p75: number; | ||
p90: number; | ||
p97_5: number; | ||
p99: number; | ||
p99_9: number; | ||
p99_99: number; | ||
p99_999: number; | ||
} | ||
export type ResourceLimits = Worker extends { | ||
@@ -60,0 +38,0 @@ resourceLimits?: infer T; |
import { Worker, MessagePort } from 'node:worker_threads'; | ||
import { RecordableHistogram } from 'node:perf_hooks'; | ||
import { HistogramSummary, ResponseMessage } from '../types'; | ||
import { ResponseMessage } from '../types'; | ||
import { TaskInfo } from '../task_queue'; | ||
import { kWorkerData } from '../symbols'; | ||
import { PiscinaHistogramSummary } from '../histogram'; | ||
import { AsynchronouslyCreatedResource, AsynchronouslyCreatedResourcePool } from './base'; | ||
@@ -13,3 +14,3 @@ export * from './balancer'; | ||
isRunningAbortableTask: boolean; | ||
histogram: HistogramSummary | null; | ||
histogram: PiscinaHistogramSummary | null; | ||
terminating: boolean; | ||
@@ -16,0 +17,0 @@ destroyed: boolean; |
@@ -26,3 +26,3 @@ "use strict"; | ||
const symbols_1 = require("../symbols"); | ||
const common_1 = require("../common"); | ||
const histogram_1 = require("../histogram"); | ||
const base_1 = require("./base"); | ||
@@ -83,3 +83,3 @@ Object.defineProperty(exports, "AsynchronouslyCreatedResourcePool", { enumerable: true, get: function () { return base_1.AsynchronouslyCreatedResourcePool; } }); | ||
if (message.time != null) { | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.record((0, common_1.toHistogramIntegerNano)(message.time)); | ||
(_a = this.histogram) === null || _a === void 0 ? void 0 : _a.record(histogram_1.PiscinaHistogramHandler.toHistogramIntegerNano(message.time)); | ||
} | ||
@@ -163,3 +163,3 @@ this.onMessage(message); | ||
get histogram() { | ||
return worker.histogram != null ? (0, common_1.createHistogramSummary)(worker.histogram) : null; | ||
return worker.histogram != null ? histogram_1.PiscinaHistogramHandler.createHistogramSummary(worker.histogram) : null; | ||
}, | ||
@@ -166,0 +166,0 @@ get terminating() { |
@@ -113,2 +113,86 @@ --- | ||
## `PiscinaHistogram` | ||
The `PiscinaHistogram` allows you to access the histogram data for the pool of worker threads. | ||
It can be reset upon request in case of a need to clear the data. | ||
**Example**: | ||
```js | ||
import { Piscina } from 'piscina'; | ||
const pool = new Piscina({ | ||
filename: resolve(__dirname, 'path/to/worker.js'), | ||
}); | ||
const firstBatch = []; | ||
for (let n = 0; n < 10; n++) { | ||
firstBatch.push(pool.run('42')); | ||
} | ||
await Promise.all(firstBatch); | ||
console.log(pool.histogram.runTime); // Print run time histogram summary | ||
console.log(pool.histogram.waitTime); // Print wait time histogram summary | ||
// If in need to reset the histogram data for a new set of tasks | ||
pool.histogram.resetRunTime(); | ||
pool.histogram.resetWaitTime(); | ||
const secondBatch = []; | ||
for (let n = 0; n < 10; n++) { | ||
secondBatch.push(pool.run('42')); | ||
} | ||
await Promise.all(secondBatch); | ||
// The histogram data will only contain the data for the second batch of tasks | ||
console.log(pool.histogram.runTime); | ||
console.log(pool.histogram.waitTime); | ||
``` | ||
### Interface: `PiscinaLoadBalancer` | ||
- `runTime`: (`PiscinaHistogramSummary`) Run Time Histogram Summary. Time taken to execute a task. | ||
- `waitTime`: (`PiscinaHistogramSummary`) Wait Time Histogram Summary. Time between a task being submitted and the task starting to run. | ||
> **Note**: The histogram data is only available if `recordTiming` is set to `true`. | ||
```ts | ||
type PiscinaHistogram = { | ||
runTime: PiscinaHistogramSummary; | ||
waitTime: PiscinaHistogramSummary; | ||
resetRunTime(): void; // Reset Run Time Histogram | ||
resetWaitTime(): void; // Reset Wait Time Histogram | ||
``` | ||
### Interface: `PiscinaHistogramSummary` | ||
```ts | ||
type PiscinaHistogramSummary = { | ||
average: number; | ||
mean: number; | ||
stddev: number; | ||
min: number; | ||
max: number; | ||
p0_001: number; | ||
p0_01: number; | ||
p0_1: number; | ||
p1: number; | ||
p2_5: number; | ||
p10: number; | ||
p25: number; | ||
p50: number; | ||
p75: number; | ||
p90: number; | ||
p97_5: number; | ||
p99: number; | ||
p99_9: number; | ||
p99_99: number; | ||
p99_999: number; | ||
} | ||
``` | ||
## `PiscinaLoadBalancer` | ||
@@ -115,0 +199,0 @@ |
{ | ||
"name": "piscina", | ||
"version": "5.0.0-alpha.0", | ||
"version": "5.0.0-alpha.1", | ||
"description": "A fast, efficient Node.js Worker Thread Pool implementation", | ||
@@ -55,3 +55,3 @@ "main": "./dist/main.js", | ||
"gen-esm-wrapper": "^1.1.1", | ||
"neostandard": "^0.11.9", | ||
"neostandard": "^0.12.0", | ||
"tap": "^16.3.7", | ||
@@ -58,0 +58,0 @@ "tinybench": "^3.0.0", |
@@ -1,6 +0,4 @@ | ||
import type { Histogram } from 'node:perf_hooks'; | ||
import { fileURLToPath, URL } from 'node:url'; | ||
import { availableParallelism } from 'node:os'; | ||
import type { HistogramSummary } from './types'; | ||
import { kMovable, kTransferable, kValue } from './symbols'; | ||
@@ -55,33 +53,2 @@ | ||
export function createHistogramSummary (histogram: Histogram): HistogramSummary { | ||
const { mean, stddev, min, max } = histogram; | ||
return { | ||
average: mean / 1000, | ||
mean: mean / 1000, | ||
stddev, | ||
min: min / 1000, | ||
max: max / 1000, | ||
p0_001: histogram.percentile(0.001) / 1000, | ||
p0_01: histogram.percentile(0.01) / 1000, | ||
p0_1: histogram.percentile(0.1) / 1000, | ||
p1: histogram.percentile(1) / 1000, | ||
p2_5: histogram.percentile(2.5) / 1000, | ||
p10: histogram.percentile(10) / 1000, | ||
p25: histogram.percentile(25) / 1000, | ||
p50: histogram.percentile(50) / 1000, | ||
p75: histogram.percentile(75) / 1000, | ||
p90: histogram.percentile(90) / 1000, | ||
p97_5: histogram.percentile(97.5) / 1000, | ||
p99: histogram.percentile(99) / 1000, | ||
p99_9: histogram.percentile(99.9) / 1000, | ||
p99_99: histogram.percentile(99.99) / 1000, | ||
p99_999: histogram.percentile(99.999) / 1000 | ||
}; | ||
} | ||
export function toHistogramIntegerNano (milliseconds: number): number { | ||
return Math.max(1, Math.trunc(milliseconds * 1000)); | ||
} | ||
export function maybeFileURLToPath (filename : string) : string { | ||
@@ -88,0 +55,0 @@ return filename.startsWith('file:') |
@@ -5,3 +5,3 @@ import { Worker, MessageChannel, MessagePort } from 'node:worker_threads'; | ||
import { inspect, types } from 'node:util'; | ||
import { RecordableHistogram, createHistogram, performance } from 'node:perf_hooks'; | ||
import { performance } from 'node:perf_hooks'; | ||
import { setTimeout as sleep } from 'node:timers/promises'; | ||
@@ -17,3 +17,2 @@ import assert from 'node:assert'; | ||
EnvSpecifier, | ||
HistogramSummary | ||
} from './types'; | ||
@@ -49,2 +48,6 @@ import { | ||
} from './abort'; | ||
import { | ||
PiscinaHistogram, | ||
PiscinaHistogramHandler, | ||
} from './histogram'; | ||
import { Errors } from './errors'; | ||
@@ -56,4 +59,2 @@ import { | ||
markMovable, | ||
createHistogramSummary, | ||
toHistogramIntegerNano, | ||
getAvailableParallelism, | ||
@@ -178,4 +179,3 @@ maybeFileURLToPath | ||
completed : number = 0; | ||
runTime? : RecordableHistogram; | ||
waitTime? : RecordableHistogram; | ||
histogram: PiscinaHistogramHandler | null = null; | ||
_needsDrain : boolean; | ||
@@ -200,4 +200,3 @@ start : number = performance.now(); | ||
if (this.options.recordTiming) { | ||
this.runTime = createHistogram(); | ||
this.waitTime = createHistogram(); | ||
this.histogram = new PiscinaHistogramHandler(); | ||
} | ||
@@ -467,3 +466,3 @@ | ||
const now = performance.now(); | ||
this.waitTime?.record(toHistogramIntegerNano(now - task.created)); | ||
this.histogram?.recordWaitTime(now - task.created) | ||
task.started = now; | ||
@@ -528,3 +527,3 @@ candidate[kWorkerData].postTask(task); | ||
if (taskInfo.started) { | ||
this.runTime?.record(toHistogramIntegerNano(performance.now() - taskInfo.started)); | ||
this.histogram?.recordRunTime(performance.now() - taskInfo.started); | ||
} | ||
@@ -729,2 +728,3 @@ if (err !== null) { | ||
#pool : ThreadPool; | ||
#histogram: PiscinaHistogram | null = null; | ||
@@ -879,20 +879,34 @@ constructor (options : Options = {}) { | ||
get waitTime () : HistogramSummary | null { | ||
if (!this.#pool.waitTime) { | ||
return null; | ||
} | ||
get histogram () : PiscinaHistogram { | ||
if (this.#histogram == null) { | ||
const piscinahistogram = { | ||
// @ts-expect-error | ||
get runTime() { return this.histogram?.runTimeSummary! }, | ||
// @ts-expect-error | ||
get waitTime() { return this.histogram?.waitTimeSummary! }, | ||
resetRunTime() { | ||
// @ts-expect-error | ||
this.histogram?.resetRunTime() | ||
}, | ||
resetWaitTime() { | ||
// @ts-expect-error | ||
this.histogram?.resetWaitTime() | ||
}, | ||
} | ||
Object.defineProperty(piscinahistogram, 'histogram', { | ||
value: this.#pool.histogram, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}) | ||
this.#histogram = piscinahistogram; | ||
}; | ||
return createHistogramSummary(this.#pool.waitTime); | ||
return this.#histogram; | ||
} | ||
get runTime () : any { | ||
if (!this.#pool.runTime) { | ||
return null; | ||
} | ||
return createHistogramSummary(this.#pool.runTime); | ||
} | ||
get utilization () : number { | ||
if (!this.#pool.runTime) { | ||
if (this.#pool.histogram == null) { | ||
return 0; | ||
@@ -902,3 +916,4 @@ } | ||
// count is available as of Node.js v16.14.0 but not present in the types | ||
const count = (this.#pool.runTime as RecordableHistogram & { count: number }).count; | ||
const count = this.#pool.histogram.runTimeCount; | ||
if (count === 0) { | ||
@@ -908,6 +923,2 @@ return 0; | ||
if (!this.#pool.runTime) { | ||
return 0; | ||
} | ||
// The capacity is the max compute time capacity of the | ||
@@ -918,3 +929,3 @@ // pool to this point in time as determined by the length | ||
const capacity = this.duration * this.#pool.options.maxThreads; | ||
const totalMeanRuntime = (this.#pool.runTime.mean / 1000) * count; | ||
const totalMeanRuntime = (this.#pool.histogram.runTimeSummary.mean / 1000) * count; | ||
@@ -921,0 +932,0 @@ // We calculate the appoximate pool utilization by multiplying |
@@ -43,25 +43,2 @@ import type { MessagePort, Worker } from 'node:worker_threads'; | ||
export interface HistogramSummary { | ||
average: number; | ||
mean: number; | ||
stddev: number; | ||
min: number; | ||
max: number; | ||
p0_001: number; | ||
p0_01: number; | ||
p0_1: number; | ||
p1: number; | ||
p2_5: number; | ||
p10: number; | ||
p25: number; | ||
p50: number; | ||
p75: number; | ||
p90: number; | ||
p97_5: number; | ||
p99: number; | ||
p99_9: number; | ||
p99_99: number; | ||
p99_999: number; | ||
} | ||
export type ResourceLimits = Worker extends { | ||
@@ -68,0 +45,0 @@ resourceLimits?: infer T; |
@@ -5,3 +5,3 @@ import { Worker, MessagePort, receiveMessageOnPort } from 'node:worker_threads'; | ||
import { HistogramSummary, RequestMessage, ResponseMessage } from '../types'; | ||
import { RequestMessage, ResponseMessage } from '../types'; | ||
import { Errors } from '../errors'; | ||
@@ -11,3 +11,3 @@ | ||
import { kFieldCount, kRequestCountField, kResponseCountField, kWorkerData } from '../symbols'; | ||
import { createHistogramSummary, toHistogramIntegerNano } from '../common'; | ||
import { PiscinaHistogramHandler, PiscinaHistogramSummary } from '../histogram'; | ||
@@ -23,3 +23,3 @@ import { AsynchronouslyCreatedResource, AsynchronouslyCreatedResourcePool } from './base'; | ||
isRunningAbortableTask: boolean; | ||
histogram: HistogramSummary | null; | ||
histogram: PiscinaHistogramSummary | null; | ||
terminating: boolean; | ||
@@ -102,3 +102,3 @@ destroyed: boolean; | ||
if (message.time != null) { | ||
this.histogram?.record(toHistogramIntegerNano(message.time)); | ||
this.histogram?.record(PiscinaHistogramHandler.toHistogramIntegerNano(message.time)); | ||
} | ||
@@ -191,3 +191,3 @@ | ||
get histogram () { | ||
return worker.histogram != null ? createHistogramSummary(worker.histogram) : null; | ||
return worker.histogram != null ? PiscinaHistogramHandler.createHistogramSummary(worker.histogram) : null; | ||
}, | ||
@@ -194,0 +194,0 @@ get terminating () { |
@@ -17,3 +17,4 @@ import Piscina from '..'; | ||
const waitTime = pool.waitTime as any; | ||
const histogram = pool.histogram; | ||
const waitTime = histogram.waitTime; | ||
ok(waitTime); | ||
@@ -26,3 +27,3 @@ equal(typeof waitTime.average, 'number'); | ||
const runTime = pool.runTime as any; | ||
const runTime = histogram.runTime; | ||
ok(runTime); | ||
@@ -34,2 +35,4 @@ equal(typeof runTime.average, 'number'); | ||
equal(typeof runTime.max, 'number'); | ||
equal(typeof histogram.resetRunTime, 'function'); | ||
equal(typeof histogram.resetWaitTime, 'function'); | ||
}); | ||
@@ -49,10 +52,10 @@ | ||
const waitTime = pool.waitTime as any; | ||
const waitTime = pool.histogram.waitTime; | ||
ok(waitTime); | ||
const runTime = pool.runTime as any; | ||
const runTime = pool.histogram.runTime; | ||
ok(runTime); | ||
}); | ||
test('pool does not maintain run and wait time histograms when recordTiming is false', async ({ equal }) => { | ||
test('pool does not maintain run and wait time histograms when recordTiming is false', async ({ notOk }) => { | ||
const pool = new Piscina({ | ||
@@ -69,4 +72,4 @@ filename: resolve(__dirname, 'fixtures/eval.js'), | ||
equal(pool.waitTime, null); | ||
equal(pool.runTime, null); | ||
notOk(pool.histogram.waitTime); | ||
notOk(pool.histogram.runTime); | ||
}); | ||
@@ -144,30 +147,3 @@ | ||
// test('histogram of worker should be initialized with max concurrent task set as min', { only: true }, async t => { | ||
// // After each task the balancer is called to distribute the next task | ||
// // The first task is distributed, the second is enqueued, once the first is done, the second is distributed and normalizes | ||
// let counter = 0; | ||
// const pool = new Piscina({ | ||
// filename: resolve(__dirname, 'fixtures/eval.js'), | ||
// maxThreads: 2, | ||
// concurrentTasksPerWorker: 1, | ||
// workerHistogram: true, | ||
// }); | ||
// const tasks = []; | ||
// t.plan(10 * 2); | ||
// pool.on('workerCreate', worker => { | ||
// if (counter === 0) { | ||
// t.equal(worker.histogram.min, 0); | ||
// } else { | ||
// t.equal(worker.histogram.min, 1); | ||
// } | ||
// }) | ||
// for (let n = 0; n < 10; n++) { | ||
// tasks.push(pool.run('new Promise(resolve => setTimeout(resolve, 500))')); | ||
// } | ||
// await Promise.all(tasks); | ||
// }); | ||
test('opts.workerHistogram should be a boolean value', async t => { | ||
test('opts.workerHistogram should be a boolean value', t => { | ||
let index = 0; | ||
@@ -174,0 +150,0 @@ t.plan(1); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
382089
139
6546