Adding logs to track overheating
This commit is contained in:
parent
57262de1bf
commit
a8bbe04cae
@ -419,7 +419,7 @@ export class IoSocketController {
|
|||||||
const userMoves = userMovesMessage.toObject();
|
const userMoves = userMovesMessage.toObject();
|
||||||
|
|
||||||
// If CPU is high, let's drop messages of users moving (we will only dispatch the final position)
|
// If CPU is high, let's drop messages of users moving (we will only dispatch the final position)
|
||||||
if (cpuTracker.getCpuPercent() > 80 && userMoves.position?.moving === true) {
|
if (cpuTracker.isOverHeating() && userMoves.position?.moving === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS)
|
|||||||
const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
|
const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false;
|
||||||
const ADMIN_API_URL = process.env.ADMIN_API_URL || null;
|
const ADMIN_API_URL = process.env.ADMIN_API_URL || null;
|
||||||
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || null;
|
const ADMIN_API_TOKEN = process.env.ADMIN_API_TOKEN || null;
|
||||||
|
const CPU_OVERHEAT_THRESHOLD = Number(process.env.CPU_OVERHEAT_THRESHOLD) || 80;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
SECRET_KEY,
|
SECRET_KEY,
|
||||||
@ -14,4 +15,5 @@ export {
|
|||||||
ADMIN_API_TOKEN,
|
ADMIN_API_TOKEN,
|
||||||
GROUP_RADIUS,
|
GROUP_RADIUS,
|
||||||
ALLOW_ARTILLERY,
|
ALLOW_ARTILLERY,
|
||||||
}
|
CPU_OVERHEAT_THRESHOLD,
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import {CPU_OVERHEAT_THRESHOLD} from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
function secNSec2ms(secNSec: Array<number>|number) {
|
function secNSec2ms(secNSec: Array<number>|number) {
|
||||||
if (Array.isArray(secNSec)) {
|
if (Array.isArray(secNSec)) {
|
||||||
@ -8,6 +9,7 @@ function secNSec2ms(secNSec: Array<number>|number) {
|
|||||||
|
|
||||||
class CpuTracker {
|
class CpuTracker {
|
||||||
private cpuPercent: number = 0;
|
private cpuPercent: number = 0;
|
||||||
|
private overHeating: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let time = process.hrtime.bigint()
|
let time = process.hrtime.bigint()
|
||||||
@ -23,6 +25,15 @@ class CpuTracker {
|
|||||||
this.cpuPercent = Math.round(100 * (elapUserMS + elapSystMS) / Number(elapTimeMS) * 1000000)
|
this.cpuPercent = Math.round(100 * (elapUserMS + elapSystMS) / Number(elapTimeMS) * 1000000)
|
||||||
|
|
||||||
time = elapTime;
|
time = elapTime;
|
||||||
|
|
||||||
|
if (!this.overHeating && this.cpuPercent > CPU_OVERHEAT_THRESHOLD) {
|
||||||
|
this.overHeating = true;
|
||||||
|
console.warn('CPU high threshold alert. Going in "overheat" mode');
|
||||||
|
} else if (this.overHeating && this.cpuPercent <= CPU_OVERHEAT_THRESHOLD) {
|
||||||
|
this.overHeating = false;
|
||||||
|
console.log('CPU is back to normal. Canceling "overheat" mode');
|
||||||
|
}
|
||||||
|
|
||||||
/*console.log('elapsed time ms: ', elapTimeMS)
|
/*console.log('elapsed time ms: ', elapTimeMS)
|
||||||
console.log('elapsed user ms: ', elapUserMS)
|
console.log('elapsed user ms: ', elapUserMS)
|
||||||
console.log('elapsed system ms:', elapSystMS)
|
console.log('elapsed system ms:', elapSystMS)
|
||||||
@ -33,6 +44,10 @@ class CpuTracker {
|
|||||||
public getCpuPercent(): number {
|
public getCpuPercent(): number {
|
||||||
return this.cpuPercent;
|
return this.cpuPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isOverHeating(): boolean {
|
||||||
|
return this.overHeating;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cpuTracker = new CpuTracker();
|
const cpuTracker = new CpuTracker();
|
||||||
|
Loading…
Reference in New Issue
Block a user