Skip to content

Commit f78cc90

Browse files
authored
Feat: Remove CPU thresold in threshold watcher (#33)
1 parent add6e6d commit f78cc90

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

.github/workflows/publish.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ jobs:
1919
run: npm test
2020
- name: Build project
2121
run: npm run build
22+
23+
- name: Version patch and push
24+
run: |
25+
cd libs/error-types
26+
git config user.name "${{ secrets.ACTION_GIT_USER_NAME }}"
27+
git config user.email "${{ secrets.ACTION_GIT_USER_EMAIL }}"
28+
yarn version --patch -m "chore(release): %s"
29+
git push origin HEAD
2230
- name: Publish to registry
2331
env:
2432
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Readme.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Puppeteer Pool Manager
22

33
![NPM Version](https://img.shields.io/npm/v/%40hoplin%2Fpuppeteer-pool?style=for-the-badge)
4+
45
### Puppeteer Pool Manager
56

67
<div style="display: flex; align-items: center;">
@@ -200,7 +201,6 @@ main();
200201
- Config
201202
- Support config customize
202203
- Threshold Watcher
203-
- CPU
204204
- Memory
205205
- Support safe pool instance reset in runtime
206206
- Metrics
@@ -230,7 +230,6 @@ config path, you can pass path to `start()` function as parameter.
230230
"threshold": {
231231
"activate": true,
232232
"interval": 5,
233-
"cpu": 80,
234233
"memory": 2048
235234
}
236235
}
@@ -257,12 +256,9 @@ config path, you can pass path to `start()` function as parameter.
257256

258257
- `activate`: Activate threshold watcher
259258
- `interval`: Interval of threshold watcher
260-
- `cpu`: CPU threshold value
261259
- `memory`: Memory threshold value
262260
- **Inteager Validation**
263261
- `interval` should be at least 1
264262
- `interval` should be integer
265-
- `cpu` should be at least 1
266-
- `cpu` should be integer
267263
- `memory` should be at least 1
268264
- `memory` should be integer

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hoplin/puppeteer-pool",
3-
"version": "2.1.0-alpha-1",
3+
"version": "2.1.0",
44
"main": "dist/index.js",
55
"description": "Puppeteer Pool Manager for worker server, process daemon, commands etc...",
66
"repository": "https://github.com/J-Hoplin/Puppeteer-Pool.git",

src/configs/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const app_config = {
2626
threshold: {
2727
activate: true,
2828
interval: 5,
29-
cpu: 80,
3029
memory: 2048,
3130
},
3231
};
@@ -92,12 +91,6 @@ export const loadConfig = (configPath: string = null): ConfigType => {
9291
'Threshold Config',
9392
'Interval',
9493
);
95-
// Threshold CPU configs
96-
if (loadedConfig.threshold?.cpu) {
97-
app_config.threshold.cpu =
98-
loadedConfig.threshold.cpu ?? app_config.threshold.cpu;
99-
ValidateInteager(app_config.threshold.cpu, 1, 'CPU Config', 'CPU');
100-
}
10194
// Threshold Memory configs
10295
if (loadedConfig.threshold?.memory) {
10396
app_config.threshold.memory =

src/pool/dispatcher.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const DEFAULT_VALUES = {
1414
CONCURRENCY_LEVEL: 1,
1515
CONTEXT_MODE: ContextMode.SHARED,
1616
THRESHOLD: {
17-
cpu: 80,
1817
memory: 1024,
1918
},
2019
QUEUE_CHECK_INTERVAL: 100,
@@ -50,7 +49,7 @@ export class TaskDispatcher extends EventEmitter {
5049
private logLevel: LogLevel;
5150
private launchOptions: PuppeteerLaunchOptions = {};
5251
private poolConfig: ConfigType;
53-
private threshold: { cpu: number; memory: number } = DEFAULT_VALUES.THRESHOLD;
52+
private threshold: { memory: number } = DEFAULT_VALUES.THRESHOLD;
5453

5554
// Logger
5655
private logger: Logger = new Logger();
@@ -167,7 +166,6 @@ export class TaskDispatcher extends EventEmitter {
167166
);
168167
if (this.poolConfig.threshold.activate) {
169168
this.threshold = {
170-
cpu: this.poolConfig.threshold.cpu,
171169
memory: this.poolConfig.threshold.memory,
172170
};
173171
this.metricsWatcher.startThresholdWatcher(
@@ -256,7 +254,6 @@ export class TaskDispatcher extends EventEmitter {
256254
);
257255
if (this.poolConfig.threshold.activate) {
258256
this.threshold = {
259-
cpu: this.poolConfig.threshold.cpu,
260257
memory: this.poolConfig.threshold.memory,
261258
};
262259
this.metricsWatcher.startThresholdWatcher(

src/watcher/metrics.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ export class MetricsWatcher {
1919
}
2020

2121
public startThresholdWatcher(
22-
limit: { cpu: number; memory: number },
22+
limit: { memory: number },
2323
cbOverThreshold: () => Promise<void>,
2424
checkIntervalSecond: number,
2525
) {
2626
/**
27-
* cpu: Should be a percentage
2827
* memory: Should be in MB
2928
*/
3029
this.intervalId = setInterval(async () => {
3130
const metrics = await this.metrics();
32-
if (
33-
metrics.cpuUsage > limit.cpu ||
34-
metrics.memoryUsageValue > limit.memory
35-
) {
31+
if (metrics.memoryUsageValue > limit.memory) {
3632
this.logger.warn(
37-
`Over threshold: CPU: ${metrics.cpuUsage.toFixed(2)}% Memory: ${metrics.memoryUsageValue.toFixed(2)}MB`,
33+
`Over threshold - Memory: ${metrics.memoryUsageValue.toFixed(2)}MB`,
3834
);
3935
await cbOverThreshold();
4036
}

0 commit comments

Comments
 (0)