repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
perf: enable prioritized tasks queue only when necessary
[poolifier.git]
/
tests
/
pools
/
abstract-pool.test.mjs
diff --git
a/tests/pools/abstract-pool.test.mjs
b/tests/pools/abstract-pool.test.mjs
index 441e7ffc80eb5a8a9408ceb55664a0cc5c77a4f6..ec8fe516ffbd278d162306920d182be9e76c8427 100644
(file)
--- a/
tests/pools/abstract-pool.test.mjs
+++ b/
tests/pools/abstract-pool.test.mjs
@@
-8,7
+8,7
@@
import { fileURLToPath } from 'node:url'
import { expect } from 'expect'
import { restore, stub } from 'sinon'
import { expect } from 'expect'
import { restore, stub } from 'sinon'
-import { Circular
Array } from '../../lib/circular-array
.cjs'
+import { Circular
Buffer } from '../../lib/circular-buffer
.cjs'
import {
DynamicClusterPool,
DynamicThreadPool,
import {
DynamicClusterPool,
DynamicThreadPool,
@@
-20,7
+20,7
@@
import {
WorkerTypes
} from '../../lib/index.cjs'
import { WorkerNode } from '../../lib/pools/worker-node.cjs'
WorkerTypes
} from '../../lib/index.cjs'
import { WorkerNode } from '../../lib/pools/worker-node.cjs'
-import { PriorityQueue } from '../../lib/priority-queue.cjs'
+import {
defaultBucketSize,
PriorityQueue } from '../../lib/priority-queue.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
import { waitPoolEvents } from '../test-utils.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
import { waitPoolEvents } from '../test-utils.cjs'
@@
-761,17
+761,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
},
waitTime: {
},
waitTime: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
},
active: {
},
active: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
}
}
})
}
}
})
@@
-789,7
+789,8
@@
describe('Abstract pool test suite', () => {
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
- expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+ expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
}
await pool.destroy()
pool = new DynamicThreadPool(
}
await pool.destroy()
pool = new DynamicThreadPool(
@@
-802,7
+803,8
@@
describe('Abstract pool test suite', () => {
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
- expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+ expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
}
await pool.destroy()
})
}
await pool.destroy()
})
@@
-933,17
+935,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})
@@
-961,17
+963,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})
@@
-1003,17
+1005,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})
@@
-1021,10
+1023,6
@@
describe('Abstract pool test suite', () => {
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
- expect(workerNode.usage.runTime.history.length).toBe(0)
- expect(workerNode.usage.waitTime.history.length).toBe(0)
- expect(workerNode.usage.elu.idle.history.length).toBe(0)
- expect(workerNode.usage.elu.active.history.length).toBe(0)
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
@@
-1039,17
+1037,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})
@@
-1057,10
+1055,6
@@
describe('Abstract pool test suite', () => {
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
- expect(workerNode.usage.runTime.history.length).toBe(0)
- expect(workerNode.usage.waitTime.history.length).toBe(0)
- expect(workerNode.usage.elu.idle.history.length).toBe(0)
- expect(workerNode.usage.elu.active.history.length).toBe(0)
}
await pool.destroy()
})
}
await pool.destroy()
})
@@
-1452,17
+1446,17
@@
describe('Abstract pool test suite', () => {
failed: 0
},
runTime: {
failed: 0
},
runTime: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
},
waitTime: {
},
waitTime: {
- history:
new CircularArray(
)
+ history:
expect.any(CircularBuffer
)
},
elu: expect.objectContaining({
idle: expect.objectContaining({
},
elu: expect.objectContaining({
idle: expect.objectContaining({
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}),
active: expect.objectContaining({
}),
active: expect.objectContaining({
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
})
})
})
})
})
})
@@
-1670,6
+1664,7
@@
describe('Abstract pool test suite', () => {
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
@@
-1683,17
+1678,17
@@
describe('Abstract pool test suite', () => {
stolen: 0
},
runTime: {
stolen: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})
@@
-1735,10
+1730,11
@@
describe('Abstract pool test suite', () => {
{ name: DEFAULT_TASK_NAME },
{ name: 'jsonIntegerSerialization' },
{ name: 'factorial' },
{ name: DEFAULT_TASK_NAME },
{ name: 'jsonIntegerSerialization' },
{ name: 'factorial' },
- { name: 'fibonacci' }
+ { name: 'fibonacci'
, priority: -5
}
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.enablePriority).toBe(true)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
@@
-1752,17
+1748,17
@@
describe('Abstract pool test suite', () => {
stolen: 0
},
runTime: {
stolen: 0
},
runTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
waitTime: {
},
waitTime: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
elu: {
idle: {
},
elu: {
idle: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
},
active: {
},
active: {
- history: expect.any(Circular
Array
)
+ history: expect.any(Circular
Buffer
)
}
}
})
}
}
})