-export const getPoolImplementationName = pool => {
- if (pool instanceof FixedThreadPool) {
- return 'FixedThreadPool'
- } else if (pool instanceof DynamicThreadPool) {
- return 'DynamicThreadPool'
- } else if (pool instanceof FixedClusterPool) {
- return 'FixedClusterPool'
- } else if (pool instanceof DynamicClusterPool) {
- return 'DynamicClusterPool'
- }
+export const runPoolifierPoolBenchmark = async (
+ name,
+ pool,
+ { taskExecutions, workerData }
+) => {
+ return await new Promise((resolve, reject) => {
+ try {
+ const suite = new Benchmark.Suite(name)
+ for (const workerChoiceStrategy of Object.values(
+ WorkerChoiceStrategies
+ )) {
+ for (const enableTasksQueue of [false, true]) {
+ if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
+ for (const measurement of [
+ Measurements.runTime,
+ Measurements.elu
+ ]) {
+ suite.add(
+ `${name} with ${workerChoiceStrategy}, with ${measurement} and ${
+ enableTasksQueue ? 'with' : 'without'
+ } tasks queue`,
+ async () => {
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy, {
+ measurement
+ })
+ pool.enableTasksQueue(enableTasksQueue)
+ assert.strictEqual(
+ pool.opts.workerChoiceStrategy,
+ workerChoiceStrategy
+ )
+ assert.strictEqual(
+ pool.opts.enableTasksQueue,
+ enableTasksQueue
+ )
+ assert.strictEqual(
+ pool.opts.workerChoiceStrategyOptions.measurement,
+ measurement
+ )
+ await runPoolifierPool(pool, {
+ taskExecutions,
+ workerData
+ })
+ }
+ )
+ }
+ } else {
+ suite.add(
+ `${name} with ${workerChoiceStrategy} and ${
+ enableTasksQueue ? 'with' : 'without'
+ } tasks queue`,
+ async () => {
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy)
+ pool.enableTasksQueue(enableTasksQueue)
+ assert.strictEqual(
+ pool.opts.workerChoiceStrategy,
+ workerChoiceStrategy
+ )
+ assert.strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
+ await runPoolifierPool(pool, {
+ taskExecutions,
+ workerData
+ })
+ }
+ )
+ }
+ }
+ }
+ suite
+ .on('cycle', event => {
+ console.info(event.target.toString())
+ })
+ .on('complete', async function () {
+ console.info(
+ 'Fastest is ' +
+ LIST_FORMATTER.format(this.filter('fastest').map('name'))
+ )
+ await pool.destroy()
+ resolve()
+ })
+ .run({ async: true })
+ } catch (error) {
+ reject(error)
+ }
+ })