From 330c983e06cc9711c66fcd0f1bb419e80453c77f Mon Sep 17 00:00:00 2001 From: aardizio Date: Sat, 27 Feb 2021 14:38:04 +0100 Subject: [PATCH] Rename FullPool event to busy, update benchmarks --- CHANGELOG.md | 1 + README.md | 2 +- benchmarks/versus-external-pools/package-lock.json | 6 +++--- benchmarks/versus-external-pools/package.json | 2 +- examples/dynamicExample.js | 2 +- src/pools/pool-internal.ts | 2 +- src/pools/selection-strategies.ts | 2 +- tests/pools/cluster/dynamic.test.js | 6 +++--- tests/pools/thread/dynamic.test.js | 6 +++--- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce72fc0f..32b70e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes +- `FullPool` event is now renamed to `busy`. - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`. _Find more details on our JSDoc._ diff --git a/README.md b/README.md index 110fbc4f..ec12e397 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ const pool = new DynamicThreadPool(10, 100, './yourWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') }) -pool.emitter.on('FullPool', () => console.log('Pool is full')) +pool.emitter.on('busy', () => console.log('Pool is full')) // the execute method signature is the same for both implementations, // so you can easy switch from one to another diff --git a/benchmarks/versus-external-pools/package-lock.json b/benchmarks/versus-external-pools/package-lock.json index d7e702d5..e52cd5d1 100644 --- a/benchmarks/versus-external-pools/package-lock.json +++ b/benchmarks/versus-external-pools/package-lock.json @@ -139,9 +139,9 @@ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" }, "piscina": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/piscina/-/piscina-2.1.0.tgz", - "integrity": "sha512-3FgX36QyZcU4prKuNKl7/lWlOF3HAv9n7JpCjw09Zbql2KkzXXQ7E5xUS+RV5wV24Rn0r6Lr8jLdtU/cNZHAnA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/piscina/-/piscina-2.2.0.tgz", + "integrity": "sha512-CQb0DfyTdC9FBIMYkVV/00fXRLKDjmWKA8S0N1zDg2JGEc5z3P9qHXtoq8OkJQ+vjCfXySkVonTNMqskMFOW/w==", "requires": { "eventemitter-asyncresource": "^1.0.0", "hdr-histogram-js": "^2.0.1", diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index acf0ab4a..06d0ba05 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -12,7 +12,7 @@ "benchmark": "^2.1.4", "microjob": "0.7.0", "node-worker-threads-pool": "1.4.3", - "piscina": "2.1.0", + "piscina": "2.2.0", "poolifier": "2.0.0-beta.7", "threads": "1.6.3", "worker-threads-pool": "2.0.0", diff --git a/examples/dynamicExample.js b/examples/dynamicExample.js index 4003c534..66909d38 100644 --- a/examples/dynamicExample.js +++ b/examples/dynamicExample.js @@ -5,7 +5,7 @@ const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { errorHandler: e => console.error(e), onlineHandler: () => console.log('worker is online') }) -pool.emitter.on('FullPool', () => maxReached++) +pool.emitter.on('busy', () => maxReached++) const start = Date.now() const iterations = 1000 diff --git a/src/pools/pool-internal.ts b/src/pools/pool-internal.ts index 6152e3a4..911e761d 100644 --- a/src/pools/pool-internal.ts +++ b/src/pools/pool-internal.ts @@ -37,7 +37,7 @@ export interface IPoolInternal< * * Events that can currently be listened to: * - * - `'FullPool'` + * - `'busy'` */ readonly emitter: PoolEmitter diff --git a/src/pools/selection-strategies.ts b/src/pools/selection-strategies.ts index 53b129c9..692ace93 100644 --- a/src/pools/selection-strategies.ts +++ b/src/pools/selection-strategies.ts @@ -144,7 +144,7 @@ class DynamicPoolWorkerChoiceStrategy } if (this.pool.workers.length === this.pool.max) { - this.pool.emitter.emit('FullPool') + this.pool.emitter.emit('busy') return this.workerChoiceStrategy.choose() } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 05d8cdd4..607e1fe9 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -21,14 +21,14 @@ describe('Dynamic cluster pool test suite', () => { it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => { const promises = [] - let fullPool = 0 - pool.emitter.on('FullPool', () => fullPool++) + let busy = 0 + pool.emitter.on('busy', () => busy++) for (let i = 0; i < max * 2; i++) { promises.push(pool.execute({ test: 'test' })) } expect(pool.workers.length).toBeLessThanOrEqual(max) expect(pool.workers.length).toBeGreaterThan(min) - expect(fullPool > 1).toBeTruthy() + expect(busy > 1).toBeTruthy() const numberOfExitEvents = await TestUtils.waitExits(pool, max - min) expect(numberOfExitEvents).toBe(max - min) }) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 4ee24720..2e3a8492 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -21,13 +21,13 @@ describe('Dynamic thread pool test suite', () => { it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => { const promises = [] - let fullPool = 0 - pool.emitter.on('FullPool', () => fullPool++) + let busy = 0 + pool.emitter.on('busy', () => busy++) for (let i = 0; i < max * 2; i++) { promises.push(pool.execute({ test: 'test' })) } expect(pool.workers.length).toBe(max) - expect(fullPool > 1).toBeTruthy() + expect(busy > 1).toBeTruthy() const res = await TestUtils.waitExits(pool, max - min) expect(res).toBe(max - min) }) -- 2.34.1